Skip to content
Snippets Groups Projects
Unverified Commit 0502e99f authored by Vadim Justus's avatar Vadim Justus Committed by GitHub
Browse files

Merge pull request #23 from vadimjustus/22-media-files-merging

Reproducing issue #22 with tests
parents 26647476 1f079b85
No related branches found
No related tags found
No related merge requests found
......@@ -39,9 +39,11 @@ class ParserChain implements ConfigParserInterface
public function execute(DOMElement $element): array
{
$data = [];
foreach ($this->parser as $parser) {
$data = array_merge($data, $parser->execute($element));
$data[] = $parser->execute($element);
}
return $data;
return array_merge(...$data);
}
}
......@@ -169,3 +169,7 @@ Feel free to add your ideas there.
## Changelog
See [changelog file](CHANGELOG.md)
## Extensions for this extension ;)
For [`magenerds/pagedesigner`](https://github.com/Magenerds/PageDesigner) there is an module, which extends this content
provisioning module: [`techdivision/pagedesigner-content-provisioning`](https://github.com/techdivision/pagedesigner-content-provisioning).
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Test\Integration\Model\Config\Parser\Query;
use Firegento\ContentProvisioning\Api\MediaFilesParserInterface;
use Firegento\ContentProvisioning\Model\Config\Parser\Query\FetchMediaFilesChain;
use PHPUnit\Framework\MockObject\MockObject;
class FetchMediaFilesChainTest extends \PHPUnit\Framework\TestCase
{
/**
* @var FetchMediaFilesChain
*/
private $chain;
/**
* @var MediaFilesParserInterface|MockObject
*/
private $parser1;
/**
* @var MediaFilesParserInterface|MockObject
*/
private $parser2;
protected function setUp()
{
$this->parser1 = self::getMockBuilder(MediaFilesParserInterface::class)
->disableOriginalConstructor()
->getMock();
$this->parser2 = self::getMockBuilder(MediaFilesParserInterface::class)
->disableOriginalConstructor()
->getMock();
$this->chain = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(FetchMediaFilesChain::class, ['parsers' => [
$this->parser1,
$this->parser2,
]]);
}
public function testMergingData()
{
$this->parser1->method('execute')->willReturn([
'path/to/file1.png',
'path/to/file2.png',
'file3.png',
]);
$this->parser2->method('execute')->willReturn([
'file3.png',
'some/other/path.jpg',
]);
$result = $this->chain->execute('');
$this->assertSame([
'path/to/file1.png',
'path/to/file2.png',
'file3.png',
'file3.png',
'some/other/path.jpg',
], $result);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment