1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Eav\Attribute; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
6
|
|
|
use N98\Magento\Command\PHPUnit\TestCase; |
7
|
|
|
|
8
|
|
|
class ViewCommandTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The test subject |
12
|
|
|
* @var ViewCommand |
13
|
|
|
*/ |
14
|
|
|
private $command; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var CommandTester |
18
|
|
|
*/ |
19
|
|
|
private $commandTester; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Initialize the command and the tester |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function setUp() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$this->getApplication()->add(new ViewCommand()); |
|
|
|
|
27
|
|
|
$this->command = $this->getApplication()->find('eav:attribute:view'); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$this->commandTester = new CommandTester($this->command); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Ensure that the ViewCommand returns information about the supplied attribute |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function execute() |
37
|
|
|
{ |
38
|
|
|
$this->commandTester->execute( |
39
|
|
|
array( |
40
|
|
|
'command' => $this->command->getName(), |
41
|
|
|
'entityType' => 'catalog_product', |
42
|
|
|
'attributeCode' => 'sku', |
43
|
|
|
) |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$result = $this->commandTester->getDisplay(); |
47
|
|
|
|
48
|
|
|
$this->assertContains('sku', $result); |
49
|
|
|
$this->assertContains('catalog_product_entity', $result); |
50
|
|
|
$this->assertContains('Backend-Type', $result); |
51
|
|
|
$this->assertContains('static', $result); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* When the attribute doesn't exist, an exception should be thrown |
56
|
|
|
* @expectedException InvalidArgumentException |
57
|
|
|
* @test |
58
|
|
|
*/ |
59
|
|
|
public function executeWithException() |
60
|
|
|
{ |
61
|
|
|
$this->commandTester->execute( |
62
|
|
|
array( |
63
|
|
|
'command' => $this->command->getName(), |
64
|
|
|
'entityType' => 'catalog_product', |
65
|
|
|
'attributeCode' => 'foo_bar_attribute_that_should_never_ever_ever_exist' |
66
|
|
|
|
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Should return extra fields when it's a frontend attribute |
73
|
|
|
* @test |
74
|
|
|
*/ |
75
|
|
|
public function getTableInput() |
76
|
|
|
{ |
77
|
|
|
$withoutFrontend = $this->command->getTableInput(false); |
78
|
|
|
$this->assertArrayHasKey('Name', $withoutFrontend); |
79
|
|
|
|
80
|
|
|
$withFrontend = $this->command->getTableInput(true); |
81
|
|
|
$this->assertArrayHasKey('Frontend/Label', $withFrontend); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Should return an attribute model (from the abstract class) |
86
|
|
|
* @test |
87
|
|
|
*/ |
88
|
|
|
public function getAttribute() |
89
|
|
|
{ |
90
|
|
|
$result = $this->command->getAttribute('catalog_product', 'sku'); |
91
|
|
|
$this->assertInstanceOf('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', $result); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.