Completed
Push — master ( 01b890...0ab6a2 )
by Robbie
01:15
created

AbstractCommandTest::executeTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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