Skip to content

Instantly share code, notes, and snippets.

@havvg
Last active March 26, 2017 09:25
Show Gist options
  • Save havvg/8baf952ef5ba87c1452d0a28db79b5db to your computer and use it in GitHub Desktop.
Save havvg/8baf952ef5ba87c1452d0a28db79b5db to your computer and use it in GitHub Desktop.
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