<commit_before><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
use Symfony\Component\Form\FormError;

class DateIntervalTypeTest extends BaseTypeTest
{
    const TESTED_TYPE = DateIntervalType::class;

    public function testSubmitDateInterval()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'dateinterval'));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
        ));

        $this->assertDateIntervalEquals(new \DateInterval('P7Y6M5D'), $form->getData());
    }

    public function testSubmitString()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'string'));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
        ));

        $this->assertSame('P7Y6M5D', $form->getData());
    }

    public function testSubmitArray()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'array'));

        $input = array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
        );

        $form->submit($input);

        $this->assertSame($input, $form->getData());
    }

    public function testSubmitWithoutMonths()
    {
        $interval = new \DateInterval('P7Y5D');

        $form = $this->factory->create(static::TESTED_TYPE, $interval, array(
            'input' => 'dateinterval',
            'with_months' => false,
        ));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
        ));

        $this->assertDateIntervalEquals($interval, $form->getData());
        $this->assertTrue($form->isSynchronized());
    }

    public function testSubmitWithTime()
    {
        $interval = new \DateInterval('P7Y6M5DT4H3M2S');
        $form = $this->factory->create(static::TESTED_TYPE, $interval, array(
            'input' => 'dateinterval',
            'with_hours' => true,
            'with_minutes' => true,
            'with_seconds' => true,
        ));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
            'hours' => '4',
            'minutes' => '3',
            'seconds' => '2',
        ));

        $this->assertDateIntervalEquals($interval, $form->getData());
        $this->assertTrue($form->isSynchronized());
    }

    public function testSubmitWithWeeks()
    {
        $form = $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y'), array(
            'input' => 'dateinterval',
            'with_years' => false,
            'with_months' => false,
            'with_weeks' => true,
            'with_days' => false,
        ));

        $form->submit(array(
            'weeks' => '30',
        ));

        $this->assertDateIntervalEquals(new \DateInterval('P30W'), $form->getData());
    }

    public function testSubmitWithInvert()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array(
            'input' => 'dateinterval',
            'with_invert' => true,
        ));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
            'invert' => true,
        ));

        $interval = new \DateInterval('P7Y6M5D');
        $interval->invert = 1;

        $this->assertDateIntervalEquals($interval, $form->getData());
    }

    public function testSubmitStringSingleText()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array(
            'input' => 'string',
            'widget' => 'single_text',
        ));

        $interval = 'P7Y6M5D';

        $form->submit($interval);

        $this->assertSame($interval, $form->getData());
        $this->assertSame($interval, $form->getViewData());
    }

    public function testSubmitStringSingleTextWithSeconds()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array(
            'input' => 'string',
            'widget' => 'single_text',
            'with_hours' => true,
            'with_minutes' => true,
            'with_seconds' => true,
        ));

        $interval = 'P7Y6M5DT4H3M2S';

        $form->submit($interval);

        $this->assertSame($interval, $form->getData());
        $this->assertSame($interval, $form->getViewData());
    }

    public function testSubmitArrayInteger()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array(
            'widget' => 'integer',
            'with_invert' => true,
        ));

        $years = '7';

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
            'invert' => true,
        ));

        $this->assertSame($years, $form['years']->getData());
        $this->assertSame($years, $form['years']->getViewData());
    }

    public function testInitializeWithDateInterval()
    {
        // Throws an exception if "data_class" option is not explicitly set
        // to null in the type
        $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y'));
    }

    public function testPassDefaultPlaceholderToViewIfNotRequired()
    {
        $view = $this->factory->create(static::TESTED_TYPE, null, array(
            'required' => false,
            'with_seconds' => true,
        ))
            ->createView();

        $this->assertSame('', $view['years']->vars['placeholder']);
        $this->assertSame('', $view['months']->vars['placeholder']);
        $this->assertSame('', $view['days']->vars['placeholder']);
        $this->assertSame('', $view['seconds']->vars['placeholder']);
    }

    public function testPassNoPlaceholderToViewIfRequired()
    {
        $view = $this->factory->create(static::TESTED_TYPE, null, array(
            'required' => true,
            'with_seconds' => true,
        ))
            ->createView();
<commit_msg>fix risky tests<commit_after><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormInterface;

class DateIntervalTypeTest extends BaseTypeTest
{
    const TESTED_TYPE = DateIntervalType::class;

    public function testSubmitDateInterval()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'dateinterval'));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
        ));

        $this->assertDateIntervalEquals(new \DateInterval('P7Y6M5D'), $form->getData());
    }

    public function testSubmitString()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'string'));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
        ));

        $this->assertSame('P7Y6M5D', $form->getData());
    }

    public function testSubmitArray()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'array'));

        $input = array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
        );

        $form->submit($input);

        $this->assertSame($input, $form->getData());
    }

    public function testSubmitWithoutMonths()
    {
        $interval = new \DateInterval('P7Y5D');

        $form = $this->factory->create(static::TESTED_TYPE, $interval, array(
            'input' => 'dateinterval',
            'with_months' => false,
        ));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
        ));

        $this->assertDateIntervalEquals($interval, $form->getData());
        $this->assertTrue($form->isSynchronized());
    }

    public function testSubmitWithTime()
    {
        $interval = new \DateInterval('P7Y6M5DT4H3M2S');
        $form = $this->factory->create(static::TESTED_TYPE, $interval, array(
            'input' => 'dateinterval',
            'with_hours' => true,
            'with_minutes' => true,
            'with_seconds' => true,
        ));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
            'hours' => '4',
            'minutes' => '3',
            'seconds' => '2',
        ));

        $this->assertDateIntervalEquals($interval, $form->getData());
        $this->assertTrue($form->isSynchronized());
    }

    public function testSubmitWithWeeks()
    {
        $form = $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y'), array(
            'input' => 'dateinterval',
            'with_years' => false,
            'with_months' => false,
            'with_weeks' => true,
            'with_days' => false,
        ));

        $form->submit(array(
            'weeks' => '30',
        ));

        $this->assertDateIntervalEquals(new \DateInterval('P30W'), $form->getData());
    }

    public function testSubmitWithInvert()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array(
            'input' => 'dateinterval',
            'with_invert' => true,
        ));

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
            'invert' => true,
        ));

        $interval = new \DateInterval('P7Y6M5D');
        $interval->invert = 1;

        $this->assertDateIntervalEquals($interval, $form->getData());
    }

    public function testSubmitStringSingleText()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array(
            'input' => 'string',
            'widget' => 'single_text',
        ));

        $interval = 'P7Y6M5D';

        $form->submit($interval);

        $this->assertSame($interval, $form->getData());
        $this->assertSame($interval, $form->getViewData());
    }

    public function testSubmitStringSingleTextWithSeconds()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array(
            'input' => 'string',
            'widget' => 'single_text',
            'with_hours' => true,
            'with_minutes' => true,
            'with_seconds' => true,
        ));

        $interval = 'P7Y6M5DT4H3M2S';

        $form->submit($interval);

        $this->assertSame($interval, $form->getData());
        $this->assertSame($interval, $form->getViewData());
    }

    public function testSubmitArrayInteger()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, array(
            'widget' => 'integer',
            'with_invert' => true,
        ));

        $years = '7';

        $form->submit(array(
            'years' => '7',
            'months' => '6',
            'days' => '5',
            'invert' => true,
        ));

        $this->assertSame($years, $form['years']->getData());
        $this->assertSame($years, $form['years']->getViewData());
    }

    public function testInitializeWithDateInterval()
    {
        // Throws an exception if "data_class" option is not explicitly set
        // to null in the type
        $this->assertInstanceOf(FormInterface::class, $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y')));
    }

    public function testPassDefaultPlaceholderToViewIfNotRequired()
    {
        $view = $this->factory->create(static::TESTED_TYPE, null, array(
            'required' => false,
            'with_seconds' => true,
        ))
            ->createView();

        $this->assertSame('', $view['years']->vars['placeholder']);
        $this->assertSame('', $view['months']->vars['placeholder']);
        $this->assertSame('', $view['days']->vars['placeholder']);
        $this->assertSame('', $view['seconds']->vars['placeholder']);
    }

    public function testPassNoPlaceholderToViewIfRequired()
    {
        $view = $this->factory->create(static::TESTED_TYPE, null, array(
            'required' => true,
            'with_seconds' => true,
        ))
            ->createView();

{'fraction_non_alphanumeric': 0.17400933322787313, 'fraction_numerical': 0.009175037570196947, 'mean_word_length': 2.178481649069884, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 276, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '669799', 'n_tokens_mistral': 3827, 'n_tokens_neox': 3715, 'n_words': 661}