Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slug to product-search results #20

Merged
merged 1 commit into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"phpstan/phpstan-guzzle": "^0.7.0",
"fr3d/swagger-assertions": "^0.8.1",
"php-vcr/php-vcr": "^1.3",
"symfony/yaml": "^3.2"
"symfony/yaml": "^3.2",
"justinrainbow/json-schema": "^5.2.1"
},
"autoload-dev": {
"psr-4": { "Wizaplace\\Tests\\": "tests/" }
Expand Down
2 changes: 1 addition & 1 deletion src/Catalog/CatalogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getCategory(int $id): CatalogCategory
return new CatalogCategory($category);
}

public function search($query = '', $filters = [], $sorting = [], $resultsPerPage = 12, $page = 1): SearchResult
public function search(string $query = '', array $filters = [], array $sorting = [], int $resultsPerPage = 12, int $page = 1): SearchResult
{
$results = $this->get(
'catalog/search/products',
Expand Down
5 changes: 5 additions & 0 deletions src/Catalog/ProductSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,9 @@ public function getCategoryPath(): array
{
return $this->categoryPath;
}

public function getSlug(): string
{
return $this->slug;
}
}
9 changes: 8 additions & 1 deletion tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use JsonSchema\Constraints\Constraint;
use JsonSchema\Validator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;
use VCR\VCR;
Expand All @@ -28,7 +30,7 @@ abstract class ApiTest extends TestCase
/**
* @var array[]
*/
private static $historyContainer = [];
protected static $historyContainer = [];

public static function getApiBaseUrl(): string
{
Expand Down Expand Up @@ -86,4 +88,9 @@ protected function tearDown(): void
}
parent::tearDown();
}

protected function getValidator(): Validator
{
return new Validator(Constraint::CHECK_MODE_TYPE_CAST);
}
}
24 changes: 24 additions & 0 deletions tests/Catalog/CatalogServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function testGetProductById()

$this->assertEquals(1, $product->getId());
$this->assertEquals('test-product-slug', $product->getSlug());
// @TODO: more assertions
} finally {
VCR::turnOff();
}
Expand All @@ -46,4 +47,27 @@ public function testGetNonExistingProductById()
VCR::turnOff();
}
}

public function testSearchOneProductByName()
{
try {
VCR::turnOn();
VCR::insertCassette($this->getName());

$catalogService = new CatalogService($this->getGuzzleClient());

$result = $catalogService->search('optio corporis similique voluptatum');

$products = $result->getProducts();
$this->assertCount(1, $products);

$product = $products[0];
$this->assertEquals(1, $product->getId());
$this->assertEquals('test-product-slug', $product->getSlug());
// @TODO: more assertions
} finally {
VCR::turnOff();
static::$historyContainer = []; // @FIXME: small hack due to fr3d/swagger-assertions not properly checking URL query non-string types.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai galéré pas mal de temps là dessus, et j'ai fini par laisser tomber. J'ouvrirai une issue sur https://github.com/Maks3w/SwaggerAssertions

En gros le problème est que quand il fait ces checks d'URL query, il prend une queryString, fait un parse_str , et se retrouve donc avec un array de strings. Puis il se plaint que ca match pas les types attendus...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux juste ajouter le lien vers l'issue dans le code ? Comme ça on pourra suivre l'évolution

}
}
}
8 changes: 4 additions & 4 deletions tests/fixtures/VCR/Swagger-schema

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions tests/fixtures/VCR/testSearchOneProductByName
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

-
request:
method: GET
url: 'http://wizaplace.loc/api/v1/catalog/search/products?resultsPerPage=12&page=1&query=optio%20corporis%20similique%20voluptatum'
headers:
Host: wizaplace.loc
Accept-Encoding: null
User-Agent: 'GuzzleHttp/6.2.1 curl/7.47.0 PHP/7.1.4-1+deb.sury.org~xenial+1'
Accept: null
response:
status:
http_version: '1.1'
code: '200'
message: OK
headers:
Date: 'Mon, 29 May 2017 10:43:50 GMT'
Server: 'Apache/2.4.10 (Debian)'
Cache-Control: 'no-cache, private'
X-Debug-Token: 0dde58
X-Debug-Token-Link: 'http://wizaplace.loc/_profiler/0dde58'
Content-Length: '1082'
Content-Type: application/json
body: '{"results":[{"productId":1,"name":"optio corporis similique voluptatum","slug":"test-product-slug","minimumPrice":40,"crossedOutPrice":451,"isAvailable":true,"createdAt":1,"updatedAt":1495619550,"transactionMode":"T","conditions":["N"],"declinationCount":1,"affiliateLink":null,"mainImage":null,"url":"\/informatique\/test-product-slug.html","subtitle":"","averageRating":null,"attributes":[],"categoryPath":[{"id":3,"name":"Informatique","slug":"informatique"}]}],"pagination":{"page":1,"nbResults":1,"nbPages":1,"resultsPerPage":12},"facets":[{"name":"categories","label":"Cat\u00e9gorie","values":{"3":{"label":"Informatique","count":"1"}},"isNumeric":false},{"name":"company_type","label":"Type de vendeur","values":{"":{"label":"w_type_product_","count":"1"}},"isNumeric":false},{"name":1,"label":"Couleur","values":{"2":{"label":"Blanc","count":0},"4":{"label":"Bleu","count":0},"1":{"label":"Noir","count":0},"3":{"label":"Rouge","count":0},"5":{"label":"test-attribute-variant-slug","count":0}},"isNumeric":false},{"name":3,"label":"Hauteur","values":[],"isNumeric":false}]}'