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

EanFieldTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
B testOptions() 0 27 1
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