Passed
Push — master ( f2e14b...2db21b )
by Robbie
04:12
created

CreateCommandTest::tearDown()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 3
eloc 5
nc 2
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 View Code Duplication
    protected function tearDown()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
            [
55
                'email'    => '[email protected]',
56
                'password' => 'OpenSe$am3!'
57
            ]
58
        );
59
        $output = $tester->getDisplay();
60
        $this->assertContains('Member created', $output);
61
    }
62
63
    /**
64
     * Ensure that the InputArgument for at least one of the arguments has been added
65
     *
66
     * @covers ::configure
67
     */
68
    public function testConfigure()
69
    {
70
        $this->assertTrue($this->command->getDefinition()->hasArgument('email'));
71
    }
72
}
73