Completed
Push — master ( 6e1671...1f3fa8 )
by Mike
02:28
created

FeatureContext::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace features\Sugarcrm\UpgradeSpec\Context;
4
5
use Behat\Behat\Context\Context;
6
use PHPUnit_Framework_Assert;
7
use Sugarcrm\UpgradeSpec\Application;
8
use Symfony\Component\Console\Tester\CommandTester;
9
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