Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractSwatchTest.php
Go to the documentation of this file.
1 <?php
8 
9 class AbstractSwatchTest extends \PHPUnit\Framework\TestCase
10 {
12  private $swatch;
13 
15  private $attribute;
16 
18  private $source;
19 
20  protected function setUp()
21  {
22  $this->source = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource::class)
23  ->getMockForAbstractClass();
24 
25  $this->attribute = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
26  ->disableOriginalConstructor()
27  ->getMock();
28 
29  $this->swatch = $this->getMockBuilder(\Magento\Swatches\Model\Form\Element\AbstractSwatch::class)
30  ->disableOriginalConstructor()
31  ->setMethods(['getData'])
32  ->getMockForAbstractClass();
33  }
34 
35  public function testGetValues()
36  {
37  $expected = [1, 2, 3];
38 
39  $this->source->expects($this->once())->method('getAllOptions')
40  ->with(true, true)
41  ->willReturn($expected);
42  $this->attribute->expects($this->once())->method('getSource')
43  ->willReturn($this->source);
44  $this->swatch->expects($this->once())->method('getData')
45  ->with('entity_attribute')
46  ->willReturn($this->attribute);
47 
48  $method = new \ReflectionMethod(\Magento\Swatches\Model\Form\Element\AbstractSwatch::class, 'getValues');
49  $method->setAccessible(true);
50 
51  $this->assertEquals($expected, $method->invoke($this->swatch));
52  }
53 
54  public function testGetValuesEmpty()
55  {
56  $this->swatch->expects($this->once())->method('getData')
57  ->with('entity_attribute')
58  ->willReturn(null);
59 
60  $method = new \ReflectionMethod(\Magento\Swatches\Model\Form\Element\AbstractSwatch::class, 'getValues');
61  $method->setAccessible(true);
62 
63  $this->assertEmpty($method->invoke($this->swatch));
64  }
65 }
$method
Definition: info.phtml:13