[Behat][API] Introduce common ResponseContext service

This commit is contained in:
Rafikooo 2023-04-07 09:37:54 +02:00
parent d40ecdffc0
commit 3dccd16479
No known key found for this signature in database
GPG key ID: 4A26D8327BC2442B
2 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Behat\Context\Api\Common;
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Webmozart\Assert\Assert;
final class ResponseContext implements Context
{
public function __construct(private ResponseCheckerInterface $responseChecker, private ApiClientInterface $client)
{
}
/**
* @Then I should be notified that it has been successfully edited
*/
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void
{
Assert::true(
$this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()),
sprintf(
'Resource could not be edited: %s',
$this->responseChecker->getError($this->client->getLastResponse()),
),
);
}
}

View file

@ -22,5 +22,15 @@
<service id="sylius.behat.context.api.shop.save" class="Sylius\Behat\Context\Api\Common\SaveContext">
<argument type="service" id="sylius.behat.api_platform_client.shop" />
</service>
<service id="sylius.behat.context.api.admin.response" class="Sylius\Behat\Context\Api\Common\ResponseContext">
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="sylius.behat.api_platform_client.admin" />
</service>
<service id="sylius.behat.context.api.shop.response" class="Sylius\Behat\Context\Api\Common\ResponseContext">
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="sylius.behat.api_platform_client.shop" />
</service>
</services>
</container>