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

ChangePasswordCommandTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 36.11 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 26
loc 72
rs 10
c 1
b 0
f 0

5 Methods

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