-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathCompositeFileIteratorTest.php
73 lines (64 loc) · 2.11 KB
/
CompositeFileIteratorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?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()));
}
}