Completed
Push — master ( ec1dbf...510cdb )
by Gabriel
04:59 queued 51s
created

EanFieldTest::testOptions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 27
ccs 17
cts 17
cp 1
crap 1
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
4
namespace Stockbase\Integration\Test\Unit\Model\Config\Source;
5
6
use Magento\Customer\Api\Data\AttributeMetadataInterface;
7
use Magento\Eav\Model\Entity\Attribute\Set;
8
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection;
9
use Magento\Framework\ObjectManagerInterface;
10
use PHPUnit\Framework\TestCase;
11
use Stockbase\Integration\Model\Config\Source\EanField;
12
13
/**
14
 * Class EanFieldTest
15
 */
16
class EanFieldTest extends TestCase
17
{
18
    /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
19
    private $objectManager;
20
21
    /** @var Collection|\PHPUnit_Framework_MockObject_MockObject */
22
    private $collection;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 1
    public function setUp()
28
    {
29 1
        $this->collection = $this->createMock(Collection::class);
30
        
31 1
        $this->objectManager = $this->createMock(ObjectManagerInterface::class);
32 1
        $this->objectManager->method('get')->with(Collection::class)->willReturn($this->collection);
33 1
    }
34
35
    /**
36
     * testOptions
37
     */
38 1
    public function testOptions()
39
    {
40 1
        $this->collection->expects($this->once())->method('addFieldToFilter')
41 1
            ->with(Set::KEY_ENTITY_TYPE_ID, 4);
42
        
43 1
        $this->collection->expects($this->once())->method('load')
44 1
            ->willReturnSelf();
45
        
46 1
        $items = [];
47 1
        $item = $this->createMock(AttributeMetadataInterface::class);
48 1
        $item->method('getFrontendLabel')->willReturn('Test Attribute');
49 1
        $item->method('getAttributeCode')->willReturn('test');
50 1
        $items[] = $item;
51
        
52 1
        $this->collection->expects($this->once())->method('getItems')
53 1
            ->willReturn($items);
54
        
55 1
        $fieldSource = new EanField($this->objectManager);
56 1
        $result = $fieldSource->toOptionArray();
57
        
58
        $expectedResult = [
59 1
            ['label' => '', 'value' => ''],
60
            ['label' => 'Test Attribute', 'value' => 'test'],
61
        ];
62
        
63 1
        $this->assertEquals($expectedResult, $result);
64 1
    }
65
}
66