1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Customer\Token; |
4
|
|
|
|
5
|
|
|
use Magento\Store\Model\StoreManagerInterface; |
6
|
|
|
use N98\Magento\Command\TestCase; |
7
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
8
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
9
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class CreateCommandTest |
13
|
|
|
* @package N98\Magento\Command\Customer\Token |
14
|
|
|
*/ |
15
|
|
|
class CreateCommandTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testExecute() |
18
|
|
|
{ |
19
|
|
|
$generatedEmail = uniqid() . '@example.com'; |
20
|
|
|
|
21
|
|
|
$this->getApplication()->setAutoExit(false); |
|
|
|
|
22
|
|
|
$this->getApplication()->run( |
|
|
|
|
23
|
|
|
new ArrayInput( |
24
|
|
|
[ |
25
|
|
|
'command' => 'customer:create', |
26
|
|
|
'email' => $generatedEmail, |
27
|
|
|
'password' => 'Password123', |
28
|
|
|
'firstname' => 'John', |
29
|
|
|
'lastname' => 'Doe', |
30
|
|
|
'website' => $this->getWebsiteCode(), |
31
|
|
|
] |
32
|
|
|
), |
33
|
|
|
new NullOutput() |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
$command = $this->getApplication()->find('customer:token:create'); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$commandTester = new CommandTester($command); |
39
|
|
|
$commandTester->execute([ |
40
|
|
|
'email' => $generatedEmail, |
41
|
|
|
'--no-newline' => true, |
42
|
|
|
]); |
43
|
|
|
|
44
|
|
|
$output = $commandTester->getDisplay(); |
45
|
|
|
$this->assertNotEmpty($output); |
46
|
|
|
$this->assertEquals(32, strlen($output)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
private function getWebsiteCode() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$storeManager = $this->getApplication()->getObjectManager()->get(StoreManagerInterface::class); |
|
|
|
|
55
|
|
|
$website = $storeManager->getWebsite('base'); |
56
|
|
|
|
57
|
|
|
return $website->getCode(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
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: