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

AbstractCommandTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
getTestCommand() 0 1 ?
A executeTest() 0 8 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