-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to make sure form registry is used
- Loading branch information
Martin Parsiegla
committed
Dec 7, 2015
1 parent
ada67d6
commit 09a3e8c
Showing
1 changed file
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |