Skip to content

Instantly share code, notes, and snippets.

@havvg
Last active Mar 26, 2017
Embed
What would you like to do?
Behat: Expect exceptions
<?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