Skip to content

Commit

Permalink
Add test to make sure form registry is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Parsiegla committed Dec 7, 2015
1 parent ada67d6 commit 09a3e8c
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions Tests/UnitTest/Resolver/FormAnnotationResolverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

/*
* This file is part of the ControllerExtraBundle for Symfony2.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <yuhu@mmoreram.com>
*/

namespace Mmoreram\ControllerExtraBundle\Tests\UnitTest\Resolver;

use Mmoreram\ControllerExtraBundle\Annotation\Form;
use Mmoreram\ControllerExtraBundle\Resolver\FormAnnotationResolver;
use Mmoreram\ControllerExtraBundle\Tests\FakeBundle\Form\Type\FakeType;
use PHPUnit_Framework_TestCase;
use ReflectionMethod;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormRegistryInterface;
use Symfony\Component\HttpFoundation\Request;

use Mmoreram\ControllerExtraBundle\Annotation\Abstracts\Annotation;

/**
* Tests FormAnnotationResolver class.
*/
class FormAnnotationResolverTest extends PHPUnit_Framework_TestCase
{
/**
* @var FormAnnotationResolver
*
* Form Annotation Resolver
*/
private $formAnnotationResolver;

/**
* @var Request
*
* Request
*/
private $request;

/**
* @var ReflectionMethod
*
* Reflection Method
*/
private $reflectionMethod;

/**
* @var Annotation
*
* Annotation
*/
private $annotation;

/**
* @var FormRegistryInterface
*/
private $formRegistry;

/**
* @var FormFactoryInterface
*/
private $formFactory;

/**
* Setup method.
*/
public function setUp()
{
$this->formRegistry = $this->getMock('Symfony\Component\Form\FormRegistryInterface');
$this->formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');

$requestParameterProvider = $this
->getMockBuilder('Mmoreram\ControllerExtraBundle\Provider\RequestParameterProvider')
->disableOriginalConstructor()
->setMethods([])
->getMock();

$requestParameterProvider
->expects($this->any())
->method('getParameterValue')
->will($this->returnValue(''));

$this->formAnnotationResolver = new FormAnnotationResolver(
$this->formRegistry,
$this->formFactory,
'form'
);

$this->request = new Request();

$this->annotation = $this
->getMockBuilder('Mmoreram\ControllerExtraBundle\Annotation\Entity')
->disableOriginalConstructor()
->setMethods([
'getClass',
'getName',
])
->getMock();

$this->reflectionMethod = new ReflectionMethod(
'Mmoreram\ControllerExtraBundle\Tests\FakeBundle\Controller\FakeController',
'formAction'
);
}

/**
* @test
*/
public function testFQDNUsesFormRegistry()
{
$resolvedFormTypeInterface = $this->getMock('Symfony\Component\Form\ResolvedFormTypeInterface');
$resolvedFormTypeInterface->method('getInnerType')->willReturn(new FakeType());

$class = 'Mmoreram\ControllerExtraBundle\Tests\FakeBundle\Form\Type\FakeType';
$annotation = new Form([
'class' => $class,
]);

$this
->formRegistry
->expects($this->once())
->method('getType')
->with($class)
->will($this->returnValue($resolvedFormTypeInterface));

$this->formAnnotationResolver->evaluateAnnotation($this->request, $annotation, $this->reflectionMethod);
}
}

0 comments on commit 09a3e8c

Please sign in to comment.