Behat: Expect exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Thengine\Behat\Context\Domain\Tariff\Model; | |
use Behat\Behat\Context\Context; | |
use Thengine\Domain\Tariff\Model\Tariff; | |
use Thengine\Domain\Tariff\Model\TariffCategory; | |
use Thengine\Domain\Tariff\Exception\CannotRemoveCategoryException; | |
use Thengine\Test\Assert\Exception\ExpectationFailedException; | |
final class TariffContext implements Context | |
{ | |
// .. | |
/** | |
* @Then I should not be able to remove the tariff ":tariff" from category ":tariffCategory" | |
*/ | |
public function expectCannotRemoveCategoryException(Tariff $tariff, TariffCategory $tariffCategory) | |
{ | |
$this->manager->refresh($tariff); | |
$this->manager->refresh($tariffCategory); | |
try { | |
$tariffCategory->removeTariff($tariff); | |
throw new ExpectationFailedException('The category should not be removable.'); | |
} catch (CannotRemoveCategoryException $e) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment