Completed
Push — master ( 29ee36...16ede1 )
by Tom
03:58
created

CreateCommandTest::_getCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command\Customer;
4
5
use Magento\Store\Model\StoreManagerInterface;
6
use N98\Magento\Command\TestCase;
7
use Symfony\Component\Console\Tester\CommandTester;
8
9
class CreateCommandTest extends TestCase
10
{
11
    /**
12
     * @outputBuffering
13
     */
14
    public function testExecute()
15
    {
16
        $generatedEmail = uniqid() . '@example.com';
17
18
        $input = array(
19
            'command'   => 'customer:create',
20
            'email'     => $generatedEmail,
21
            'password'  => 'password123',
22
            'firstname' => 'John',
23
            'lastname'  => 'Doe',
24
            'website'   => $this->getWebsiteCode(),
25
        );
26
        $this->assertDisplayContains($input, 'successfully created');
27
28
        // Format option
29
        $generatedEmail = uniqid() . '@example.com';
30
        $input['email'] = $generatedEmail;
31
        $input['--format'] = 'csv';
32
33
        $this->assertDisplayContains($input, 'email,password,firstname,lastname');
34
        $this->assertdisplayContains($input, $generatedEmail . ',password123,John,Doe');
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    private function getWebsiteCode()
41
    {
42
        $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...
43
        $website = $storeManager->getWebsite();
44
45
        return $website->getCode();
46
    }
47
48
    public function testWithWrongPassword()
49
    {
50
        $this->markTestIncomplete('We currently cannot deal with interactive commands');
51
52
        $application = $this->getApplication();
53
        $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...
54
55
        // try to create a customer with a password < 6 chars
56
        $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...
57
58
        $generatedEmail = uniqid() . '@example.com';
59
60
        // mock dialog
61
        // We mock the DialogHelper
62
        $dialog = $this->getMock('N98\Util\Console\Helper\ParameterHelper', array('askPassword'));
63
        $dialog->expects($this->at(0))
64
            ->method('askPassword')
65
            ->will($this->returnValue(true)); // The user confirms
66
67
        // We override the standard helper with our mock
68
        $command->getHelperSet()->set($dialog, 'parameter');
69
70
        $options = array(
71
            'command'   => $command->getName(),
72
            'email'     => $generatedEmail,
73
            'password'  => 'pass',
74
            'firstname' => 'John',
75
            'lastname'  => 'Doe',
76
        );
77
        $commandTester = new CommandTester($command);
78
        $commandTester->execute($options);
79
        $this->assertRegExp(
80
            '/The password must have at least 6 characters. Leading or trailing spaces will be ignored./',
81
            $commandTester->getDisplay()
82
        );
83
    }
84
}
85