AbstractCommandTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SilverLeague\Console\Tests\Command;
4
5
use SilverLeague\Console\Command\SilverStripeCommand;
6
use SilverLeague\Console\Framework\Scaffold;
7
use Symfony\Component\Console\Tester\CommandTester;
8
9
/**
10
 * An abstract base for testing SilverStripeCommand classes
11
 *
12
 * @package silverstripe-console
13
 * @author  Robbie Averill <[email protected]>
14
 */
15
abstract class AbstractCommandTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * The test subject
19
     *
20
     * @var SilverStripeCommand
21
     */
22
    protected $command;
23
24
    /**
25
     * Add the command
26
     */
27
    protected function setUp()
28
    {
29
        $this->command = (new Scaffold)->getApplication()->find($this->getTestCommand());
30
    }
31
32
    /**
33
     * Provide the command name to test, e.g. "object:lookup"
34
     *
35
     * @return string
36
     */
37
    abstract protected function getTestCommand();
38
39
    /**
40
     * Create a CommandTester and execute the command with given arguments
41
     *
42
     * @param  array $params
43
     * @return CommandTester
44
     */
45
    protected function executeTest(array $params = [])
46
    {
47
        $tester = new CommandTester($this->command);
48
        $tester->execute($params);
49
        return $tester;
50
    }
51
}
52