CreateCommandTest::testExecute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
cc 1
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
9
/**
10
 * @coversDefaultClass \SilverLeague\Console\Command\Member\CreateCommand
11
 * @package silverstripe-console
12
 * @author  Robbie Averill <[email protected]>
13
 */
14
class CreateCommandTest extends AbstractCommandTest
15
{
16
    protected function getTestCommand()
17
    {
18
        return 'member:create';
19
    }
20
21
    /**
22
     * Delete fixtured members after tests have run
23
     */
24
    protected function tearDown()
25
    {
26
        parent::tearDown();
27
28
        $testMember = Member::get()->filter(['Email' => '[email protected]'])->first();
29
        if ($testMember && $testMember->exists()) {
30
            $testMember->delete();
31
        }
32
    }
33
34
    /**
35
     * Test that a Member can be created
36
     *
37
     * @covers ::execute
38
     */
39
    public function testExecute()
40
    {
41
        $questionHelper = $this
42
            ->getMockBuilder(QuestionHelper::class)
43
            ->setMethods(['ask'])
44
            ->getMock();
45
46
        $questionHelper
47
            ->expects($this->atLeastOnce())
48
            ->method('ask')
49
            ->willReturn(false);
50
51
        $this->command->getApplication()->getHelperSet()->set($questionHelper, 'question');
52
53
        $tester = $this->executeTest([
54
            'email'    => '[email protected]',
55
            'password' => 'OpenSe$am3!',
56
        ]);
57
        $output = $tester->getDisplay();
58
        $this->assertContains('Member created', $output);
59
60
        $tester = $this->executeTest([
61
            'email'    => '[email protected]',
62
            'password' => 'OpenSe$am3!',
63
        ]);
64
        $output = $tester->getDisplay();
65
        $this->assertContains('Member already exists', $output);
66
    }
67
68
    /**
69
     * Ensure that the InputArgument for at least one of the arguments has been added
70
     *
71
     * @covers ::configure
72
     */
73
    public function testConfigure()
74
    {
75
        $this->assertTrue($this->command->getDefinition()->hasArgument('email'));
76
    }
77
}
78