| 1 | <?php |
||
| 10 | class FeatureContext implements Context |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var Application |
||
| 14 | */ |
||
| 15 | private $application; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var |
||
| 19 | */ |
||
| 20 | private $tester; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * FeatureContext constructor. |
||
| 24 | */ |
||
| 25 | public function __construct() |
||
| 26 | { |
||
| 27 | if (false === @copy(realpath(__DIR__ . '/../../bin/uspec.pubkey'), BEHAT_BIN_PATH . '.pubkey')) { |
||
| 28 | throw new \RuntimeException('Application public key is not available'); |
||
| 29 | } |
||
| 30 | |||
| 31 | $this->application = new Application('SugarCRM upgrade spec generator', '@test'); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * FeatureContext destructor. |
||
| 36 | */ |
||
| 37 | public function __destruct() |
||
| 38 | { |
||
| 39 | @unlink(BEHAT_BIN_PATH . '.pubkey'); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @When /^I run "([^"]*)" command$/ |
||
| 44 | */ |
||
| 45 | public function iRunCommand($name) |
||
| 46 | { |
||
| 47 | $command = $this->application->find($name); |
||
| 48 | |||
| 49 | $this->tester = new CommandTester($command); |
||
| 50 | $this->tester->execute(array('command' => $command->getName())); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @Then /^I should see "([^"]*)"$/ |
||
| 55 | */ |
||
| 56 | public function iShouldSee($regexp) |
||
| 57 | { |
||
| 58 | return call_user_func_array( |
||
| 59 | [PHPUnit_Framework_Assert::class, 'assertRegExp'], |
||
| 60 | [$regexp, $this->tester->getDisplay()] |
||
| 61 | ); |
||
| 62 | } |
||
| 63 | } |
||
| 64 |