Completed
Push — develop ( 73bd0a...ccb498 )
by Tom
05:04
created

CreateCommandTest::testWithWrongPassword()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command\Customer;
4
5
use Magento\Store\Model\StoreManagerInterface;
6
use Symfony\Component\Console\Tester\CommandTester;
7
use N98\Magento\Command\PHPUnit\TestCase;
8
9
class CreateCommandTest extends TestCase
10
{
11
    /**
12
     * @outputBuffering
13
     */
14
    public function testExecute()
15
    {
16
        $command = $this->_getCommand();
17
        $generatedEmail = uniqid() . '@example.com';
18
19
        $storeManager = $this->getApplication()->getObjectManager()->get(StoreManagerInterface::class);
0 ignored issues
show
Bug introduced by
The method getObjectManager does only exist in N98\Magento\Application, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
20
        $website = $storeManager->getWebsite();
21
22
        $commandTester = new CommandTester($command);
23
        $options = array(
24
            'command'   => $command->getName(),
25
            'email'     => $generatedEmail,
26
            'password'  => 'password123',
27
            'firstname' => 'John',
28
            'lastname'  => 'Doe',
29
            'website'   => $website->getCode(),
30
        );
31
        $commandTester->execute($options);
32
        $this->assertRegExp('/successfully created/', $commandTester->getDisplay());
33
34
        // Format option
35
        $commandTester = new CommandTester($command);
36
        $generatedEmail = uniqid() . '@example.com';
37
        $options['email'] = $generatedEmail;
38
        $options['--format'] = 'csv';
39
        $this->assertEquals(0, $commandTester->execute($options));
40
        $this->assertContains('email,password,firstname,lastname', $commandTester->getDisplay());
41
        $this->assertContains($generatedEmail . ',password123,John,Doe', $commandTester->getDisplay());
42
    }
43
44
    public function testWithWrongPassword()
45
    {
46
        $this->markTestIncomplete('We currently cannot deal with interactive commands');
47
48
        $command = $this->_getCommand();
49
        $generatedEmail = uniqid() . '@example.com';
50
51
        // mock dialog
52
        // We mock the DialogHelper
53
        $dialog = $this->getMock('N98\Util\Console\Helper\ParameterHelper', array('askPassword'));
54
        $dialog->expects($this->at(0))
55
            ->method('askPassword')
56
            ->will($this->returnValue(true)); // The user confirms
57
58
        // We override the standard helper with our mock
59
        $command->getHelperSet()->set($dialog, 'parameter');
60
61
        $options = array(
62
            'command'   => $command->getName(),
63
            'email'     => $generatedEmail,
64
            'password'  => 'pass',
65
            'firstname' => 'John',
66
            'lastname'  => 'Doe',
67
        );
68
        $commandTester = new CommandTester($command);
69
        $commandTester->execute($options);
70
        $this->assertRegExp('/The password must have at least 6 characters. Leading or trailing spaces will be ignored./', $commandTester->getDisplay());
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 153 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
71
    }
72
73
    /**
74
     * @return CreateCommand
75
     */
76
    protected function _getCommand()
77
    {
78
        $application = $this->getApplication();
79
        $application->add(new CreateCommand());
0 ignored issues
show
Bug introduced by
The method add does only exist in N98\Magento\Application, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
80
81
        // try to create a customer with a password < 6 chars
82
        $command = $this->getApplication()->find('customer:create');
0 ignored issues
show
Bug introduced by
The method find does only exist in N98\Magento\Application, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
83
84
        return $command;
85
    }
86
}
87