1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\Console\Tests\Command\Member; |
4
|
|
|
|
5
|
|
|
use SilverLeague\Console\Tests\Command\AbstractCommandTest; |
6
|
|
|
use SilverStripe\Security\Member; |
7
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
8
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @coversDefaultClass \SilverLeague\Console\Command\Member\CreateCommand |
12
|
|
|
* @package silverstripe-console |
13
|
|
|
* @author Robbie Averill <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class CreateCommandTest extends AbstractCommandTest |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* {@inheritDoc} |
19
|
|
|
*/ |
20
|
|
|
public function getTestCommand() |
21
|
|
|
{ |
22
|
|
|
return 'member:create'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Test that a Member can be created |
27
|
|
|
* |
28
|
|
|
* @covers ::execute |
29
|
|
|
*/ |
30
|
|
|
public function testExecute() |
31
|
|
|
{ |
32
|
|
|
// Remove any existing members from the database |
33
|
|
|
Member::get()->removeAll(); |
34
|
|
|
|
35
|
|
|
$questionHelper = $this |
36
|
|
|
->getMockBuilder(QuestionHelper::class) |
37
|
|
|
->setMethods(['ask']) |
38
|
|
|
->getMock(); |
39
|
|
|
|
40
|
|
|
$questionHelper |
41
|
|
|
->expects($this->atLeastOnce()) |
42
|
|
|
->method('ask') |
43
|
|
|
->willReturn(false); |
44
|
|
|
|
45
|
|
|
$this->command->getApplication()->getHelperSet()->set($questionHelper, 'question'); |
46
|
|
|
|
47
|
|
|
$tester = new CommandTester($this->command); |
48
|
|
|
$tester->execute( |
49
|
|
|
[ |
50
|
|
|
'command' => $this->command->getName(), |
51
|
|
|
'email' => '[email protected]', |
52
|
|
|
'password' => 'opensesame' |
53
|
|
|
] |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$output = $tester->getDisplay(); |
57
|
|
|
$this->assertContains('Member created', $output); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Ensure that the InputArgument for at least one of the arguments has been added |
62
|
|
|
* |
63
|
|
|
* @covers ::configure |
64
|
|
|
*/ |
65
|
|
|
public function testConfigure() |
66
|
|
|
{ |
67
|
|
|
$this->assertTrue($this->command->getDefinition()->hasArgument('email')); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|