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

[API] improve tests for overwriting api configs #12411

Merged
Merged
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
36 changes: 28 additions & 8 deletions src/Sylius/Bundle/ApiBundle/test/src/Tests/PromotionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,33 @@ public function setUp(): void
/**
* @test
*/
public function it_allows_to_get_collection_as_a_visitor_on_resource_from_api_bundle_with_customized_path(): void
public function it_gets_resource_collection_as_a_guest_by_custom_path(): void
{
$response = static::createClient()->request('GET', '/api/v2/custom/promotions');
static::createClient()->request('GET', '/api/v2/custom/promotions');

$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');

$objects = json_decode($response->getContent(), true)['hydra:member'];
$this->assertSame('Sunday promotion', $objects[0]['name']);
$this->assertJsonContains([
'@context' => '/api/v2/contexts/Promotion',
'@id' => '/api/v2/custom/promotions',
'@type' => 'hydra:Collection',
'hydra:member' => [
[
'@type' => 'Promotion',
'name' => 'Sunday promotion'
],
],
'hydra:totalItems' => 1,
]);
}

/**
* @test
*/
public function it_allows_to_get_collection_as_an_login_administrator_on_resource_from_api_bundle_with_customized_path(): void
public function it_gets_resource_collection_as_a_admin_by_custom_path(): void
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function it_gets_resource_collection_as_a_admin_by_custom_path(): void
public function it_gets_resource_collection_as_an_logged_in_administrator_by_custom_path(): void

{
$response = static::createClient()->request(
static::createClient()->request(
'GET',
'/api/v2/custom/promotions',
['auth_bearer' => $this->JWTAdminUserToken]
Expand All @@ -53,7 +63,17 @@ public function it_allows_to_get_collection_as_an_login_administrator_on_resourc
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');

$objects = json_decode($response->getContent(), true)['hydra:member'];
$this->assertSame('Sunday promotion', $objects[0]['name']);
$this->assertJsonContains([
'@context' => '/api/v2/contexts/Promotion',
'@id' => '/api/v2/custom/promotions',
'@type' => 'hydra:Collection',
'hydra:member' => [
[
'@type' => 'Promotion',
'name' => 'Sunday promotion'
],
],
'hydra:totalItems' => 1,
]);
}
}