Completed
Push — master ( 383d0c...3523cb )
by Tom
04:14
created

ViewCommandTest::getTableInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command\Eav\Attribute;
4
5
use N98\Magento\Application;
6
use Symfony\Component\Console\Tester\CommandTester;
7
use N98\Magento\Command\PHPUnit\TestCase;
8
9
class ViewCommandTest extends TestCase
10
{
11
    /**
12
     * The test subject
13
     * @var ViewCommand
14
     */
15
    private $command;
16
17
    /**
18
     * @var CommandTester
19
     */
20
    private $commandTester;
21
22
    /**
23
     * Initialize the command and the tester
24
     */
25 View Code Duplication
    public function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
26
    {
27
        /** @var Application $application */
28
        $application = $this->getApplication();
29
        $application->add(new ViewCommand());
30
        $this->command = $application->find('eav:attribute:view');
31
        $this->commandTester = new CommandTester($this->command);
32
    }
33
34
    /**
35
     * Ensure that the ViewCommand returns information about the supplied attribute
36
     * @test
37
     */
38
    public function execute()
39
    {
40
        $this->commandTester->execute(
41
            array(
42
                'command'       => $this->command->getName(),
43
                'entityType'    => 'catalog_product',
44
                'attributeCode' => 'sku',
45
            )
46
        );
47
48
        $result = $this->commandTester->getDisplay();
49
50
        $this->assertContains('sku', $result);
51
        $this->assertContains('catalog_product_entity', $result);
52
        $this->assertContains('Backend-Type', $result);
53
        $this->assertContains('static', $result);
54
    }
55
56
    /**
57
     * When the attribute doesn't exist, an exception should be thrown
58
     * @expectedException InvalidArgumentException
59
     * @test
60
     */
61
    public function executeWithException()
62
    {
63
        $this->commandTester->execute(
64
            array(
65
                'command'       => $this->command->getName(),
66
                'entityType'    => 'catalog_product',
67
                'attributeCode' => 'foo_bar_attribute_that_should_never_ever_ever_exist'
68
69
            )
70
        );
71
    }
72
73
    /**
74
     * Should return extra fields when it's a frontend attribute
75
     * @test
76
     */
77
    public function getTableInput()
78
    {
79
        $withoutFrontend = $this->command->getTableInput(false);
80
        $this->assertArrayHasKey('Name', $withoutFrontend);
81
82
        $withFrontend = $this->command->getTableInput(true);
83
        $this->assertArrayHasKey('Frontend/Label', $withFrontend);
84
    }
85
86
    /**
87
     * Should return an attribute model (from the abstract class)
88
     * @test
89
     */
90
    public function getAttribute()
91
    {
92
        $result = $this->command->getAttribute('catalog_product', 'sku');
93
        $this->assertInstanceOf('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', $result);
94
    }
95
}
96