From 1f079b855470f84925f679df204ffadd932d4c2f Mon Sep 17 00:00:00 2001 From: Vadim Justus <v.justus@techdivision.com> Date: Tue, 2 Apr 2019 23:59:59 +0200 Subject: [PATCH] #22 Reproduce issue in integration test --- Model/Config/Parser/ParserChain.php | 6 +- .../Parser/Query/FetchMediaFilesChainTest.php | 66 +++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 Test/Integration/Model/Config/Parser/Query/FetchMediaFilesChainTest.php diff --git a/Model/Config/Parser/ParserChain.php b/Model/Config/Parser/ParserChain.php index 5eb6980..eefbbe8 100644 --- a/Model/Config/Parser/ParserChain.php +++ b/Model/Config/Parser/ParserChain.php @@ -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); } } diff --git a/Test/Integration/Model/Config/Parser/Query/FetchMediaFilesChainTest.php b/Test/Integration/Model/Config/Parser/Query/FetchMediaFilesChainTest.php new file mode 100644 index 0000000..7688e15 --- /dev/null +++ b/Test/Integration/Model/Config/Parser/Query/FetchMediaFilesChainTest.php @@ -0,0 +1,66 @@ +<?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); + } +} -- GitLab