<commit_before><?php

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

namespace Integrated\Bundle\WorkflowBundle\Tests\Form\EventListener;

use Integrated\Bundle\WorkflowBundle\Entity\Definition;
use Integrated\Bundle\WorkflowBundle\Form\EventListener\ExtractDefaultStateFromCollectionListener;

/**
 * @author <NAME> <<EMAIL>>
 */
class ExtractDefaultStateFromCollectionListenerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Symfony\Component\Form\FormInterface | \PHPUnit_Framework_MockObject_MockObject
     */
    private $form;

    /**
     * @var \Symfony\Component\Form\FormEvent | \PHPUnit_Framework_MockObject_MockObject
     */
    private $event;

    /**
     * @var Definition
     */
    private $definition;

    /**
     * Set up the test
     */
    public function setUp()
    {
        $this->event = $this->getMock('Symfony\Component\Form\FormEvent', [], [], '', false);
        $this->form = $this->getMock('Symfony\Component\Form\FormInterface');
        $this->definition = new Definition();
    }

    /**
     * Test instance of
     */
    public function testInstanceOf()
    {
        $instance = $this->getInstance();
        $this->assertInstanceOf('Symfony\Component\EventDispatcher\EventSubscriberInterface', $instance);
    }

    /**
     * Test getSubscribedEvents function
     */
    public function testGetSubscribedEvents()
    {
        $instance = $this->getInstance();
        $this->assertCount(3, $instance::getSubscribedEvents());
    }

    /**
     * Test onPreSubmit event
     */
    public function testOnPreSubmit()
    {
        $instance = $this->getInstance();

        // Stub getForm function
        $this->event
            ->expects($this->once())
            ->method('getForm')
            ->will($this->returnValue($this->form))
        ;

        // Stub getData function
        $this->form
            ->expects($this->once())
            ->method('getData')
            ->will($this->returnValue($this->definition))
        ;

        /** @var \Integrated\Bundle\WorkflowBundle\Entity\Definition\State | \PHPUnit_Framework_MockObject_MockObject $state */
        $state = $this->getMock('Integrated\Bundle\WorkflowBundle\Entity\Definition\State');

        // Set default state<commit_msg>Improve getSubscribedEvents test<commit_after><?php

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

namespace Integrated\Bundle\WorkflowBundle\Tests\Form\EventListener;

use Integrated\Bundle\WorkflowBundle\Entity\Definition;
use Integrated\Bundle\WorkflowBundle\Form\EventListener\ExtractDefaultStateFromCollectionListener;
use Symfony\Component\Form\FormEvents;

/**
 * @author <NAME> <<EMAIL>>
 */
class ExtractDefaultStateFromCollectionListenerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Symfony\Component\Form\FormInterface | \PHPUnit_Framework_MockObject_MockObject
     */
    private $form;

    /**
     * @var \Symfony\Component\Form\FormEvent | \PHPUnit_Framework_MockObject_MockObject
     */
    private $event;

    /**
     * @var Definition
     */
    private $definition;

    /**
     * Set up the test
     */
    public function setUp()
    {
        $this->event = $this->getMock('Symfony\Component\Form\FormEvent', [], [], '', false);
        $this->form = $this->getMock('Symfony\Component\Form\FormInterface');
        $this->definition = new Definition();
    }

    /**
     * Test instance of
     */
    public function testInstanceOf()
    {
        $instance = $this->getInstance();
        $this->assertInstanceOf('Symfony\Component\EventDispatcher\EventSubscriberInterface', $instance);
    }

    /**
     * Test getSubscribedEvents function
     */
    public function testGetSubscribedEvents()
    {
        $instance = $this->getInstance();

        $events = array(
            FormEvents::PRE_SUBMIT => 'onPreSubmit',
            FormEvents::POST_SET_DATA => 'onPostSetData',
            FormEvents::SUBMIT => 'onSubmit'
        );

        $this->assertSame($events, $instance::getSubscribedEvents());
    }

    /**
     * Test onPreSubmit event
     */
    public function testOnPreSubmit()
    {
        $instance = $this->getInstance();

        // Stub getForm function
        $this->event
            ->expects($this->once())
            ->method('getForm')
            ->will($this->returnValue($this->form))
        ;

        // Stub getData function
        $this->form
            ->expects($this->once())
            ->method('getData')
            ->will($this->returnValue($this->definition))
        ;

        /** @var \Integrated\Bundle\WorkflowBundle\Entity\Definition\State | \PHPUnit_Framework_MockObject_MockObject $state */
        $state = $this->getMock('Integrated\Bundle\WorkflowBundle\Entity\Definition\State');

        // Set default state
{'fraction_non_alphanumeric': 0.13444725082572373, 'fraction_numerical': 0.00019428793471925395, 'mean_word_length': 2.63302752293578, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 66, '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': '2372488', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1402, 'n_words': 261}