<commit_before><?php

namespace Piwi\Form\Handler;

use Mockery;
use Mockery\MockInterface;
use PHPUnit_Framework_TestCase;
use Piwi\Form\Exception\ValidationException;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\HttpFoundation\Request;

final class FormHandlerTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var FormFactoryInterface|MockInterface
     */
    private $formFactory;

    /**
     * @var FormTypeInterface|MockInterface
     */
    private $formType;

    /**
     * @var FormHandlerInterface
     */
    private $handler;

    /**
     * @var MockInterface
     */
    private $postProcessExpectation;

    public function setUp()
    {
        $this->formFactory = Mockery::mock(FormFactoryInterface::class);
        $this->formType = Mockery::mock(FormTypeInterface::class);
        $this->postProcessExpectation = Mockery::mock();
        $this->handler = new FormHandler($this->formFactory, $this->formType, $this->postProcessExpectation);
    }

    public function test_form_method()
    {
        $data = null;
        $options = [];

        $this->formFactory
            ->shouldReceive('create')
            ->once()
            ->withArgs([$this->formType, $data, $options])
            ;

        $this->handler->form($data, $options);
    }

    public function test_post_process()
    {
        $form = Mockery::mock(FormInterface::class);
        $request = Mockery::mock(Request::class);

        $form
            ->shouldReceive('handleRequest')
            ->withArgs([$request])
            ->once()
            ->andReturnUndefined()
            ;

        $this->postProcessExpectation
            ->shouldReceive('postProcess')
            ->withArgs([$form, $request])
            ->once()
            ->andReturnUndefined()
            ;

        $this->handler->process($form, $request);

        $this->assertSame($this->formFactory, $this->handler->getFormFactory());
        $this->assertSame($this->formType, $this->handler->getFormType());

        Mockery::close();
    }

    /**
     * @expectedException \Piwi\Form\Exception\ValidationException
     * @expectedExceptionMessage The form 'Foo' is invalid
     */
    public function test_validation_exception_depends_on_form()
    {
        $form = Mockery::mock(FormInterface::class);
        $form<commit_msg>This line got here for some reason, Mockery::close should not be called<commit_after><?php

namespace Piwi\Form\Handler;

use Mockery;
use Mockery\MockInterface;
use PHPUnit_Framework_TestCase;
use Piwi\Form\Exception\ValidationException;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\HttpFoundation\Request;

final class FormHandlerTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var FormFactoryInterface|MockInterface
     */
    private $formFactory;

    /**
     * @var FormTypeInterface|MockInterface
     */
    private $formType;

    /**
     * @var FormHandlerInterface
     */
    private $handler;

    /**
     * @var MockInterface
     */
    private $postProcessExpectation;

    public function setUp()
    {
        $this->formFactory = Mockery::mock(FormFactoryInterface::class);
        $this->formType = Mockery::mock(FormTypeInterface::class);
        $this->postProcessExpectation = Mockery::mock();
        $this->handler = new FormHandler($this->formFactory, $this->formType, $this->postProcessExpectation);
    }

    public function test_form_method()
    {
        $data = null;
        $options = [];

        $this->formFactory
            ->shouldReceive('create')
            ->once()
            ->withArgs([$this->formType, $data, $options])
            ;

        $this->handler->form($data, $options);
    }

    public function test_post_process()
    {
        $form = Mockery::mock(FormInterface::class);
        $request = Mockery::mock(Request::class);

        $form
            ->shouldReceive('handleRequest')
            ->withArgs([$request])
            ->once()
            ->andReturnUndefined()
            ;

        $this->postProcessExpectation
            ->shouldReceive('postProcess')
            ->withArgs([$form, $request])
            ->once()
            ->andReturnUndefined()
            ;

        $this->handler->process($form, $request);

        $this->assertSame($this->formFactory, $this->handler->getFormFactory());
        $this->assertSame($this->formType, $this->handler->getFormType());
    }

    /**
     * @expectedException \Piwi\Form\Exception\ValidationException
     * @expectedExceptionMessage The form 'Foo' is invalid
     */
    public function test_validation_exception_depends_on_form()
    {
        $form = Mockery::mock(FormInterface::class);
        $form
{'fraction_non_alphanumeric': 0.13170234454638124, 'fraction_numerical': 0.0, 'mean_word_length': 2.6448736998514115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '101034', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1328, 'n_words': 223}