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
|
|
|
*/ |
35
|
|
|
public function testExecute() |
36
|
|
|
{ |
37
|
|
|
$this->commandTester->execute( |
38
|
|
|
array( |
39
|
|
|
'command' => $this->command->getName(), |
40
|
|
|
'entityType' => 'catalog_product', |
41
|
|
|
'attributeCode' => 'sku', |
42
|
|
|
) |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$result = $this->commandTester->getDisplay(); |
46
|
|
|
|
47
|
|
|
$this->assertContains('sku', $result); |
48
|
|
|
$this->assertContains('catalog_product_entity', $result); |
49
|
|
|
$this->assertContains('Backend-Type', $result); |
50
|
|
|
$this->assertContains('static', $result); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* When the attribute doesn't exist, an exception should be thrown |
55
|
|
|
* @expectedException InvalidArgumentException |
56
|
|
|
*/ |
57
|
|
|
public function testExecuteWithException() |
58
|
|
|
{ |
59
|
|
|
$this->commandTester->execute( |
60
|
|
|
array( |
61
|
|
|
'command' => $this->command->getName(), |
62
|
|
|
'entityType' => 'catalog_product', |
63
|
|
|
'attributeCode' => 'foo_bar_attribute_that_should_never_ever_ever_exist' |
64
|
|
|
|
65
|
|
|
) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* The getTableInput() method should return extra fields when it's a frontend attribute |
71
|
|
|
*/ |
72
|
|
|
public function testShouldReturnTableArrayWithOrWithoutFrontendKeys() |
73
|
|
|
{ |
74
|
|
|
$withoutFrontend = $this->command->getTableInput(false); |
75
|
|
|
$this->assertArrayHasKey('Name', $withoutFrontend); |
76
|
|
|
|
77
|
|
|
$withFrontend = $this->command->getTableInput(true); |
78
|
|
|
$this->assertArrayHasKey('Frontend/Label', $withFrontend); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* getAttribute() should return an attribute model |
83
|
|
|
*/ |
84
|
|
|
public function testGetAttribute() |
85
|
|
|
{ |
86
|
|
|
$result = $this->command->getAttribute('catalog_product', 'sku'); |
87
|
|
|
$this->assertInstanceOf('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', $result); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.