Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TablerateTest.php
Go to the documentation of this file.
1 <?php
7 
8 class TablerateTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $model;
14 
19 
20  protected function setUp()
21  {
22  $this->carrierTablerateMock = $this->getMockBuilder(\Magento\OfflineShipping\Model\Carrier\Tablerate::class)
23  ->disableOriginalConstructor()
24  ->setMethods(['getCode'])
25  ->getMock();
26 
27  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
28  $this->model = $helper->getObject(
29  \Magento\OfflineShipping\Model\Config\Source\Tablerate::class,
30  ['carrierTablerate' => $this->carrierTablerateMock]
31  );
32  }
33 
34  public function testToOptionArray()
35  {
36  $codes = [1, 2, 3, 4, 5];
37  $expected = [];
38  foreach ($codes as $k => $v) {
39  $expected[] = ['value' => $k, 'label' => $v];
40  }
41 
42  $this->carrierTablerateMock->expects($this->once())
43  ->method('getCode')
44  ->willReturn($codes);
45 
46  $this->assertEquals($expected, $this->model->toOptionArray());
47  }
48 }
$helper
Definition: iframe.phtml:13