Passed
Pull Request — master (#56)
by Robbie
04:41
created

LockCommandTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 52
loc 52
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 9 9 3
A getTestCommand() 4 4 1
A testExecute() 11 11 1
A testMemberNotFound() 5 5 1
A createMember() 8 8 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
 * Test the lock member command
10
 *
11
 * @package silverstripe-console
12
 * @author  Robbie Averill <[email protected]>
13
 */
14 View Code Duplication
class LockCommandTest extends AbstractCommandTest
15
{
16
    /**
17
     * Delete fixtured members after tests have run
18
     */
19
    protected function tearDown()
20
    {
21
        parent::tearDown();
22
23
        $testMember = Member::get()->filter(['Email' => '[email protected]'])->first();
24
        if ($testMember && $testMember->exists()) {
25
            $testMember->delete();
26
        }
27
    }
28
29
    protected function getTestCommand()
30
    {
31
        return 'member:lock';
32
    }
33
34
    public function testExecute()
35
    {
36
        $member = $this->createMember();
37
        $this->assertFalse($member->isLockedOut());
38
39
        $tester = $this->executeTest(['email' => '[email protected]']);
40
        /** @var Member $member */
41
        $member = Member::get()->byID($member->ID);
42
        $this->assertContains('Member [email protected] locked for', $tester->getDisplay());
43
        $this->assertTrue($member->isLockedOut());
44
    }
45
46
    public function testMemberNotFound()
47
    {
48
        $result = $this->executeTest(['email' => '[email protected]']);
49
        $this->assertContains('Member with email "[email protected]" was not found.', $result->getDisplay());
50
    }
51
52
    /**
53
     * Creates a dummy user for testing with
54
     *
55
     * @return Member
56
     */
57
    protected function createMember()
58
    {
59
        $member = Member::create();
60
        $member->Email = '[email protected]';
61
        $member->Password = 'Opensesame1';
62
        $member->write();
63
        return $member;
64
    }
65
}
66