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); |
|
|
|
|
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()); |
|
|
|
|
54
|
|
|
|
55
|
|
|
// try to create a customer with a password < 6 chars |
56
|
|
|
$command = $this->getApplication()->find('customer:create'); |
|
|
|
|
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
|
|
|
|
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: