![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/framework/Config/Test/Unit/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Framework\Config\Test\Unit; use Magento\Framework\Config\CompositeFileIterator; use Magento\Framework\Config\FileIterator; use Magento\Framework\Filesystem\File\ReadFactory; use Magento\Framework\Filesystem\File\Read; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * Test composition of file iterators. */ class CompositeFileIteratorTest extends TestCase { /** * @var ReadFactory|MockObject */ private $readFactoryMock; /** * @inheritDoc */ protected function setUp(): void { parent::setUp(); $this->readFactoryMock = $this->createMock(ReadFactory::class); $this->readFactoryMock->method('create') ->willReturnCallback( function (string $file): Read { $readMock = $this->createMock(Read::class); $readMock->method('readAll')->willReturn('Content of ' .$file); return $readMock; } ); } /** * Test the composite. */ public function testComposition(): void { $existingFiles = [ '/etc/magento/somefile.ext', '/etc/magento/somefile2.ext', '/etc/magento/somefile3.ext' ]; $newFiles = [ '/etc/magento/some-other-file.ext', '/etc/magento/some-other-file2.ext' ]; $existing = new FileIterator($this->readFactoryMock, $existingFiles); $composite = new CompositeFileIterator($this->readFactoryMock, $newFiles, $existing); $found = []; foreach ($composite as $file => $content) { $this->assertNotEmpty($content); $found[] = $file; } $this->assertEquals(array_merge($existingFiles, $newFiles), $found); $this->assertEquals(count($existingFiles) + count($newFiles), $composite->count()); $this->assertEquals(array_merge($existingFiles, $newFiles), array_keys($composite->toArray())); } }