init without trunk
This commit is contained in:
parent
ed24ac4994
commit
bb809e7233
14652 changed files with 177862 additions and 94817 deletions
101
vendor/sensio/framework-extra-bundle/Tests/Request/ParamConverter/DateTimeParamConverterTest.php
vendored
Normal file
101
vendor/sensio/framework-extra-bundle/Tests/Request/ParamConverter/DateTimeParamConverterTest.php
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\FrameworkExtraBundle\Tests\Request\ParamConverter;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\DateTimeParamConverter;
|
||||
|
||||
class DateTimeParamConverterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $converter;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->converter = new DateTimeParamConverter();
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$config = $this->createConfiguration('DateTime');
|
||||
$this->assertTrue($this->converter->supports($config));
|
||||
|
||||
$config = $this->createConfiguration(__CLASS__);
|
||||
$this->assertFalse($this->converter->supports($config));
|
||||
|
||||
$config = $this->createConfiguration();
|
||||
$this->assertFalse($this->converter->supports($config));
|
||||
}
|
||||
|
||||
public function testApply()
|
||||
{
|
||||
$request = new Request(array(), array(), array('start' => '2012-07-21 00:00:00'));
|
||||
$config = $this->createConfiguration('DateTime', 'start');
|
||||
|
||||
$this->converter->apply($request, $config);
|
||||
|
||||
$this->assertInstanceOf('DateTime', $request->attributes->get('start'));
|
||||
$this->assertEquals('2012-07-21', $request->attributes->get('start')->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testApplyInvalidDate404Exception()
|
||||
{
|
||||
$request = new Request(array(), array(), array('start' => 'Invalid DateTime Format'));
|
||||
$config = $this->createConfiguration('DateTime', 'start');
|
||||
|
||||
$this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'Invalid date given for parameter "start".');
|
||||
$this->converter->apply($request, $config);
|
||||
}
|
||||
|
||||
public function testApplyWithFormatInvalidDate404Exception()
|
||||
{
|
||||
$request = new Request(array(), array(), array('start' => '2012-07-21'));
|
||||
$config = $this->createConfiguration('DateTime', 'start');
|
||||
$config->expects($this->any())->method('getOptions')->will($this->returnValue(array('format' => 'd.m.Y')));
|
||||
|
||||
$this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'Invalid date given for parameter "start".');
|
||||
$this->converter->apply($request, $config);
|
||||
}
|
||||
|
||||
public function testApplyOptionalWithEmptyAttribute()
|
||||
{
|
||||
$request = new Request(array(), array(), array('start' => null));
|
||||
$config = $this->createConfiguration('DateTime', 'start');
|
||||
$config->expects($this->once())
|
||||
->method('isOptional')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertFalse($this->converter->apply($request, $config));
|
||||
$this->assertNull($request->attributes->get('start'));
|
||||
}
|
||||
|
||||
public function createConfiguration($class = null, $name = null)
|
||||
{
|
||||
$config = $this
|
||||
->getMockBuilder('Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter')
|
||||
->setMethods(array('getClass', 'getAliasName', 'getOptions', 'getName', 'allowArray', 'isOptional'))
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
if ($name !== null) {
|
||||
$config->expects($this->any())
|
||||
->method('getName')
|
||||
->will($this->returnValue($name));
|
||||
}
|
||||
if ($class !== null) {
|
||||
$config->expects($this->any())
|
||||
->method('getClass')
|
||||
->will($this->returnValue($class));
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
468
vendor/sensio/framework-extra-bundle/Tests/Request/ParamConverter/DoctrineParamConverterTest.php
vendored
Normal file
468
vendor/sensio/framework-extra-bundle/Tests/Request/ParamConverter/DoctrineParamConverterTest.php
vendored
Normal file
|
|
@ -0,0 +1,468 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\FrameworkExtraBundle\Tests\Request\ParamConverter;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\DoctrineParamConverter;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class DoctrineParamConverterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ManagerRegistry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @var DoctrineParamConverter
|
||||
*/
|
||||
private $converter;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
|
||||
$this->converter = new DoctrineParamConverter($this->registry);
|
||||
}
|
||||
|
||||
public function createConfiguration($class = null, array $options = null, $name = 'arg', $isOptional = false)
|
||||
{
|
||||
$methods = array('getClass', 'getAliasName', 'getOptions', 'getName', 'allowArray');
|
||||
if (null !== $isOptional) {
|
||||
$methods[] = 'isOptional';
|
||||
}
|
||||
$config = $this
|
||||
->getMockBuilder('Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter')
|
||||
->setMethods($methods)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
if ($options !== null) {
|
||||
$config->expects($this->once())
|
||||
->method('getOptions')
|
||||
->will($this->returnValue($options));
|
||||
}
|
||||
if ($class !== null) {
|
||||
$config->expects($this->any())
|
||||
->method('getClass')
|
||||
->will($this->returnValue($class));
|
||||
}
|
||||
$config->expects($this->any())
|
||||
->method('getName')
|
||||
->will($this->returnValue($name));
|
||||
if (null !== $isOptional) {
|
||||
$config->expects($this->any())
|
||||
->method('isOptional')
|
||||
->will($this->returnValue($isOptional));
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function testApplyWithNoIdAndData()
|
||||
{
|
||||
$request = new Request();
|
||||
$config = $this->createConfiguration(null, array());
|
||||
$objectManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
|
||||
$this->setExpectedException('LogicException');
|
||||
$this->converter->apply($request, $config);
|
||||
}
|
||||
|
||||
public function testApplyWithNoIdAndDataOptional()
|
||||
{
|
||||
$request = new Request();
|
||||
$config = $this->createConfiguration(null, array(), 'arg', true);
|
||||
$objectManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
|
||||
$ret = $this->converter->apply($request, $config);
|
||||
|
||||
$this->assertTrue($ret);
|
||||
$this->assertNull($request->attributes->get('arg'));
|
||||
}
|
||||
|
||||
public function testApplyWithStripNulls()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('arg', null);
|
||||
$config = $this->createConfiguration('stdClass', array('mapping' => array('arg' => 'arg'), 'strip_null' => true), 'arg', true);
|
||||
|
||||
$classMetadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock();
|
||||
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$manager->expects($this->once())
|
||||
->method('getClassMetadata')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($classMetadata));
|
||||
|
||||
$manager->expects($this->never())
|
||||
->method('getRepository');
|
||||
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($manager));
|
||||
|
||||
$classMetadata->expects($this->once())
|
||||
->method('hasField')
|
||||
->with($this->equalTo('arg'))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->converter->apply($request, $config);
|
||||
|
||||
$this->assertNull($request->attributes->get('arg'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider idsProvider
|
||||
*/
|
||||
public function testApplyWithId($id)
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('id', $id);
|
||||
|
||||
$config = $this->createConfiguration('stdClass', array('id' => 'id'), 'arg');
|
||||
|
||||
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$objectRepository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository')->getMock();
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($manager));
|
||||
|
||||
$manager->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($objectRepository));
|
||||
|
||||
$objectRepository->expects($this->once())
|
||||
->method('find')
|
||||
->with($this->equalTo($id))
|
||||
->will($this->returnValue($object = new \stdClass()));
|
||||
|
||||
$ret = $this->converter->apply($request, $config);
|
||||
|
||||
$this->assertTrue($ret);
|
||||
$this->assertSame($object, $request->attributes->get('arg'));
|
||||
}
|
||||
|
||||
public function testUsedProperIdentifier()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('id', 1);
|
||||
$request->attributes->set('entity_id', null);
|
||||
$request->attributes->set('arg', null);
|
||||
|
||||
$config = $this->createConfiguration('stdClass', array('id' => 'entity_id'), 'arg', null);
|
||||
|
||||
$ret = $this->converter->apply($request, $config);
|
||||
|
||||
$this->assertTrue($ret);
|
||||
$this->assertNull($request->attributes->get('arg'));
|
||||
}
|
||||
|
||||
public function idsProvider()
|
||||
{
|
||||
return array(
|
||||
array(1),
|
||||
array(0),
|
||||
array('foo'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testApplyGuessOptional()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('arg', null);
|
||||
|
||||
$config = $this->createConfiguration('stdClass', array(), 'arg', null);
|
||||
|
||||
$classMetadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock();
|
||||
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$manager->expects($this->once())
|
||||
->method('getClassMetadata')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($classMetadata));
|
||||
|
||||
$objectRepository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository')->getMock();
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($manager));
|
||||
|
||||
$manager->expects($this->never())->method('getRepository');
|
||||
|
||||
$objectRepository->expects($this->never())->method('find');
|
||||
$objectRepository->expects($this->never())->method('findOneBy');
|
||||
|
||||
$ret = $this->converter->apply($request, $config);
|
||||
|
||||
$this->assertTrue($ret);
|
||||
$this->assertNull($request->attributes->get('arg'));
|
||||
}
|
||||
|
||||
public function testApplyWithMappingAndExclude()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('foo', 1);
|
||||
$request->attributes->set('bar', 2);
|
||||
|
||||
$config = $this->createConfiguration(
|
||||
'stdClass',
|
||||
array('mapping' => array('foo' => 'Foo'), 'exclude' => array('bar')),
|
||||
'arg'
|
||||
);
|
||||
|
||||
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$metadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock();
|
||||
$repository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository')->getMock();
|
||||
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($manager));
|
||||
|
||||
$manager->expects($this->once())
|
||||
->method('getClassMetadata')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($metadata));
|
||||
$manager->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($repository));
|
||||
|
||||
$metadata->expects($this->once())
|
||||
->method('hasField')
|
||||
->with($this->equalTo('Foo'))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$repository->expects($this->once())
|
||||
->method('findOneBy')
|
||||
->with($this->equalTo(array('Foo' => 1)))
|
||||
->will($this->returnValue($object = new \stdClass()));
|
||||
|
||||
$ret = $this->converter->apply($request, $config);
|
||||
|
||||
$this->assertTrue($ret);
|
||||
$this->assertSame($object, $request->attributes->get('arg'));
|
||||
}
|
||||
|
||||
public function testApplyWithRepositoryMethod()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('id', 1);
|
||||
|
||||
$config = $this->createConfiguration(
|
||||
'stdClass',
|
||||
array('repository_method' => 'getClassName'),
|
||||
'arg'
|
||||
);
|
||||
|
||||
$objectRepository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository')->getMock();
|
||||
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$manager->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($objectRepository));
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->will($this->returnValue($manager));
|
||||
|
||||
$objectRepository->expects($this->once())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue($className = 'ObjectRepository'));
|
||||
|
||||
$ret = $this->converter->apply($request, $config);
|
||||
|
||||
$this->assertTrue($ret);
|
||||
$this->assertSame($className, $request->attributes->get('arg'));
|
||||
}
|
||||
|
||||
public function testApplyWithRepositoryMethodAndMapping()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('id', 1);
|
||||
|
||||
$config = $this->createConfiguration(
|
||||
'stdClass',
|
||||
array('repository_method' => 'getClassName', 'mapping' => array('foo' => 'Foo')),
|
||||
'arg'
|
||||
);
|
||||
|
||||
$objectManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$objectRepository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository')->getMock();
|
||||
$metadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock();
|
||||
|
||||
$objectManager->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($objectRepository));
|
||||
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->will($this->returnValue($objectManager));
|
||||
|
||||
$metadata->expects($this->once())
|
||||
->method('hasField')
|
||||
->with($this->equalTo('Foo'))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$objectManager->expects($this->once())
|
||||
->method('getClassMetadata')
|
||||
->will($this->returnValue($metadata));
|
||||
$objectManager->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($objectRepository));
|
||||
|
||||
$objectRepository->expects($this->once())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue($className = 'ObjectRepository'));
|
||||
|
||||
$ret = $this->converter->apply($request, $config);
|
||||
|
||||
$this->assertTrue($ret);
|
||||
$this->assertSame($className, $request->attributes->get('arg'));
|
||||
}
|
||||
|
||||
public function testApplyWithRepositoryMethodAndMapMethodSignature()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('first_name', 'Fabien');
|
||||
$request->attributes->set('last_name', 'Potencier');
|
||||
|
||||
$config = $this->createConfiguration(
|
||||
'stdClass',
|
||||
array(
|
||||
'repository_method' => 'findByFullName',
|
||||
'mapping' => array('first_name' => 'firstName', 'last_name' => 'lastName'),
|
||||
'map_method_signature' => true,
|
||||
),
|
||||
'arg'
|
||||
);
|
||||
|
||||
$objectManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$objectRepository = new TestUserRepository();
|
||||
$metadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock();
|
||||
|
||||
$objectManager->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($objectRepository));
|
||||
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->will($this->returnValue($objectManager));
|
||||
|
||||
$objectManager->expects($this->once())
|
||||
->method('getClassMetadata')
|
||||
->will($this->returnValue($metadata));
|
||||
|
||||
$ret = $this->converter->apply($request, $config);
|
||||
|
||||
$this->assertTrue($ret);
|
||||
$this->assertSame('Fabien Potencier', $request->attributes->get('arg'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Repository method "Sensio\Bundle\FrameworkExtraBundle\Tests\Request\ParamConverter\TestUserRepository::findByFullName" requires that you provide a value for the "$lastName" argument.
|
||||
*/
|
||||
public function testApplyWithRepositoryMethodAndMapMethodSignatureException()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('first_name', 'Fabien');
|
||||
$request->attributes->set('last_name', 'Potencier');
|
||||
|
||||
$config = $this->createConfiguration(
|
||||
'stdClass',
|
||||
array(
|
||||
'repository_method' => 'findByFullName',
|
||||
'mapping' => array('first_name' => 'firstName', 'last_name' => 'lastNameXxx'),
|
||||
'map_method_signature' => true,
|
||||
),
|
||||
'arg'
|
||||
);
|
||||
|
||||
$objectManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$objectRepository = new TestUserRepository();
|
||||
$metadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock();
|
||||
|
||||
$objectManager->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($objectRepository));
|
||||
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->will($this->returnValue($objectManager));
|
||||
|
||||
$objectManager->expects($this->once())
|
||||
->method('getClassMetadata')
|
||||
->will($this->returnValue($metadata));
|
||||
|
||||
$this->converter->apply($request, $config);
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$config = $this->createConfiguration('stdClass', array());
|
||||
$metadataFactory = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadataFactory')->getMock();
|
||||
$metadataFactory->expects($this->once())
|
||||
->method('isTransient')
|
||||
->with($this->equalTo('stdClass'))
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$objectManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$objectManager->expects($this->once())
|
||||
->method('getMetadataFactory')
|
||||
->will($this->returnValue($metadataFactory));
|
||||
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagers')
|
||||
->will($this->returnValue(array($objectManager)));
|
||||
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($objectManager));
|
||||
|
||||
$ret = $this->converter->supports($config);
|
||||
|
||||
$this->assertTrue($ret, 'Should be supported');
|
||||
}
|
||||
|
||||
public function testSupportsWithConfiguredEntityManager()
|
||||
{
|
||||
$config = $this->createConfiguration('stdClass', array('entity_manager' => 'foo'));
|
||||
$metadataFactory = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadataFactory')->getMock();
|
||||
$metadataFactory->expects($this->once())
|
||||
->method('isTransient')
|
||||
->with($this->equalTo('stdClass'))
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$objectManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock();
|
||||
$objectManager->expects($this->once())
|
||||
->method('getMetadataFactory')
|
||||
->will($this->returnValue($metadataFactory));
|
||||
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManagers')
|
||||
->will($this->returnValue(array($objectManager)));
|
||||
|
||||
$this->registry->expects($this->once())
|
||||
->method('getManager')
|
||||
->with('foo')
|
||||
->will($this->returnValue($objectManager));
|
||||
|
||||
$ret = $this->converter->supports($config);
|
||||
|
||||
$this->assertTrue($ret, 'Should be supported');
|
||||
}
|
||||
}
|
||||
175
vendor/sensio/framework-extra-bundle/Tests/Request/ParamConverter/ParamConverterManagerTest.php
vendored
Normal file
175
vendor/sensio/framework-extra-bundle/Tests/Request/ParamConverter/ParamConverterManagerTest.php
vendored
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\FrameworkExtraBundle\Tests\Request\ParamConverter;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterManager;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ParamConverterManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testPriorities()
|
||||
{
|
||||
$manager = new ParamConverterManager();
|
||||
$this->assertEquals(array(), $manager->all());
|
||||
|
||||
$high = $this->createParamConverterMock();
|
||||
$low = $this->createParamConverterMock();
|
||||
|
||||
$manager->add($low);
|
||||
$manager->add($high, 10);
|
||||
|
||||
$this->assertEquals(array($high, $low), $manager->all());
|
||||
}
|
||||
|
||||
public function testApply()
|
||||
{
|
||||
$supported = $this->createParamConverterMock();
|
||||
$supported
|
||||
->expects($this->once())
|
||||
->method('supports')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
$supported
|
||||
->expects($this->once())
|
||||
->method('apply')
|
||||
->will($this->returnValue(false))
|
||||
;
|
||||
|
||||
$invalid = $this->createParamConverterMock();
|
||||
$invalid
|
||||
->expects($this->once())
|
||||
->method('supports')
|
||||
->will($this->returnValue(false))
|
||||
;
|
||||
$invalid
|
||||
->expects($this->never())
|
||||
->method('apply')
|
||||
;
|
||||
|
||||
$configurations = array(
|
||||
new Configuration\ParamConverter(array(
|
||||
'name' => 'var',
|
||||
)),
|
||||
);
|
||||
|
||||
$manager = new ParamConverterManager();
|
||||
$manager->add($supported);
|
||||
$manager->add($invalid);
|
||||
$manager->apply(new Request(), $configurations);
|
||||
}
|
||||
|
||||
public function testApplyNamedConverter()
|
||||
{
|
||||
$converter = $this->createParamConverterMock();
|
||||
$converter
|
||||
->expects($this->any())
|
||||
->method('supports')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$converter
|
||||
->expects($this->any())
|
||||
->method('apply')
|
||||
;
|
||||
|
||||
$request = new Request();
|
||||
$request->attributes->set('param', '1234');
|
||||
|
||||
$configuration = new Configuration\ParamConverter(array(
|
||||
'name' => 'param',
|
||||
'class' => 'stdClass',
|
||||
'converter' => 'test',
|
||||
));
|
||||
|
||||
$manager = new ParamConverterManager();
|
||||
$manager->add($converter, 0, 'test');
|
||||
$manager->apply($request, array($configuration));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage Converter 'test' does not support conversion of parameter 'param'.
|
||||
*/
|
||||
public function testApplyNamedConverterNotSupportsParameter()
|
||||
{
|
||||
$converter = $this->createParamConverterMock();
|
||||
$converter
|
||||
->expects($this->any())
|
||||
->method('supports')
|
||||
->will($this->returnValue(false))
|
||||
;
|
||||
|
||||
$request = new Request();
|
||||
$request->attributes->set('param', '1234');
|
||||
|
||||
$configuration = new Configuration\ParamConverter(array(
|
||||
'name' => 'param',
|
||||
'class' => 'stdClass',
|
||||
'converter' => 'test',
|
||||
));
|
||||
|
||||
$manager = new ParamConverterManager();
|
||||
$manager->add($converter, 0, 'test');
|
||||
$manager->apply($request, array($configuration));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage No converter named 'test' found for conversion of parameter 'param'.
|
||||
*/
|
||||
public function testApplyNamedConverterNoConverter()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->attributes->set('param', '1234');
|
||||
|
||||
$configuration = new Configuration\ParamConverter(array(
|
||||
'name' => 'param',
|
||||
'class' => 'stdClass',
|
||||
'converter' => 'test',
|
||||
));
|
||||
|
||||
$manager = new ParamConverterManager();
|
||||
$manager->apply($request, array($configuration));
|
||||
}
|
||||
|
||||
public function testApplyNotCalledOnAlreadyConvertedObjects()
|
||||
{
|
||||
$converter = $this->createParamConverterMock();
|
||||
$converter
|
||||
->expects($this->never())
|
||||
->method('supports')
|
||||
;
|
||||
|
||||
$converter
|
||||
->expects($this->never())
|
||||
->method('apply')
|
||||
;
|
||||
|
||||
$request = new Request();
|
||||
$request->attributes->set('converted', new \stdClass());
|
||||
|
||||
$configuration = new Configuration\ParamConverter(array(
|
||||
'name' => 'converted',
|
||||
'class' => 'stdClass',
|
||||
));
|
||||
|
||||
$manager = new ParamConverterManager();
|
||||
$manager->add($converter);
|
||||
$manager->apply($request, array($configuration));
|
||||
}
|
||||
|
||||
protected function createParamConverterMock()
|
||||
{
|
||||
return $this->getMockBuilder('Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface')->getMock();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\FrameworkExtraBundle\Tests\Request\ParamConverter;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\PsrServerRequestParamConverter;
|
||||
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
* @requires PHP 5.4
|
||||
*/
|
||||
class PsrServerRequestParamConverterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$converter = new PsrServerRequestParamConverter(new DiactorosFactory());
|
||||
$config = $this->createConfiguration('Psr\Http\Message\ServerRequestInterface');
|
||||
$this->assertTrue($converter->supports($config));
|
||||
|
||||
$config = $this->createConfiguration('Psr\Http\Message\RequestInterface');
|
||||
$this->assertTrue($converter->supports($config));
|
||||
|
||||
$config = $this->createConfiguration('Psr\Http\Message\MessageInterface');
|
||||
$this->assertTrue($converter->supports($config));
|
||||
|
||||
$config = $this->createConfiguration(__CLASS__);
|
||||
$this->assertFalse($converter->supports($config));
|
||||
|
||||
$config = $this->createConfiguration();
|
||||
$this->assertFalse($converter->supports($config));
|
||||
}
|
||||
|
||||
public function testApply()
|
||||
{
|
||||
$converter = new PsrServerRequestParamConverter(new DiactorosFactory());
|
||||
$request = new Request(
|
||||
array('foo' => 'bar'),
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
array('HTTP_HOST' => 'dunglas.fr')
|
||||
);
|
||||
$config = $this->createConfiguration('Psr\Http\Message\ServerRequestInterface', 'request');
|
||||
|
||||
$converter->apply($request, $config);
|
||||
|
||||
$this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $request->attributes->get('request'));
|
||||
$this->assertEquals('bar', $request->query->get('foo'));
|
||||
}
|
||||
|
||||
private function createConfiguration($class = null, $name = null)
|
||||
{
|
||||
$config = $this
|
||||
->getMockBuilder('Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter')
|
||||
->setMethods(array('getClass', 'getAliasName', 'getOptions', 'getName', 'allowArray', 'isOptional'))
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
|
||||
if (null !== $name) {
|
||||
$config->expects($this->any())
|
||||
->method('getName')
|
||||
->will($this->returnValue($name));
|
||||
}
|
||||
if (null !== $class) {
|
||||
$config->expects($this->any())
|
||||
->method('getClass')
|
||||
->will($this->returnValue($class));
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
23
vendor/sensio/framework-extra-bundle/Tests/Request/ParamConverter/TestUserRepository.php
vendored
Normal file
23
vendor/sensio/framework-extra-bundle/Tests/Request/ParamConverter/TestUserRepository.php
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\FrameworkExtraBundle\Tests\Request\ParamConverter;
|
||||
|
||||
/*
|
||||
* This class is a helper Repository for DoctrineParamConverter's map_method_signature functionality
|
||||
*/
|
||||
class TestUserRepository
|
||||
{
|
||||
public function findByFullName($firstName, $lastName)
|
||||
{
|
||||
return $firstName.' '.$lastName;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue