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

CreateCommandTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 15.25 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 9
loc 59
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestCommand() 0 4 1
A tearDown() 9 9 3
A testExecute() 0 23 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\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