ChangePasswordCommandTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 13.24 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 4
dl 9
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 9 9 1
A tearDown() 0 9 3
A getTestCommand() 0 4 1
A testExecute() 0 5 1
A testErrorWhenEmailNotFound() 0 5 1
A testConfigure() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
    protected function setUp()
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...
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
    protected function tearDown()
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