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); |
|
|
|
|
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()); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return CreateCommand |
75
|
|
|
*/ |
76
|
|
|
protected function _getCommand() |
77
|
|
|
{ |
78
|
|
|
$application = $this->getApplication(); |
79
|
|
|
$application->add(new CreateCommand()); |
|
|
|
|
80
|
|
|
|
81
|
|
|
// try to create a customer with a password < 6 chars |
82
|
|
|
$command = $this->getApplication()->find('customer:create'); |
|
|
|
|
83
|
|
|
|
84
|
|
|
return $command; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: