Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IteratorFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class IteratorFactoryTest extends \PHPUnit\Framework\TestCase
12 {
16  private $objectManagerMock;
17 
21  private $iteratorIteratorMock;
22 
26  private $iteratorFactory;
27 
31  protected function setUp()
32  {
33  $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
34  ->disableOriginalConstructor()
35  ->getMock();
36 
37  $this->iteratorIteratorMock = $this->getMockBuilder(\IteratorIterator::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40 
41  $this->iteratorFactory = new IteratorFactory(
42  $this->objectManagerMock
43  );
44  }
45 
46  public function testCreate()
47  {
48  $arrayObject = new \ArrayIterator([1, 2, 3, 4, 5]);
49  $this->objectManagerMock->expects($this->once())
50  ->method('create')
51  ->with(\IteratorIterator::class, ['iterator' => $arrayObject])
52  ->willReturn($this->iteratorIteratorMock);
53 
54  $this->assertEquals($this->iteratorFactory->create($arrayObject), $this->iteratorIteratorMock);
55  }
56 }