diff --git a/src/Formatter.php b/src/Formatter.php index 8dfb231..174070a 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -106,11 +106,11 @@ private function predicateToArray(Predicate $predicate, bool $withAdditionalFiel case Predicate::OPERATOR_OR: case Predicate::OPERATOR_NOT: $value = []; - foreach ($predicate->getConfig() as $predicateOperator => $predicateConfig) { + foreach ($predicate->getConfig() as $predicateConfig) { if ($predicateConfig instanceof Predicate) { - $value = array_merge($value, $this->predicateToArray($predicateConfig, false)); + $value[] = $this->predicateToArray($predicateConfig, false); } else { - $value[$predicateOperator] = $predicateConfig; + $value[] = $predicateConfig; } } break; diff --git a/src/Predicate.php b/src/Predicate.php index e9e497b..3e3030a 100644 --- a/src/Predicate.php +++ b/src/Predicate.php @@ -30,7 +30,7 @@ class Predicate private string $operator; /** - * @var array + * @var array */ private array $config = []; @@ -102,7 +102,7 @@ public function setOperator(string $operator): self } /** - * @return array + * @return array */ public function getConfig(): array { @@ -110,7 +110,7 @@ public function getConfig(): array } /** - * @param array $config + * @param array $config */ public function setConfig(array $config): self { diff --git a/tests/Unit/FormatterTest.php b/tests/Unit/FormatterTest.php index 5d1535d..53e41ba 100644 --- a/tests/Unit/FormatterTest.php +++ b/tests/Unit/FormatterTest.php @@ -157,10 +157,14 @@ public function testPredicateWithPredicates(): void $predicate2 = new Predicate(Predicate::OPERATOR_START_WITH); $predicate2->setConfig(['path' => '/test2']); + $predicate3 = new Predicate(Predicate::OPERATOR_START_WITH); + $predicate3->setConfig(['path' => '/test3']); + $predicate = new Predicate(Predicate::OPERATOR_AND); $predicate->setConfig([ - $predicate1->getOperator() => $predicate1, - $predicate2->getOperator() => $predicate2, + $predicate1, + $predicate2, + $predicate3, ]); $stub = new Stub(); @@ -177,11 +181,20 @@ public function testPredicateWithPredicates(): void $this->assertSame([ [ 'and' => [ - 'equals' => [ - 'path' => '/test1', + [ + 'equals' => [ + 'path' => '/test1', + ], + ], + [ + 'startsWith' => [ + 'path' => '/test2', + ], ], - 'startsWith' => [ - 'path' => '/test2', + [ + 'startsWith' => [ + 'path' => '/test3', + ], ], ], 'caseSensitive' => false, @@ -194,8 +207,9 @@ public function testPredicateWithPredicatesAsArray(): void { $predicate = new Predicate(Predicate::OPERATOR_AND); $predicate->setConfig([ - Predicate::OPERATOR_EQUALS => ['path' => '/test1'], - Predicate::OPERATOR_START_WITH => ['path' => '/test2'], + [Predicate::OPERATOR_EQUALS => ['path' => '/test1']], + [Predicate::OPERATOR_START_WITH => ['path' => '/test2']], + [Predicate::OPERATOR_START_WITH => ['path' => '/test3']], ]); $stub = new Stub(); @@ -212,11 +226,20 @@ public function testPredicateWithPredicatesAsArray(): void $this->assertSame([ [ 'and' => [ - 'equals' => [ - 'path' => '/test1', + [ + 'equals' => [ + 'path' => '/test1', + ], + ], + [ + 'startsWith' => [ + 'path' => '/test2', + ], ], - 'startsWith' => [ - 'path' => '/test2', + [ + 'startsWith' => [ + 'path' => '/test3', + ], ], ], 'caseSensitive' => false,