-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from riul88/hotfix/33
Fixes #33 Collection has empty bonded nested objects
- Loading branch information
Showing
6 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,14 @@ | |
use LaminasTest\Form\ErrorHandler; | ||
use LaminasTest\Form\TestAsset; | ||
use LaminasTest\Form\TestAsset\Annotation\Entity; | ||
use LaminasTest\Form\TestAsset\Annotation\EntityObjectPropertyHydrator; | ||
use LaminasTest\Form\TestAsset\Annotation\Form; | ||
use LaminasTest\Form\TestAsset\Annotation\InputFilter; | ||
use LaminasTest\Form\TestAsset\Annotation\InputFilterInput; | ||
use PHPUnit\Framework\TestCase; | ||
use Throwable; | ||
|
||
use function count; | ||
use function getenv; | ||
|
||
abstract class AbstractBuilderTestCase extends TestCase | ||
|
@@ -261,7 +263,44 @@ public function testAllowsComposingMultipleChildEntities(): void | |
self::assertTrue($target->has('username')); | ||
self::assertTrue($target->has('password')); | ||
self::assertInstanceOf(InputFilterProviderFieldset::class, $target); | ||
$filterSpec = $target->getInputFilterSpecification(); | ||
$this->validateEntityFilterSpec($target->getInputFilterSpecification()); | ||
} | ||
|
||
public function testAllowsComposingMultipleChildEntitiesWithEntityBind(): void | ||
{ | ||
$entity = new TestAsset\Annotation\EntityComposingMultipleEntitiesObjectPropertyHydrator(); | ||
$builder = $this->createBuilder(); | ||
$form = $builder->createForm($entity); | ||
|
||
self::assertTrue($form->has('child')); | ||
$child = $form->get('child'); | ||
self::assertInstanceOf(Collection::class, $child); | ||
$target = $child->getTargetElement(); | ||
self::assertInstanceOf(FieldsetInterface::class, $target); | ||
self::assertTrue($target->has('username')); | ||
self::assertTrue($target->has('password')); | ||
self::assertInstanceOf(InputFilterProviderFieldset::class, $target); | ||
$this->validateEntityFilterSpec($target->getInputFilterSpecification()); | ||
|
||
self::assertNull($entity->child); | ||
$form->bind($entity); | ||
$form->setData([ | ||
'child' => [ | ||
'0' => ['password' => '[email protected]', 'username' => 'user'], | ||
'1' => ['password' => '[email protected]', 'username' => 'user2'], | ||
], | ||
]); | ||
self::assertTrue($form->isValid()); | ||
self::assertNotNull($entity->child); | ||
self::assertEquals(2, count($entity->child)); | ||
self::assertInstanceOf(EntityObjectPropertyHydrator::class, $entity->child[0]); | ||
self::assertEquals('[email protected]', $entity->child[0]->password); | ||
self::assertEquals('user', $entity->child[0]->username); | ||
self::assertInstanceOf(EntityObjectPropertyHydrator::class, $entity->child[1]); | ||
} | ||
|
||
protected function validateEntityFilterSpec(array $filterSpec): void | ||
{ | ||
self::assertArrayHasKey('username', $filterSpec); | ||
self::assertArrayHasKey('password', $filterSpec); | ||
$usernameFilterSpec = $filterSpec['username']; | ||
|
28 changes: 28 additions & 0 deletions
28
test/TestAsset/Annotation/EntityComposingMultipleEntitiesObjectPropertyHydrator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\Form\TestAsset\Annotation; | ||
|
||
use Laminas\Form\Annotation; | ||
use Laminas\Hydrator\ObjectPropertyHydrator; | ||
|
||
/** | ||
* @Annotation\Name("hierarchical") | ||
* @Annotation\Hydrator("Laminas\Hydrator\ObjectPropertyHydrator") | ||
*/ | ||
#[Annotation\Name("hierarchical")] | ||
#[Annotation\Hydrator(ObjectPropertyHydrator::class)] | ||
class EntityComposingMultipleEntitiesObjectPropertyHydrator | ||
{ | ||
/** | ||
* @var null|list<EntityObjectPropertyHydrator> | ||
* @Annotation\ComposedObject("LaminasTest\Form\TestAsset\Annotation\EntityObjectPropertyHydrator", isCollection=true) | ||
*/ | ||
#[Annotation\ComposedObject( | ||
EntityObjectPropertyHydrator::class, | ||
isCollection: true, | ||
options: ['create_new_objects' => true] | ||
)] | ||
public ?array $child = null; | ||
} |
16 changes: 16 additions & 0 deletions
16
test/TestAsset/Annotation/EntityObjectPropertyHydrator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\Form\TestAsset\Annotation; | ||
|
||
use Laminas\Form\Annotation; | ||
use Laminas\Hydrator\ObjectPropertyHydrator; | ||
|
||
/** | ||
* @Annotation\Hydrator("Laminas\Hydrator\ObjectPropertyHydrator") | ||
*/ | ||
#[Annotation\Hydrator(ObjectPropertyHydrator::class)] | ||
class EntityObjectPropertyHydrator extends Entity | ||
{ | ||
} |