diff --git a/src/ArrayCriteriaVisitor.php b/src/ArrayCriteriaVisitor.php index 95460a1..8fd9ff1 100644 --- a/src/ArrayCriteriaVisitor.php +++ b/src/ArrayCriteriaVisitor.php @@ -72,11 +72,11 @@ static function ($item) use ($filter) { } if (FilterOperator::IN === $filter->operator()->value()) { - return false !== in_array($filter->value()->value(), $itemValue); + return false !== in_array($itemValue, $filter->value()->value()); } if (FilterOperator::NOT_IN === $filter->operator()->value()) { - return true !== in_array($filter->value()->value(), $itemValue); + return true !== in_array($itemValue, $filter->value()->value()); } } diff --git a/tests/ArrayBuilderCriteriaVisitorTest.php b/tests/ArrayBuilderCriteriaVisitorTest.php index a83a7f8..e083ba1 100644 --- a/tests/ArrayBuilderCriteriaVisitorTest.php +++ b/tests/ArrayBuilderCriteriaVisitorTest.php @@ -3,6 +3,7 @@ namespace PcComponentes\CriteriaArrayAdapter\Tests; +use Pccomponentes\Criteria\Domain\Criteria\FilterArrayValue; use PcComponentes\CriteriaArrayAdapter\Tests\Mocks\MemoryArticleRepository; use PcComponentes\CriteriaArrayAdapter\Tests\Mocks\ArticleObjectMother; use Pccomponentes\Criteria\Domain\Criteria\AndFilter; @@ -314,14 +315,16 @@ public function test_not_equal_operator() public function test_in_operator() { $article = ArticleObjectMother::random(); + $withNamePhone = ArticleObjectMother::withNamePhone(); $this->repository->save($article); + $this->repository->save($withNamePhone); $criteria = new Criteria( new Filters( new Filter( - FilterField::from('tags'), + FilterField::from('name'), FilterOperator::from(FilterOperator::IN), - FilterValue::from(ArticleObjectMother::TAG_INCLUDED), + FilterArrayValue::from(['benito', 'Phone']), ), ), null, @@ -330,21 +333,23 @@ public function test_in_operator() ); $result = $this->repository->filter($criteria); - $this->assertEquals($article, $result[0]); + $this->assertEquals($withNamePhone, $result[1]); } public function test_not_in_operator() { $article = ArticleObjectMother::random(); + $withNamePhone = ArticleObjectMother::withNamePhone(); $this->repository->save($article); + $this->repository->save($withNamePhone); $criteria = new Criteria( new Filters( new Filter( - FilterField::from('tags'), + FilterField::from('name'), FilterOperator::from(FilterOperator::NOT_IN), - FilterValue::from(ArticleObjectMother::TAG_NOT_INCLUDED), + FilterArrayValue::from(['Phone']), ), ), null, diff --git a/tests/Mocks/Article.php b/tests/Mocks/Article.php index ce864aa..138848a 100644 --- a/tests/Mocks/Article.php +++ b/tests/Mocks/Article.php @@ -8,7 +8,7 @@ class Article { private Uuid $id; - private string $name; + protected string $name; private float $stock; private \DateTimeInterface $date; private array $tags; diff --git a/tests/Mocks/ArticleObjectMother.php b/tests/Mocks/ArticleObjectMother.php index 6250892..d52f656 100644 --- a/tests/Mocks/ArticleObjectMother.php +++ b/tests/Mocks/ArticleObjectMother.php @@ -1,16 +1,25 @@ name = 'Phone'; + return $withNamePhone; + } + public static function random(): Article { $faker = Factory::create(); @@ -19,7 +28,7 @@ public static function random(): Article Uuid::v4(), $faker->text(100), $faker->numberBetween(0, 1000), - \DateTimeImmutable::createFromMutable($faker->dateTimeBetween('-10 year', 'now')), + DateTimeImmutable::createFromMutable($faker->dateTimeBetween('-10 year', 'now')), [self::TAG_INCLUDED] ); }