From 63a5d7f4c8f458626c9cf9166dcd32297f3b5a96 Mon Sep 17 00:00:00 2001 From: ropczan Date: Wed, 5 Jan 2022 11:59:12 +0100 Subject: [PATCH] ANS-9289 added param to SearchByFeatureRequest - max number of return products --- .github/workflows/phpunit.yml | 2 +- README.md | 3 ++- src/Request/SearchByFeatureRequest.php | 5 ++++- tests/Unit/Request/SearchByFeatureRequestTest.php | 13 +++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index f7b899f..d264168 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -45,4 +45,4 @@ jobs: if: "${{ matrix.deps == 'low' }}" - name: "Run PHPUnit" - run: "vendor/bin/phpunit" + run: "SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/phpunit" diff --git a/README.md b/README.md index f988739..37cb13d 100755 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ To search products with previously found feature use `searchByFeature` ```php use Answear\WideEyesBundle\Service\SearchByImageClient; -$detectAndFeturesResponse = $searchByImageClient->searchByFeature('featureId', 'label', 'gender', 'filters'); +$detectAndFeturesResponse = $searchByImageClient->searchByFeature('featureId', 'label', 'gender', 'filters', 'maxNumResults'); ``` Your agruments are: @@ -71,6 +71,7 @@ Your agruments are: * `label` - label you got form DetectAndFeatures * `gender` - gender you got from DetectAndFeatures (optional) * `filters` - result filters (optional) + * `maxNumResults` - maximal number of return products (optional) In result you're getting `SearchByFeatureResponse` that contains all found products uids meeting your criteria. diff --git a/src/Request/SearchByFeatureRequest.php b/src/Request/SearchByFeatureRequest.php index 912d0a7..c636353 100644 --- a/src/Request/SearchByFeatureRequest.php +++ b/src/Request/SearchByFeatureRequest.php @@ -10,13 +10,15 @@ class SearchByFeatureRequest implements Request private string $label; private ?string $gender; private ?string $filters; + private ?int $maxNumResults; - public function __construct(string $featureId, string $label, ?string $gender = null, ?string $filters = null) + public function __construct(string $featureId, string $label, ?string $gender = null, ?string $filters = null, ?int $maxNumResults = null) { $this->featureId = $featureId; $this->label = $label; $this->gender = $gender; $this->filters = $filters; + $this->maxNumResults = $maxNumResults; } public function toJson(): string @@ -28,6 +30,7 @@ public function toJson(): string 'label' => $this->label, 'gender' => $this->gender, 'filters' => $this->filters, + 'maxNumResults' => $this->maxNumResults, ] ) ); diff --git a/tests/Unit/Request/SearchByFeatureRequestTest.php b/tests/Unit/Request/SearchByFeatureRequestTest.php index 3b9ead3..f3a17a9 100644 --- a/tests/Unit/Request/SearchByFeatureRequestTest.php +++ b/tests/Unit/Request/SearchByFeatureRequestTest.php @@ -34,4 +34,17 @@ public function requestWithGenderAndCountryIsCorrect(): void $request->toJson() ); } + + /** + * @test + */ + public function requestWithMaxNumResultsIsCorrect(): void + { + $request = new SearchByFeatureRequest('featureId', 'label', null, null, 30); + + self::assertSame( + '{"featureId":"featureId","label":"label","maxNumResults":30}', + $request->toJson() + ); + } }