Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceAbstractTest.php
Go to the documentation of this file.
1 <?php
7 
8 class SourceAbstractTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_model = null;
14 
15  protected function setUp()
16  {
17  $this->_model = $this->getMockForAbstractClass(
18  \Magento\ImportExport\Model\Import\AbstractSource::class,
19  [['key1', 'key2', 'key3']]
20  );
21  }
22 
28  public function testConstructException($argument)
29  {
30  $this->getMockForAbstractClass(\Magento\ImportExport\Model\Import\AbstractSource::class, [$argument]);
31  }
32 
37  {
38  return ['empty column names' => [[]], 'duplicate column names' => [['1', '2', '1']]];
39  }
40 
41  public function testGetColNames()
42  {
43  $this->assertSame(['key1', 'key2', 'key3'], $this->_model->getColNames());
44  }
45 
50  public function testIteratorInterface()
51  {
52  $this->assertSame(-1, $this->_model->key());
53  $this->assertFalse($this->_model->valid());
54 
55  $this->_model->expects(
56  $this->exactly(4)
57  )->method(
58  '_getNextRow'
59  )->will(
60  $this->onConsecutiveCalls([1, 2, 3], [4, 5, 5], [6, 7, 8], [])
61  );
62  $data = [];
63  foreach ($this->_model as $key => $value) {
64  $data[$key] = $value;
65  }
66  $this->assertSame(
67  [
68  ['key1' => 1, 'key2' => 2, 'key3' => 3],
69  ['key1' => 4, 'key2' => 5, 'key3' => 5],
70  ['key1' => 6, 'key2' => 7, 'key3' => 8],
71  ],
72  $data
73  );
74  $this->_model->current();
75  }
76 
77  public function testSeekableInterface()
78  {
79  $this->assertSame(-1, $this->_model->key());
80  $this->_model->seek(-1);
81  $this->assertSame(-1, $this->_model->key());
82 
83  $this->_model->expects(
84  $this->any()
85  )->method(
86  '_getNextRow'
87  )->will(
88  $this->onConsecutiveCalls([1, 2, 3], [4, 5, 5], [6, 7, 8], [1, 2, 3], [4, 5, 5])
89  );
90  $this->_model->seek(2);
91  $this->assertSame(['key1' => 6, 'key2' => 7, 'key3' => 8], $this->_model->current());
92  $this->_model->seek(1);
93  $this->assertSame(['key1' => 4, 'key2' => 5, 'key3' => 5], $this->_model->current());
94  }
95 
100  {
101  $this->_model->seek(0);
102  }
103 }
$value
Definition: gender.phtml:16