[Form] fix return type declarations
This commit is contained in:
parent
a32a713045
commit
8706f18ea8
@ -27,7 +27,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
|
|||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $disabled;
|
private $disabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ResolvedFormTypeInterface
|
* @var ResolvedFormTypeInterface
|
||||||
|
@ -26,6 +26,7 @@ class ButtonType extends BaseType implements ButtonTypeInterface
|
|||||||
*/
|
*/
|
||||||
public function getParent()
|
public function getParent()
|
||||||
{
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -190,6 +190,7 @@ class FormType extends BaseType
|
|||||||
*/
|
*/
|
||||||
public function getParent()
|
public function getParent()
|
||||||
{
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,7 +127,7 @@ class FormError implements \Serializable
|
|||||||
/**
|
/**
|
||||||
* Returns the form that caused this error.
|
* Returns the form that caused this error.
|
||||||
*
|
*
|
||||||
* @return FormInterface The form that caused this error
|
* @return FormInterface|null The form that caused this error
|
||||||
*/
|
*/
|
||||||
public function getOrigin()
|
public function getOrigin()
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
|
|||||||
* @throws Exception\LogicException when trying to set a parent for a form with
|
* @throws Exception\LogicException when trying to set a parent for a form with
|
||||||
* an empty name
|
* an empty name
|
||||||
*/
|
*/
|
||||||
public function setParent(self $parent = null);
|
public function setParent(FormInterface $parent = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parent form.
|
* Returns the parent form.
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Test\Traits;
|
|||||||
|
|
||||||
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
|
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
use Symfony\Component\Form\Test\TypeTestCase;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
@ -37,9 +38,9 @@ trait ValidatorExtensionTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->validator = $this->getMockBuilder(ValidatorInterface::class)->getMock();
|
$this->validator = $this->getMockBuilder(ValidatorInterface::class)->getMock();
|
||||||
$metadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->setMethods(['addPropertyConstraint'])->getMock();
|
$metadata = $this->getMockBuilder(ClassMetadata::class)->setConstructorArgs([''])->setMethods(['addPropertyConstraint'])->getMock();
|
||||||
$this->validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
|
$this->validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
|
||||||
$this->validator->expects($this->any())->method('validate')->will($this->returnValue([]));
|
$this->validator->expects($this->any())->method('validate')->will($this->returnValue(new ConstraintViolationList()));
|
||||||
|
|
||||||
return new ValidatorExtension($this->validator);
|
return new ValidatorExtension($this->validator);
|
||||||
}
|
}
|
||||||
|
@ -346,7 +346,7 @@ abstract class AbstractRequestHandlerTest extends TestCase
|
|||||||
[1024, '1K', false],
|
[1024, '1K', false],
|
||||||
[null, '1K', false],
|
[null, '1K', false],
|
||||||
[1024, '', false],
|
[1024, '', false],
|
||||||
[1024, 0, false],
|
[1024, '0', false],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,9 @@ namespace Symfony\Component\Form\Tests\ChoiceList\Factory;
|
|||||||
|
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||||
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
|
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
|
||||||
|
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
@ -38,7 +40,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
|
|
||||||
public function testCreateFromChoicesEmpty()
|
public function testCreateFromChoicesEmpty()
|
||||||
{
|
{
|
||||||
$list = new \stdClass();
|
$list = new ArrayChoiceList([]);
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createListFromChoices')
|
->method('createListFromChoices')
|
||||||
@ -54,7 +56,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
// The top-most traversable is converted to an array
|
// The top-most traversable is converted to an array
|
||||||
$choices1 = new \ArrayIterator(['A' => 'a']);
|
$choices1 = new \ArrayIterator(['A' => 'a']);
|
||||||
$choices2 = ['A' => 'a'];
|
$choices2 = ['A' => 'a'];
|
||||||
$list = new \stdClass();
|
$list = new ArrayChoiceList([]);
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createListFromChoices')
|
->method('createListFromChoices')
|
||||||
@ -69,8 +71,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$choices1 = ['key' => ['A' => 'a']];
|
$choices1 = ['key' => ['A' => 'a']];
|
||||||
$choices2 = ['A' => 'a'];
|
$choices2 = ['A' => 'a'];
|
||||||
$list1 = new \stdClass();
|
$list1 = new ArrayChoiceList([]);
|
||||||
$list2 = new \stdClass();
|
$list2 = new ArrayChoiceList([]);
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createListFromChoices')
|
->method('createListFromChoices')
|
||||||
@ -92,7 +94,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$choices1 = [$choice1];
|
$choices1 = [$choice1];
|
||||||
$choices2 = [$choice2];
|
$choices2 = [$choice2];
|
||||||
$list = new \stdClass();
|
$list = new ArrayChoiceList([]);
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createListFromChoices')
|
->method('createListFromChoices')
|
||||||
@ -110,8 +112,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$choices1 = [$choice1];
|
$choices1 = [$choice1];
|
||||||
$choices2 = [$choice2];
|
$choices2 = [$choice2];
|
||||||
$list1 = new \stdClass();
|
$list1 = new ArrayChoiceList([]);
|
||||||
$list2 = new \stdClass();
|
$list2 = new ArrayChoiceList([]);
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createListFromChoices')
|
->method('createListFromChoices')
|
||||||
@ -129,7 +131,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
public function testCreateFromChoicesSameValueClosure()
|
public function testCreateFromChoicesSameValueClosure()
|
||||||
{
|
{
|
||||||
$choices = [1];
|
$choices = [1];
|
||||||
$list = new \stdClass();
|
$list = new ArrayChoiceList([]);
|
||||||
$closure = function () {};
|
$closure = function () {};
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
@ -144,8 +146,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
public function testCreateFromChoicesDifferentValueClosure()
|
public function testCreateFromChoicesDifferentValueClosure()
|
||||||
{
|
{
|
||||||
$choices = [1];
|
$choices = [1];
|
||||||
$list1 = new \stdClass();
|
$list1 = new ArrayChoiceList([]);
|
||||||
$list2 = new \stdClass();
|
$list2 = new ArrayChoiceList([]);
|
||||||
$closure1 = function () {};
|
$closure1 = function () {};
|
||||||
$closure2 = function () {};
|
$closure2 = function () {};
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
public function testCreateFromLoaderSameLoader()
|
public function testCreateFromLoaderSameLoader()
|
||||||
{
|
{
|
||||||
$loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
$loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
||||||
$list = new \stdClass();
|
$list = new ArrayChoiceList([]);
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createListFromLoader')
|
->method('createListFromLoader')
|
||||||
@ -180,8 +182,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$loader1 = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
$loader1 = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
||||||
$loader2 = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
$loader2 = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
||||||
$list1 = new \stdClass();
|
$list1 = new ArrayChoiceList([]);
|
||||||
$list2 = new \stdClass();
|
$list2 = new ArrayChoiceList([]);
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createListFromLoader')
|
->method('createListFromLoader')
|
||||||
@ -199,7 +201,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
public function testCreateFromLoaderSameValueClosure()
|
public function testCreateFromLoaderSameValueClosure()
|
||||||
{
|
{
|
||||||
$loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
$loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
||||||
$list = new \stdClass();
|
$list = new ArrayChoiceList([]);
|
||||||
$closure = function () {};
|
$closure = function () {};
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
@ -214,8 +216,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
public function testCreateFromLoaderDifferentValueClosure()
|
public function testCreateFromLoaderDifferentValueClosure()
|
||||||
{
|
{
|
||||||
$loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
$loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
|
||||||
$list1 = new \stdClass();
|
$list1 = new ArrayChoiceList([]);
|
||||||
$list2 = new \stdClass();
|
$list2 = new ArrayChoiceList([]);
|
||||||
$closure1 = function () {};
|
$closure1 = function () {};
|
||||||
$closure2 = function () {};
|
$closure2 = function () {};
|
||||||
|
|
||||||
@ -236,7 +238,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$preferred = ['a'];
|
$preferred = ['a'];
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view = new \stdClass();
|
$view = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -252,8 +254,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
$preferred1 = ['a'];
|
$preferred1 = ['a'];
|
||||||
$preferred2 = ['b'];
|
$preferred2 = ['b'];
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view1 = new \stdClass();
|
$view1 = new ChoiceListView();
|
||||||
$view2 = new \stdClass();
|
$view2 = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -272,7 +274,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$preferred = function () {};
|
$preferred = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view = new \stdClass();
|
$view = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -288,8 +290,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
$preferred1 = function () {};
|
$preferred1 = function () {};
|
||||||
$preferred2 = function () {};
|
$preferred2 = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view1 = new \stdClass();
|
$view1 = new ChoiceListView();
|
||||||
$view2 = new \stdClass();
|
$view2 = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -308,7 +310,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$labels = function () {};
|
$labels = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view = new \stdClass();
|
$view = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -324,8 +326,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
$labels1 = function () {};
|
$labels1 = function () {};
|
||||||
$labels2 = function () {};
|
$labels2 = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view1 = new \stdClass();
|
$view1 = new ChoiceListView();
|
||||||
$view2 = new \stdClass();
|
$view2 = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -344,7 +346,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$index = function () {};
|
$index = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view = new \stdClass();
|
$view = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -360,8 +362,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
$index1 = function () {};
|
$index1 = function () {};
|
||||||
$index2 = function () {};
|
$index2 = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view1 = new \stdClass();
|
$view1 = new ChoiceListView();
|
||||||
$view2 = new \stdClass();
|
$view2 = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -380,7 +382,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$groupBy = function () {};
|
$groupBy = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view = new \stdClass();
|
$view = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -396,8 +398,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
$groupBy1 = function () {};
|
$groupBy1 = function () {};
|
||||||
$groupBy2 = function () {};
|
$groupBy2 = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view1 = new \stdClass();
|
$view1 = new ChoiceListView();
|
||||||
$view2 = new \stdClass();
|
$view2 = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -416,7 +418,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$attr = ['class' => 'foobar'];
|
$attr = ['class' => 'foobar'];
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view = new \stdClass();
|
$view = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -432,8 +434,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
$attr1 = ['class' => 'foobar1'];
|
$attr1 = ['class' => 'foobar1'];
|
||||||
$attr2 = ['class' => 'foobar2'];
|
$attr2 = ['class' => 'foobar2'];
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view1 = new \stdClass();
|
$view1 = new ChoiceListView();
|
||||||
$view2 = new \stdClass();
|
$view2 = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -452,7 +454,7 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$attr = function () {};
|
$attr = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view = new \stdClass();
|
$view = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->once())
|
$this->decoratedFactory->expects($this->once())
|
||||||
->method('createView')
|
->method('createView')
|
||||||
@ -468,8 +470,8 @@ class CachingFactoryDecoratorTest extends TestCase
|
|||||||
$attr1 = function () {};
|
$attr1 = function () {};
|
||||||
$attr2 = function () {};
|
$attr2 = function () {};
|
||||||
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
|
||||||
$view1 = new \stdClass();
|
$view1 = new ChoiceListView();
|
||||||
$view2 = new \stdClass();
|
$view2 = new ChoiceListView();
|
||||||
|
|
||||||
$this->decoratedFactory->expects($this->at(0))
|
$this->decoratedFactory->expects($this->at(0))
|
||||||
->method('createView')
|
->method('createView')
|
||||||
|
@ -13,7 +13,9 @@ namespace Symfony\Component\Form\Tests\ChoiceList\Factory;
|
|||||||
|
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||||
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
|
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
|
||||||
|
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
|
||||||
use Symfony\Component\PropertyAccess\PropertyPath;
|
use Symfony\Component\PropertyAccess\PropertyPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,10 +47,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createListFromChoices')
|
->method('createListFromChoices')
|
||||||
->with($choices, $this->isInstanceOf('\Closure'))
|
->with($choices, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($choices, $callback) {
|
->willReturnCallback(function ($choices, $callback) {
|
||||||
return array_map($callback, $choices);
|
return new ArrayChoiceList(array_map($callback, $choices));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame(['value'], $this->factory->createListFromChoices($choices, 'property'));
|
$this->assertSame(['value' => 'value'], $this->factory->createListFromChoices($choices, 'property')->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateFromChoicesPropertyPathInstance()
|
public function testCreateFromChoicesPropertyPathInstance()
|
||||||
@ -59,10 +61,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createListFromChoices')
|
->method('createListFromChoices')
|
||||||
->with($choices, $this->isInstanceOf('\Closure'))
|
->with($choices, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($choices, $callback) {
|
->willReturnCallback(function ($choices, $callback) {
|
||||||
return array_map($callback, $choices);
|
return new ArrayChoiceList(array_map($callback, $choices));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame(['value'], $this->factory->createListFromChoices($choices, new PropertyPath('property')));
|
$this->assertSame(['value' => 'value'], $this->factory->createListFromChoices($choices, new PropertyPath('property'))->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,10 +90,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createListFromLoader')
|
->method('createListFromLoader')
|
||||||
->with($loader, $this->isInstanceOf('\Closure'))
|
->with($loader, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($loader, $callback) {
|
->willReturnCallback(function ($loader, $callback) {
|
||||||
return $callback((object) ['property' => 'value']);
|
return new ArrayChoiceList((array) $callback((object) ['property' => 'value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('value', $this->factory->createListFromLoader($loader, 'property'));
|
$this->assertSame(['value' => 'value'], $this->factory->createListFromLoader($loader, 'property')->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,10 +120,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createListFromChoices')
|
->method('createListFromChoices')
|
||||||
->with($choices, $this->isInstanceOf('\Closure'))
|
->with($choices, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($choices, $callback) {
|
->willReturnCallback(function ($choices, $callback) {
|
||||||
return array_map($callback, $choices);
|
return new ArrayChoiceList(array_map($callback, $choices));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame([null], $this->factory->createListFromChoices($choices, 'property'));
|
$this->assertSame([null], $this->factory->createListFromChoices($choices, 'property')->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/symfony/symfony/issues/5494
|
// https://github.com/symfony/symfony/issues/5494
|
||||||
@ -133,10 +135,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createListFromLoader')
|
->method('createListFromLoader')
|
||||||
->with($loader, $this->isInstanceOf('\Closure'))
|
->with($loader, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($loader, $callback) {
|
->willReturnCallback(function ($loader, $callback) {
|
||||||
return $callback(null);
|
return new ArrayChoiceList((array) $callback(null));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertNull($this->factory->createListFromLoader($loader, 'property'));
|
$this->assertSame([], $this->factory->createListFromLoader($loader, 'property')->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateFromLoaderPropertyPathInstance()
|
public function testCreateFromLoaderPropertyPathInstance()
|
||||||
@ -147,10 +149,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createListFromLoader')
|
->method('createListFromLoader')
|
||||||
->with($loader, $this->isInstanceOf('\Closure'))
|
->with($loader, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($loader, $callback) {
|
->willReturnCallback(function ($loader, $callback) {
|
||||||
return $callback((object) ['property' => 'value']);
|
return new ArrayChoiceList((array) $callback((object) ['property' => 'value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('value', $this->factory->createListFromLoader($loader, new PropertyPath('property')));
|
$this->assertSame(['value' => 'value'], $this->factory->createListFromLoader($loader, new PropertyPath('property'))->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateViewPreferredChoicesAsPropertyPath()
|
public function testCreateViewPreferredChoicesAsPropertyPath()
|
||||||
@ -161,13 +163,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, $this->isInstanceOf('\Closure'))
|
->with($list, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred) {
|
->willReturnCallback(function ($list, $preferred) {
|
||||||
return $preferred((object) ['property' => true]);
|
return new ChoiceListView((array) $preferred((object) ['property' => true]));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertTrue($this->factory->createView(
|
$this->assertSame([true], $this->factory->createView($list, 'property')->choices);
|
||||||
$list,
|
|
||||||
'property'
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,13 +195,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, $this->isInstanceOf('\Closure'))
|
->with($list, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred) {
|
->willReturnCallback(function ($list, $preferred) {
|
||||||
return $preferred((object) ['property' => true]);
|
return new ChoiceListView((array) $preferred((object) ['property' => true]));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertTrue($this->factory->createView(
|
$this->assertSame([true], $this->factory->createView($list, 'property')->choices);
|
||||||
$list,
|
|
||||||
new PropertyPath('property')
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/symfony/symfony/issues/5494
|
// https://github.com/symfony/symfony/issues/5494
|
||||||
@ -214,13 +210,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, $this->isInstanceOf('\Closure'))
|
->with($list, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred) {
|
->willReturnCallback(function ($list, $preferred) {
|
||||||
return $preferred((object) ['category' => null]);
|
return new ChoiceListView((array) $preferred((object) ['category' => null]));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertFalse($this->factory->createView(
|
$this->assertSame([false], $this->factory->createView($list, 'category.preferred')->choices);
|
||||||
$list,
|
|
||||||
'category.preferred'
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateViewLabelsAsPropertyPath()
|
public function testCreateViewLabelsAsPropertyPath()
|
||||||
@ -231,14 +224,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, null, $this->isInstanceOf('\Closure'))
|
->with($list, null, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred, $label) {
|
->willReturnCallback(function ($list, $preferred, $label) {
|
||||||
return $label((object) ['property' => 'label']);
|
return new ChoiceListView((array) $label((object) ['property' => 'label']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('label', $this->factory->createView(
|
$this->assertSame(['label'], $this->factory->createView($list, null, 'property')->choices);
|
||||||
$list,
|
|
||||||
null, // preferred choices
|
|
||||||
'property'
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -268,14 +257,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, null, $this->isInstanceOf('\Closure'))
|
->with($list, null, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred, $label) {
|
->willReturnCallback(function ($list, $preferred, $label) {
|
||||||
return $label((object) ['property' => 'label']);
|
return new ChoiceListView((array) $label((object) ['property' => 'label']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('label', $this->factory->createView(
|
$this->assertSame(['label'], $this->factory->createView($list, null, new PropertyPath('property'))->choices);
|
||||||
$list,
|
|
||||||
null, // preferred choices
|
|
||||||
new PropertyPath('property')
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateViewIndicesAsPropertyPath()
|
public function testCreateViewIndicesAsPropertyPath()
|
||||||
@ -286,15 +271,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, null, null, $this->isInstanceOf('\Closure'))
|
->with($list, null, null, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred, $label, $index) {
|
->willReturnCallback(function ($list, $preferred, $label, $index) {
|
||||||
return $index((object) ['property' => 'index']);
|
return new ChoiceListView((array) $index((object) ['property' => 'index']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('index', $this->factory->createView(
|
$this->assertSame(['index'], $this->factory->createView($list, null, null, 'property')->choices);
|
||||||
$list,
|
|
||||||
null, // preferred choices
|
|
||||||
null, // label
|
|
||||||
'property'
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -325,15 +305,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, null, null, $this->isInstanceOf('\Closure'))
|
->with($list, null, null, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred, $label, $index) {
|
->willReturnCallback(function ($list, $preferred, $label, $index) {
|
||||||
return $index((object) ['property' => 'index']);
|
return new ChoiceListView((array) $index((object) ['property' => 'index']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('index', $this->factory->createView(
|
$this->assertSame(['index'], $this->factory->createView($list, null, null, new PropertyPath('property'))->choices);
|
||||||
$list,
|
|
||||||
null, // preferred choices
|
|
||||||
null, // label
|
|
||||||
new PropertyPath('property')
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateViewGroupsAsPropertyPath()
|
public function testCreateViewGroupsAsPropertyPath()
|
||||||
@ -344,16 +319,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, null, null, null, $this->isInstanceOf('\Closure'))
|
->with($list, null, null, null, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
|
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
|
||||||
return $groupBy((object) ['property' => 'group']);
|
return new ChoiceListView((array) $groupBy((object) ['property' => 'group']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('group', $this->factory->createView(
|
$this->assertSame(['group'], $this->factory->createView($list, null, null, null, 'property')->choices);
|
||||||
$list,
|
|
||||||
null, // preferred choices
|
|
||||||
null, // label
|
|
||||||
null, // index
|
|
||||||
'property'
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -385,16 +354,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, null, null, null, $this->isInstanceOf('\Closure'))
|
->with($list, null, null, null, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
|
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
|
||||||
return $groupBy((object) ['property' => 'group']);
|
return new ChoiceListView((array) $groupBy((object) ['property' => 'group']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('group', $this->factory->createView(
|
$this->assertSame(['group'], $this->factory->createView($list, null, null, null, new PropertyPath('property'))->choices);
|
||||||
$list,
|
|
||||||
null, // preferred choices
|
|
||||||
null, // label
|
|
||||||
null, // index
|
|
||||||
new PropertyPath('property')
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/symfony/symfony/issues/5494
|
// https://github.com/symfony/symfony/issues/5494
|
||||||
@ -406,16 +369,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, null, null, null, $this->isInstanceOf('\Closure'))
|
->with($list, null, null, null, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
|
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
|
||||||
return $groupBy((object) ['group' => null]);
|
return new ChoiceListView((array) $groupBy((object) ['group' => null]));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertNull($this->factory->createView(
|
$this->assertSame([], $this->factory->createView($list, null, null, null, 'group.name')->choices);
|
||||||
$list,
|
|
||||||
null, // preferred choices
|
|
||||||
null, // label
|
|
||||||
null, // index
|
|
||||||
'group.name'
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateViewAttrAsPropertyPath()
|
public function testCreateViewAttrAsPropertyPath()
|
||||||
@ -426,17 +383,10 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, null, null, null, null, $this->isInstanceOf('\Closure'))
|
->with($list, null, null, null, null, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) {
|
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) {
|
||||||
return $attr((object) ['property' => 'attr']);
|
return new ChoiceListView((array) $attr((object) ['property' => 'attr']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('attr', $this->factory->createView(
|
$this->assertSame(['attr'], $this->factory->createView($list, null, null, null, null, 'property')->choices);
|
||||||
$list,
|
|
||||||
null, // preferred choices
|
|
||||||
null, // label
|
|
||||||
null, // index
|
|
||||||
null, // groups
|
|
||||||
'property'
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -469,16 +419,9 @@ class PropertyAccessDecoratorTest extends TestCase
|
|||||||
->method('createView')
|
->method('createView')
|
||||||
->with($list, null, null, null, null, $this->isInstanceOf('\Closure'))
|
->with($list, null, null, null, null, $this->isInstanceOf('\Closure'))
|
||||||
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) {
|
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) {
|
||||||
return $attr((object) ['property' => 'attr']);
|
return new ChoiceListView((array) $attr((object) ['property' => 'attr']));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('attr', $this->factory->createView(
|
$this->assertSame(['attr'], $this->factory->createView($list, null, null, null, null, new PropertyPath('property'))->choices);
|
||||||
$list,
|
|
||||||
null, // preferred choices
|
|
||||||
null, // label
|
|
||||||
null, // index
|
|
||||||
null, // groups
|
|
||||||
new PropertyPath('property')
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,10 +56,10 @@ class LazyChoiceListTest extends TestCase
|
|||||||
// The same list is returned by the loader
|
// The same list is returned by the loader
|
||||||
$this->loadedList->expects($this->exactly(2))
|
$this->loadedList->expects($this->exactly(2))
|
||||||
->method('getChoices')
|
->method('getChoices')
|
||||||
->willReturn('RESULT');
|
->willReturn(['RESULT']);
|
||||||
|
|
||||||
$this->assertSame('RESULT', $this->list->getChoices());
|
$this->assertSame(['RESULT'], $this->list->getChoices());
|
||||||
$this->assertSame('RESULT', $this->list->getChoices());
|
$this->assertSame(['RESULT'], $this->list->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,10 +96,10 @@ class LazyChoiceListTest extends TestCase
|
|||||||
// The same list is returned by the loader
|
// The same list is returned by the loader
|
||||||
$this->loadedList->expects($this->exactly(2))
|
$this->loadedList->expects($this->exactly(2))
|
||||||
->method('getValues')
|
->method('getValues')
|
||||||
->willReturn('RESULT');
|
->willReturn(['RESULT']);
|
||||||
|
|
||||||
$this->assertSame('RESULT', $this->list->getValues());
|
$this->assertSame(['RESULT'], $this->list->getValues());
|
||||||
$this->assertSame('RESULT', $this->list->getValues());
|
$this->assertSame(['RESULT'], $this->list->getValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetStructuredValuesLoadsLoadedListOnFirstCall()
|
public function testGetStructuredValuesLoadsLoadedListOnFirstCall()
|
||||||
@ -112,10 +112,10 @@ class LazyChoiceListTest extends TestCase
|
|||||||
// The same list is returned by the loader
|
// The same list is returned by the loader
|
||||||
$this->loadedList->expects($this->exactly(2))
|
$this->loadedList->expects($this->exactly(2))
|
||||||
->method('getStructuredValues')
|
->method('getStructuredValues')
|
||||||
->willReturn('RESULT');
|
->willReturn(['RESULT']);
|
||||||
|
|
||||||
$this->assertSame('RESULT', $this->list->getStructuredValues());
|
$this->assertSame(['RESULT'], $this->list->getStructuredValues());
|
||||||
$this->assertSame('RESULT', $this->list->getStructuredValues());
|
$this->assertSame(['RESULT'], $this->list->getStructuredValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetOriginalKeysLoadsLoadedListOnFirstCall()
|
public function testGetOriginalKeysLoadsLoadedListOnFirstCall()
|
||||||
@ -128,10 +128,10 @@ class LazyChoiceListTest extends TestCase
|
|||||||
// The same list is returned by the loader
|
// The same list is returned by the loader
|
||||||
$this->loadedList->expects($this->exactly(2))
|
$this->loadedList->expects($this->exactly(2))
|
||||||
->method('getOriginalKeys')
|
->method('getOriginalKeys')
|
||||||
->willReturn('RESULT');
|
->willReturn(['RESULT']);
|
||||||
|
|
||||||
$this->assertSame('RESULT', $this->list->getOriginalKeys());
|
$this->assertSame(['RESULT'], $this->list->getOriginalKeys());
|
||||||
$this->assertSame('RESULT', $this->list->getOriginalKeys());
|
$this->assertSame(['RESULT'], $this->list->getOriginalKeys());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetChoicesForValuesForwardsCallIfListNotLoaded()
|
public function testGetChoicesForValuesForwardsCallIfListNotLoaded()
|
||||||
@ -139,10 +139,10 @@ class LazyChoiceListTest extends TestCase
|
|||||||
$this->loader->expects($this->exactly(2))
|
$this->loader->expects($this->exactly(2))
|
||||||
->method('loadChoicesForValues')
|
->method('loadChoicesForValues')
|
||||||
->with(['a', 'b'])
|
->with(['a', 'b'])
|
||||||
->willReturn('RESULT');
|
->willReturn(['RESULT']);
|
||||||
|
|
||||||
$this->assertSame('RESULT', $this->list->getChoicesForValues(['a', 'b']));
|
$this->assertSame(['RESULT'], $this->list->getChoicesForValues(['a', 'b']));
|
||||||
$this->assertSame('RESULT', $this->list->getChoicesForValues(['a', 'b']));
|
$this->assertSame(['RESULT'], $this->list->getChoicesForValues(['a', 'b']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetChoicesForValuesUsesLoadedList()
|
public function testGetChoicesForValuesUsesLoadedList()
|
||||||
@ -160,13 +160,13 @@ class LazyChoiceListTest extends TestCase
|
|||||||
$this->loadedList->expects($this->exactly(2))
|
$this->loadedList->expects($this->exactly(2))
|
||||||
->method('getChoicesForValues')
|
->method('getChoicesForValues')
|
||||||
->with(['a', 'b'])
|
->with(['a', 'b'])
|
||||||
->willReturn('RESULT');
|
->willReturn(['RESULT']);
|
||||||
|
|
||||||
// load choice list
|
// load choice list
|
||||||
$this->list->getChoices();
|
$this->list->getChoices();
|
||||||
|
|
||||||
$this->assertSame('RESULT', $this->list->getChoicesForValues(['a', 'b']));
|
$this->assertSame(['RESULT'], $this->list->getChoicesForValues(['a', 'b']));
|
||||||
$this->assertSame('RESULT', $this->list->getChoicesForValues(['a', 'b']));
|
$this->assertSame(['RESULT'], $this->list->getChoicesForValues(['a', 'b']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,12 +198,12 @@ class LazyChoiceListTest extends TestCase
|
|||||||
$this->loadedList->expects($this->exactly(2))
|
$this->loadedList->expects($this->exactly(2))
|
||||||
->method('getValuesForChoices')
|
->method('getValuesForChoices')
|
||||||
->with(['a', 'b'])
|
->with(['a', 'b'])
|
||||||
->willReturn('RESULT');
|
->willReturn(['RESULT']);
|
||||||
|
|
||||||
// load choice list
|
// load choice list
|
||||||
$this->list->getChoices();
|
$this->list->getChoices();
|
||||||
|
|
||||||
$this->assertSame('RESULT', $this->list->getValuesForChoices(['a', 'b']));
|
$this->assertSame(['RESULT'], $this->list->getValuesForChoices(['a', 'b']));
|
||||||
$this->assertSame('RESULT', $this->list->getValuesForChoices(['a', 'b']));
|
$this->assertSame(['RESULT'], $this->list->getValuesForChoices(['a', 'b']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
|||||||
$this->tokenManager->expects($this->once())
|
$this->tokenManager->expects($this->once())
|
||||||
->method('getToken')
|
->method('getToken')
|
||||||
->with('FORM_NAME')
|
->with('FORM_NAME')
|
||||||
->willReturn('token');
|
->willReturn(new CsrfToken('TOKEN_ID', 'token'));
|
||||||
|
|
||||||
$view = $this->factory
|
$view = $this->factory
|
||||||
->createNamed('FORM_NAME', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, [
|
->createNamed('FORM_NAME', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, [
|
||||||
@ -160,7 +160,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
|||||||
$this->tokenManager->expects($this->once())
|
$this->tokenManager->expects($this->once())
|
||||||
->method('getToken')
|
->method('getToken')
|
||||||
->with('Symfony\Component\Form\Extension\Core\Type\FormType')
|
->with('Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||||
->willReturn('token');
|
->willReturn(new CsrfToken('TOKEN_ID', 'token'));
|
||||||
|
|
||||||
$view = $this->factory
|
$view = $this->factory
|
||||||
->createNamed('', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, [
|
->createNamed('', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, [
|
||||||
|
@ -16,6 +16,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
use Symfony\Component\Form\CallbackTransformer;
|
use Symfony\Component\Form\CallbackTransformer;
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Extension\DataCollector\FormDataExtractor;
|
use Symfony\Component\Form\Extension\DataCollector\FormDataExtractor;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||||
use Symfony\Component\Form\FormBuilder;
|
use Symfony\Component\Form\FormBuilder;
|
||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
@ -57,7 +58,7 @@ class FormDataExtractorTest extends TestCase
|
|||||||
$type = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeInterface')->getMock();
|
$type = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeInterface')->getMock();
|
||||||
$type->expects($this->any())
|
$type->expects($this->any())
|
||||||
->method('getInnerType')
|
->method('getInnerType')
|
||||||
->willReturn(new \stdClass());
|
->willReturn(new HiddenType());
|
||||||
|
|
||||||
$form = $this->createBuilder('name')
|
$form = $this->createBuilder('name')
|
||||||
->setType($type)
|
->setType($type)
|
||||||
@ -66,7 +67,7 @@ class FormDataExtractorTest extends TestCase
|
|||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
'id' => 'name',
|
'id' => 'name',
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
'type_class' => 'stdClass',
|
'type_class' => HiddenType::class,
|
||||||
'synchronized' => true,
|
'synchronized' => true,
|
||||||
'passed_options' => [],
|
'passed_options' => [],
|
||||||
'resolved_options' => [],
|
'resolved_options' => [],
|
||||||
@ -78,7 +79,7 @@ class FormDataExtractorTest extends TestCase
|
|||||||
$type = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeInterface')->getMock();
|
$type = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeInterface')->getMock();
|
||||||
$type->expects($this->any())
|
$type->expects($this->any())
|
||||||
->method('getInnerType')
|
->method('getInnerType')
|
||||||
->willReturn(new \stdClass());
|
->willReturn(new HiddenType());
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'b' => 'foo',
|
'b' => 'foo',
|
||||||
@ -96,7 +97,7 @@ class FormDataExtractorTest extends TestCase
|
|||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
'id' => 'name',
|
'id' => 'name',
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
'type_class' => 'stdClass',
|
'type_class' => HiddenType::class,
|
||||||
'synchronized' => true,
|
'synchronized' => true,
|
||||||
'passed_options' => [
|
'passed_options' => [
|
||||||
'a' => 'bar',
|
'a' => 'bar',
|
||||||
@ -112,7 +113,7 @@ class FormDataExtractorTest extends TestCase
|
|||||||
$type = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeInterface')->getMock();
|
$type = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeInterface')->getMock();
|
||||||
$type->expects($this->any())
|
$type->expects($this->any())
|
||||||
->method('getInnerType')
|
->method('getInnerType')
|
||||||
->willReturn(new \stdClass());
|
->willReturn(new HiddenType());
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'b' => 'foo',
|
'b' => 'foo',
|
||||||
@ -127,7 +128,7 @@ class FormDataExtractorTest extends TestCase
|
|||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
'id' => 'name',
|
'id' => 'name',
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
'type_class' => 'stdClass',
|
'type_class' => HiddenType::class,
|
||||||
'synchronized' => true,
|
'synchronized' => true,
|
||||||
'passed_options' => [],
|
'passed_options' => [],
|
||||||
'resolved_options' => [
|
'resolved_options' => [
|
||||||
@ -143,7 +144,7 @@ class FormDataExtractorTest extends TestCase
|
|||||||
$type = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeInterface')->getMock();
|
$type = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeInterface')->getMock();
|
||||||
$type->expects($this->any())
|
$type->expects($this->any())
|
||||||
->method('getInnerType')
|
->method('getInnerType')
|
||||||
->willReturn(new \stdClass());
|
->willReturn(new HiddenType());
|
||||||
|
|
||||||
$grandParent = $this->createBuilder('grandParent')
|
$grandParent = $this->createBuilder('grandParent')
|
||||||
->setCompound(true)
|
->setCompound(true)
|
||||||
@ -163,7 +164,7 @@ class FormDataExtractorTest extends TestCase
|
|||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
'id' => 'grandParent_parent_name',
|
'id' => 'grandParent_parent_name',
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
'type_class' => 'stdClass',
|
'type_class' => HiddenType::class,
|
||||||
'synchronized' => true,
|
'synchronized' => true,
|
||||||
'passed_options' => [],
|
'passed_options' => [],
|
||||||
'resolved_options' => [],
|
'resolved_options' => [],
|
||||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Tests;
|
|||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\Form\FormFactory;
|
use Symfony\Component\Form\FormFactory;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\Form\FormTypeGuesserChain;
|
use Symfony\Component\Form\FormTypeGuesserChain;
|
||||||
use Symfony\Component\Form\Guess\Guess;
|
use Symfony\Component\Form\Guess\Guess;
|
||||||
use Symfony\Component\Form\Guess\TypeGuess;
|
use Symfony\Component\Form\Guess\TypeGuess;
|
||||||
@ -193,11 +194,13 @@ class FormFactoryTest extends TestCase
|
|||||||
->method('buildForm')
|
->method('buildForm')
|
||||||
->with($this->builder, $resolvedOptions);
|
->with($this->builder, $resolvedOptions);
|
||||||
|
|
||||||
|
$form = $this->createMock(FormInterface::class);
|
||||||
|
|
||||||
$this->builder->expects($this->once())
|
$this->builder->expects($this->once())
|
||||||
->method('getForm')
|
->method('getForm')
|
||||||
->willReturn('FORM');
|
->willReturn($form);
|
||||||
|
|
||||||
$this->assertSame('FORM', $this->factory->create('TYPE', null, $options));
|
$this->assertSame($form, $this->factory->create('TYPE', null, $options));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateNamed()
|
public function testCreateNamed()
|
||||||
@ -224,11 +227,13 @@ class FormFactoryTest extends TestCase
|
|||||||
->method('buildForm')
|
->method('buildForm')
|
||||||
->with($this->builder, $resolvedOptions);
|
->with($this->builder, $resolvedOptions);
|
||||||
|
|
||||||
|
$form = $this->createMock(FormInterface::class);
|
||||||
|
|
||||||
$this->builder->expects($this->once())
|
$this->builder->expects($this->once())
|
||||||
->method('getForm')
|
->method('getForm')
|
||||||
->willReturn('FORM');
|
->willReturn($form);
|
||||||
|
|
||||||
$this->assertSame('FORM', $this->factory->createNamed('name', 'type', null, $options));
|
$this->assertSame($form, $this->factory->createNamed('name', 'type', null, $options));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateBuilderForPropertyWithoutTypeGuesser()
|
public function testCreateBuilderForPropertyWithoutTypeGuesser()
|
||||||
@ -242,11 +247,11 @@ class FormFactoryTest extends TestCase
|
|||||||
$factory->expects($this->once())
|
$factory->expects($this->once())
|
||||||
->method('createNamedBuilder')
|
->method('createNamedBuilder')
|
||||||
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [])
|
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [])
|
||||||
->willReturn('builderInstance');
|
->willReturn($this->builder);
|
||||||
|
|
||||||
$this->builder = $factory->createBuilderForProperty('Application\Author', 'firstName');
|
$this->builder = $factory->createBuilderForProperty('Application\Author', 'firstName');
|
||||||
|
|
||||||
$this->assertEquals('builderInstance', $this->builder);
|
$this->assertSame($this->builder, $this->builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateBuilderForPropertyCreatesFormWithHighestConfidence()
|
public function testCreateBuilderForPropertyCreatesFormWithHighestConfidence()
|
||||||
@ -274,11 +279,11 @@ class FormFactoryTest extends TestCase
|
|||||||
$factory->expects($this->once())
|
$factory->expects($this->once())
|
||||||
->method('createNamedBuilder')
|
->method('createNamedBuilder')
|
||||||
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\PasswordType', null, ['attr' => ['maxlength' => 7]])
|
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\PasswordType', null, ['attr' => ['maxlength' => 7]])
|
||||||
->willReturn('builderInstance');
|
->willReturn($this->builder);
|
||||||
|
|
||||||
$this->builder = $factory->createBuilderForProperty('Application\Author', 'firstName');
|
$this->builder = $factory->createBuilderForProperty('Application\Author', 'firstName');
|
||||||
|
|
||||||
$this->assertEquals('builderInstance', $this->builder);
|
$this->assertSame($this->builder, $this->builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateBuilderCreatesTextFormIfNoGuess()
|
public function testCreateBuilderCreatesTextFormIfNoGuess()
|
||||||
@ -293,11 +298,11 @@ class FormFactoryTest extends TestCase
|
|||||||
$factory->expects($this->once())
|
$factory->expects($this->once())
|
||||||
->method('createNamedBuilder')
|
->method('createNamedBuilder')
|
||||||
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
||||||
->willReturn('builderInstance');
|
->willReturn($this->builder);
|
||||||
|
|
||||||
$this->builder = $factory->createBuilderForProperty('Application\Author', 'firstName');
|
$this->builder = $factory->createBuilderForProperty('Application\Author', 'firstName');
|
||||||
|
|
||||||
$this->assertEquals('builderInstance', $this->builder);
|
$this->assertSame($this->builder, $this->builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOptionsCanBeOverridden()
|
public function testOptionsCanBeOverridden()
|
||||||
@ -316,7 +321,7 @@ class FormFactoryTest extends TestCase
|
|||||||
$factory->expects($this->once())
|
$factory->expects($this->once())
|
||||||
->method('createNamedBuilder')
|
->method('createNamedBuilder')
|
||||||
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['attr' => ['class' => 'foo', 'maxlength' => 11]])
|
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['attr' => ['class' => 'foo', 'maxlength' => 11]])
|
||||||
->willReturn('builderInstance');
|
->willReturn($this->builder);
|
||||||
|
|
||||||
$this->builder = $factory->createBuilderForProperty(
|
$this->builder = $factory->createBuilderForProperty(
|
||||||
'Application\Author',
|
'Application\Author',
|
||||||
@ -325,7 +330,7 @@ class FormFactoryTest extends TestCase
|
|||||||
['attr' => ['maxlength' => 11]]
|
['attr' => ['maxlength' => 11]]
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals('builderInstance', $this->builder);
|
$this->assertSame($this->builder, $this->builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateBuilderUsesMaxLengthIfFound()
|
public function testCreateBuilderUsesMaxLengthIfFound()
|
||||||
@ -351,14 +356,14 @@ class FormFactoryTest extends TestCase
|
|||||||
$factory->expects($this->once())
|
$factory->expects($this->once())
|
||||||
->method('createNamedBuilder')
|
->method('createNamedBuilder')
|
||||||
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['attr' => ['maxlength' => 20]])
|
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['attr' => ['maxlength' => 20]])
|
||||||
->willReturn('builderInstance');
|
->willReturn($this->builder);
|
||||||
|
|
||||||
$this->builder = $factory->createBuilderForProperty(
|
$this->builder = $factory->createBuilderForProperty(
|
||||||
'Application\Author',
|
'Application\Author',
|
||||||
'firstName'
|
'firstName'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals('builderInstance', $this->builder);
|
$this->assertSame($this->builder, $this->builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateBuilderUsesMaxLengthAndPattern()
|
public function testCreateBuilderUsesMaxLengthAndPattern()
|
||||||
@ -384,7 +389,7 @@ class FormFactoryTest extends TestCase
|
|||||||
$factory->expects($this->once())
|
$factory->expects($this->once())
|
||||||
->method('createNamedBuilder')
|
->method('createNamedBuilder')
|
||||||
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['attr' => ['maxlength' => 20, 'pattern' => '.{5,}', 'class' => 'tinymce']])
|
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['attr' => ['maxlength' => 20, 'pattern' => '.{5,}', 'class' => 'tinymce']])
|
||||||
->willReturn('builderInstance');
|
->willReturn($this->builder);
|
||||||
|
|
||||||
$this->builder = $factory->createBuilderForProperty(
|
$this->builder = $factory->createBuilderForProperty(
|
||||||
'Application\Author',
|
'Application\Author',
|
||||||
@ -393,7 +398,7 @@ class FormFactoryTest extends TestCase
|
|||||||
['attr' => ['class' => 'tinymce']]
|
['attr' => ['class' => 'tinymce']]
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals('builderInstance', $this->builder);
|
$this->assertSame($this->builder, $this->builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateBuilderUsesRequiredSettingWithHighestConfidence()
|
public function testCreateBuilderUsesRequiredSettingWithHighestConfidence()
|
||||||
@ -419,14 +424,14 @@ class FormFactoryTest extends TestCase
|
|||||||
$factory->expects($this->once())
|
$factory->expects($this->once())
|
||||||
->method('createNamedBuilder')
|
->method('createNamedBuilder')
|
||||||
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['required' => false])
|
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['required' => false])
|
||||||
->willReturn('builderInstance');
|
->willReturn($this->builder);
|
||||||
|
|
||||||
$this->builder = $factory->createBuilderForProperty(
|
$this->builder = $factory->createBuilderForProperty(
|
||||||
'Application\Author',
|
'Application\Author',
|
||||||
'firstName'
|
'firstName'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals('builderInstance', $this->builder);
|
$this->assertSame($this->builder, $this->builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateBuilderUsesPatternIfFound()
|
public function testCreateBuilderUsesPatternIfFound()
|
||||||
@ -452,14 +457,14 @@ class FormFactoryTest extends TestCase
|
|||||||
$factory->expects($this->once())
|
$factory->expects($this->once())
|
||||||
->method('createNamedBuilder')
|
->method('createNamedBuilder')
|
||||||
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['attr' => ['pattern' => '[a-zA-Z]']])
|
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, ['attr' => ['pattern' => '[a-zA-Z]']])
|
||||||
->willReturn('builderInstance');
|
->willReturn($this->builder);
|
||||||
|
|
||||||
$this->builder = $factory->createBuilderForProperty(
|
$this->builder = $factory->createBuilderForProperty(
|
||||||
'Application\Author',
|
'Application\Author',
|
||||||
'firstName'
|
'firstName'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals('builderInstance', $this->builder);
|
$this->assertSame($this->builder, $this->builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getMockFactory(array $methods = [])
|
private function getMockFactory(array $methods = [])
|
||||||
|
@ -193,7 +193,7 @@ class PropertyPathBuilder
|
|||||||
/**
|
/**
|
||||||
* Returns the current property path.
|
* Returns the current property path.
|
||||||
*
|
*
|
||||||
* @return PropertyPathInterface The constructed property path
|
* @return PropertyPathInterface|null The constructed property path
|
||||||
*/
|
*/
|
||||||
public function getPropertyPath()
|
public function getPropertyPath()
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,7 @@ interface PropertyPathInterface extends \Traversable
|
|||||||
*
|
*
|
||||||
* If this property path only contains one item, null is returned.
|
* If this property path only contains one item, null is returned.
|
||||||
*
|
*
|
||||||
* @return PropertyPath|null The parent path or null
|
* @return self|null The parent path or null
|
||||||
*/
|
*/
|
||||||
public function getParent();
|
public function getParent();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user