Completed
Pull Request — master (#25)
by Robbie
03:50 queued 42s
created

CreateCommandTest::testExecute()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 29
rs 8.8571
c 1
b 0
f 0
cc 1
eloc 18
nc 1
nop 0
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