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

ChangePasswordCommandTest::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
8
/**
9
 * @coversDefaultClass \SilverLeague\Console\Command\Member\ChangePasswordCommand
10
 * @package silverstripe-console
11
 * @author  Robbie Averill <[email protected]>
12
 */
13
class ChangePasswordCommandTest extends AbstractCommandTest
14
{
15
    /**
16
     * Create a Member to play with
17
     */
18
    protected function setUp()
19
    {
20
        parent::setUp();
21
22
        $member = Member::create();
23
        $member->Email = '[email protected]';
24
        $member->Password = 'NotRelevant1';
25
        $member->write();
26
    }
27
28
    /**
29
     * Delete fixtured members after tests have run
30
     */
31 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...
32
    {
33
        parent::tearDown();
34
35
        $testMember = Member::get()->filter(['Email' => '[email protected]'])->first();
36
        if ($testMember && $testMember->exists()) {
37
            $testMember->delete();
38
        }
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    protected function getTestCommand()
45
    {
46
        return 'member:change-password';
47
    }
48
49
    /**
50
     * Test that our existing Member's password can be changed
51
     *
52
     * @covers ::execute
53
     */
54
    public function testExecute()
55
    {
56
        $tester = $this->executeTest(['email' => '[email protected]', 'password' => 'NewPassword123']);
57
        $this->assertContains('Password updated', $tester->getDisplay());
58
    }
59
60
    /**
61
     * Test that if an email does not match a Member, then an error is returned
62
     *
63
     * @covers ::execute
64
     */
65
    public function testErrorWhenEmailNotFound()
66
    {
67
        $tester = $this->executeTest(['email' => '[email protected]', 'password' => 'NewPassword234']);
68
        $this->assertContains('Member with email "[email protected]" was not found', $tester->getDisplay());
69
    }
70
71
    /**
72
     * Ensure that the InputArgument for at least one of the arguments has been added
73
     *
74
     * @covers ::configure
75
     */
76
    public function testConfigure()
77
    {
78
        $this->assertTrue($this->command->getDefinition()->hasArgument('password'));
79
    }
80
}
81