1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\Console\Tests\Command; |
4
|
|
|
|
5
|
|
|
use SilverLeague\Console\Command\SilverStripeCommand; |
6
|
|
|
use SilverLeague\Console\Framework\Scaffold; |
7
|
|
|
use SilverStripe\Core\Config\Config; |
8
|
|
|
use SilverStripe\Core\Injector\Injector; |
9
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Console\Question\Question; |
13
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @coversDefaultClass \SilverLeague\Console\Command\SilverStripeCommand |
17
|
|
|
* @package silverstripe-console |
18
|
|
|
* @author Robbie Averill <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class SilverStripeCommandTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Test that an argument is prompted for if it doesn't get provided, or returned if provided |
24
|
|
|
* |
25
|
|
|
* @covers ::getOrAskForArgument |
26
|
|
|
*/ |
27
|
|
|
public function testGetOrAskForArgument() |
28
|
|
|
{ |
29
|
|
|
$questionHelper = $this |
30
|
|
|
->getMockBuilder(QuestionHelper::class) |
31
|
|
|
->setMethods(['ask']) |
32
|
|
|
->getMock(); |
33
|
|
|
|
34
|
|
|
$questionHelper |
35
|
|
|
->expects($this->atLeastOnce()) |
36
|
|
|
->method('ask') |
37
|
|
|
->with( |
38
|
|
|
$this->isInstanceOf(InputInterface::class), |
39
|
|
|
$this->isInstanceOf(OutputInterface::class), |
40
|
|
|
$this->isInstanceOf(Question::class) |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$application = (new Scaffold)->getApplication(); |
44
|
|
|
$application->getHelperSet()->set($questionHelper, 'question'); |
45
|
|
|
|
46
|
|
|
$command = $application->find('member:create'); |
47
|
|
|
|
48
|
|
|
$tester = new CommandTester($command); |
49
|
|
|
$tester->execute( |
50
|
|
|
[ |
51
|
|
|
'command' => $command->getName(), |
52
|
|
|
'email' => '[email protected]' |
53
|
|
|
] |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
// Check that the email is returned since it existed |
57
|
|
|
$this->assertSame('[email protected]', $tester->getInput()->getArgument('email')); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Test that the Injector is returned |
62
|
|
|
* |
63
|
|
|
* @covers ::getInjector |
64
|
|
|
*/ |
65
|
|
|
public function testShouldReturnInjector() |
66
|
|
|
{ |
67
|
|
|
$this->assertInstanceOf(Injector::class, (new SilverStripeCommand('foo'))->getInjector()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Test that a Config instance is returned |
72
|
|
|
* |
73
|
|
|
* @covers ::getConfig |
74
|
|
|
*/ |
75
|
|
|
public function testShouldReturnConfig() |
76
|
|
|
{ |
77
|
|
|
$this->assertInstanceOf(Config::class, (new SilverStripeCommand('bar'))->getConfig()); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|