Skip to content

Commit

Permalink
embeddables: implement ArrayCollection filtering support
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Dec 30, 2019
1 parent acb4794 commit bc362fd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Collection/Helpers/ArrayCollectionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use DateTimeInterface;
use Nette\Utils\Arrays;
use Nextras\Orm\Collection\ICollection;
use Nextras\Orm\Entity\Embeddable\EmbeddableContainer;
use Nextras\Orm\Entity\IEntity;
use Nextras\Orm\Entity\Reflection\EntityMetadata;
use Nextras\Orm\Entity\Reflection\PropertyMetadata;
Expand Down Expand Up @@ -212,6 +213,9 @@ private function getValueByTokens(IEntity $entity, array $tokens, EntityMetadata
}
continue 2;
}
} elseif ($propertyMeta->wrapper === EmbeddableContainer::class) {
\assert($propertyMeta->args !== null);
$entityMeta = $propertyMeta->args[EmbeddableContainer::class]['metadata'];
}
} while (count($tokens) > 0 && $value !== null);

Expand Down
3 changes: 1 addition & 2 deletions src/Entity/Embeddable/EmbeddableContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public function setPropertyEntity(IEntity $entity)

public function convertToRawValue($value)
{
// this flow path should not happened
throw new InvalidStateException();
return $value;
}


Expand Down
39 changes: 39 additions & 0 deletions tests/cases/integration/Collection/collection.embeddables.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types = 1);

/**
* @testCase
* @dataProvider ../../../sections.ini
*/

namespace NextrasTests\Orm\Integration\Collection;

use NextrasTests\Orm\Currency;
use NextrasTests\Orm\DataTestCase;
use NextrasTests\Orm\Money;
use Tester\Assert;


$dic = require_once __DIR__ . '/../../../bootstrap.php';


class CollectionEmbeddablesTest extends DataTestCase
{
public function testBasics()
{
$books1 = $this->orm->books->findBy(['this->price->cents>=' => 100]);
Assert::same(0, $books1->count());
Assert::same(0, $books1->countStored());

$book = $this->orm->books->getById(1);
$book->price = new Money(100, Currency::CZK());
$this->orm->persistAndFlush($book);

$books2 = $this->orm->books->findBy(['this->price->cents>=' => 100]);
Assert::same(1, $books2->count());
Assert::same(1, $books2->countStored());
}
}


$test = new CollectionEmbeddablesTest($dic);
$test->run();

0 comments on commit bc362fd

Please sign in to comment.