Skip to content

Commit

Permalink
fix problem with in and not in filters
Browse files Browse the repository at this point in the history
  • Loading branch information
otis22 committed Jun 30, 2021
1 parent 766db92 commit 45eeaa8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/Query/Filter/InArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public function __construct(Property $property, ArrayValue $value)
public function asKeyValue(): array
{
$filterSettings['property'] = $this->property->asString();
$filterSettings['value'] = $this->value->asString();
$filterSettings['value'] = json_decode(
$this->value->asString(),
true
);
$filterSettings['operator'] = $this->operator;
return $filterSettings;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Query/Filter/NotInArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public function __construct(Property $property, ArrayValue $value)
public function asKeyValue(): array
{
$filterSettings['property'] = $this->property->asString();
$filterSettings['value'] = $this->value->asString();
$filterSettings['value'] = json_decode(
$this->value->asString(),
true
);
$filterSettings['operator'] = $this->operator;
return $filterSettings;
}
Expand Down
59 changes: 56 additions & 3 deletions tests/integration/QueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
use Otis22\VetmanagerRestApi\Model\Property;
use Otis22\VetmanagerRestApi\Query\Filter\Value\ArrayValue;
use Otis22\VetmanagerRestApi\Query\Sorts;
use Otis22\VetmanagerRestApi\Query\Sort\AscBy;
use Otis22\VetmanagerRestApi\Query\PagedQuery;
use Otis22\VetmanagerRestApi\Query\Sort\DescBy;
use Otis22\VetmanagerRestApi\Query\Sort\AscBy;
use Otis22\VetmanagerRestApi\Query\Filter\InArray;

use function Otis22\VetmanagerUrl\url;
use function Otis22\VetmanagerRestApi\uri;
Expand All @@ -20,7 +22,7 @@

class QueriesTest extends TestCase
{
public function testInvoiceWithFewFilters(): void
public function testInvoiceWithNotInArrayFilter(): void
{
$client = new Client(
[
Expand Down Expand Up @@ -49,7 +51,7 @@ public function testInvoiceWithFewFilters(): void
)
),
new Sorts(
new AscBy(
new DescBy(
new Property('id')
)
)
Expand All @@ -65,4 +67,55 @@ public function testInvoiceWithFewFilters(): void
);
$this->assertEquals($json->data->invoice[0]->status, 'deleted');
}

public function testInvoiceWithInArrayFilter(): void
{
$client = new Client(
[
'base_uri' => url(
strval(
getenv('TEST_DOMAIN_NAME')
)
)->asString()
]
);
$request = $client->request(
'GET',
uri('invoice')->asString(),
[
'headers' => byApiKey(
strval(
getenv("TEST_API_KEY")
)
)->asKeyValue(),
'query' => PagedQuery::forGettingTop(
new Query(
new Filters(
new InArray(
new Property('status'),
new ArrayValue(['exec','save'])
)
),
new Sorts(
new AscBy(
new Property('id')
)
)
),
1
)->asKeyValue()
]
);
$json = json_decode(
strval(
$request->getBody()
)
);
$this->assertTrue(
in_array(
$json->data->invoice[0]->status,
['exec', 'save']
)
);
}
}
2 changes: 1 addition & 1 deletion tests/unit/Query/Filter/InArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testAsKeyValue(): void
[
'operator' => 'in',
'property' => 'test',
'value' => '[1,2,3]'
'value' => [1,2,3]
],
(
new InArray(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Query/Filter/NotInArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testAsKeyValue(): void
[
'operator' => 'not in',
'property' => 'test',
'value' => '[1,2,3]'
'value' => [1,2,3]
],
(
new NotInArray(
Expand Down

0 comments on commit 45eeaa8

Please sign in to comment.