Skip to content

Commit c0b4c7a

Browse files
committed
Implementing code review requested changes
1 parent 49bcf98 commit c0b4c7a

File tree

8 files changed

+52
-26
lines changed

8 files changed

+52
-26
lines changed

app/code/Magento/Rss/Model/Rss.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Magento\Framework\App\ObjectManager;
99
use Magento\Framework\App\Rss\DataProviderInterface;
1010
use Magento\Framework\Serialize\SerializerInterface;
11-
use Magento\Framework\App\FeedImporterInterface;
11+
use Magento\Framework\App\FeedFactoryInterface;
1212

1313
class Rss
1414
{
@@ -23,9 +23,9 @@ class Rss
2323
protected $cache;
2424

2525
/**
26-
* @var \Magento\Framework\App\FeedImporterInterface
26+
* @var \Magento\Framework\App\FeedFactoryInterface
2727
*/
28-
private $feedImporter;
28+
private $feedFactory;
2929

3030
/**
3131
* @var SerializerInterface
@@ -37,16 +37,16 @@ class Rss
3737
*
3838
* @param \Magento\Framework\App\CacheInterface $cache
3939
* @param SerializerInterface|null $serializer
40-
* @param FeedImporterInterface|null $feedImporter
40+
* @param FeedFactoryInterface|null $feedFactory
4141
*/
4242
public function __construct(
4343
\Magento\Framework\App\CacheInterface $cache,
4444
SerializerInterface $serializer = null,
45-
FeedImporterInterface $feedImporter = null
45+
FeedFactoryInterface $feedFactory = null
4646
) {
4747
$this->cache = $cache;
4848
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
49-
$this->feedImporter = $feedImporter ?: ObjectManager::getInstance()->get(FeedImporterInterface::class);
49+
$this->feedFactory = $feedFactory ?: ObjectManager::getInstance()->get(FeedFactoryInterface::class);
5050
}
5151

5252
/**
@@ -95,7 +95,13 @@ public function setDataProvider(DataProviderInterface $dataProvider)
9595
*/
9696
public function createRssXml()
9797
{
98-
$rssFeed = $this->feedImporter->importArray($this->getFeeds(), 'rss');
99-
return $rssFeed->asXML();
98+
$feed = $this->feedFactory->importArray(
99+
$this->getFeeds(),
100+
\Magento\Framework\App\FeedFormatsInterface::DEFAULT_FORMAT
101+
);
102+
103+
return $feed->getFormatedContentAs(
104+
\Magento\Framework\App\FeedOutputFormatsInterface::DEFAULT_FORMAT
105+
);
100106
}
101107
}

app/code/Magento/Rss/Test/Unit/Model/RssTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class RssTest extends \PHPUnit_Framework_TestCase
6565
private $cacheMock;
6666

6767
/**
68-
* @var \Magento\Framework\App\FeedImporterInterface|\PHPUnit_Framework_MockObject_MockObject
68+
* @var \Magento\Framework\App\FeedFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
6969
*/
70-
private $feedImporterMock;
70+
private $feedFactoryMock;
7171

7272
/**
7373
* @var \Magento\Framework\App\FeedInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -83,15 +83,15 @@ protected function setUp()
8383
{
8484
$this->cacheMock = $this->getMock(\Magento\Framework\App\CacheInterface::class);
8585
$this->serializerMock = $this->getMock(SerializerInterface::class);
86-
$this->feedImporterMock = $this->getMock(\Magento\Framework\App\FeedImporterInterface::class);
86+
$this->feedFactoryMock = $this->getMock(\Magento\Framework\App\FeedFactoryInterface::class);
8787
$this->feedMock = $this->getMock(\Magento\Framework\App\FeedInterface::class);
8888

8989
$this->objectManagerHelper = new ObjectManagerHelper($this);
9090
$this->rss = $this->objectManagerHelper->getObject(
9191
\Magento\Rss\Model\Rss::class,
9292
[
9393
'cache' => $this->cacheMock,
94-
'feedImporter' => $this->feedImporterMock,
94+
'feedFactory' => $this->feedFactoryMock,
9595
'serializer' => $this->serializerMock
9696
]
9797
);
@@ -152,12 +152,13 @@ public function testCreateRssXml()
152152
$dataProvider->expects($this->any())->method('getRssData')->will($this->returnValue($this->feedData));
153153

154154
$this->feedMock->expects($this->once())
155-
->method('asXml')
155+
->method('getFormatedContentAs')
156+
->with(\Magento\Framework\App\FeedOutputFormatsInterface::DEFAULT_FORMAT)
156157
->will($this->returnValue($this->feedXml));
157158

158-
$this->feedImporterMock->expects($this->once())
159+
$this->feedFactoryMock->expects($this->once())
159160
->method('importArray')
160-
->with($this->feedData)
161+
->with($this->feedData, \Magento\Framework\App\FeedFormatsInterface::DEFAULT_FORMAT)
161162
->will($this->returnValue($this->feedMock));
162163

163164
$this->rss->setDataProvider($dataProvider);

app/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
<preference for="Magento\Framework\View\Page\FaviconInterface" type="Magento\Theme\Model\Favicon\Favicon" />
172172
<preference for="Magento\Framework\View\Element\Message\InterpretationStrategyInterface" type="Magento\Framework\View\Element\Message\InterpretationMediator" />
173173
<preference for="Magento\Framework\App\FeedInterface" type="Magento\Framework\App\Feed" />
174-
<preference for="Magento\Framework\App\FeedImporterInterface" type="Magento\Framework\App\Feed\Importer" />
174+
<preference for="Magento\Framework\App\FeedFactoryInterface" type="Magento\Framework\App\FeedFactory" />
175175
<type name="Magento\Framework\Model\ResourceModel\Db\TransactionManager" shared="false" />
176176
<type name="Magento\Framework\Acl\Data\Cache">
177177
<arguments>

lib/internal/Magento/Framework/App/Feed.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Feed implements \Magento\Framework\App\FeedInterface
99
{
1010
/**
11-
* @var \Magento\Framework\App\FeedImporterInterface
11+
* @var \Zend_Feed_Abstract
1212
*/
1313
private $feed;
1414

@@ -25,8 +25,15 @@ public function __construct(\Zend_Feed_Abstract $feed)
2525
*
2626
* @return string
2727
*/
28-
public function asXml()
29-
{
30-
return $this->feed->saveXml();
28+
public function getFormatedContentAs(
29+
$format = FeedOutputFormatsInterface::DEFAULT_FORMAT
30+
) {
31+
if ($format === FeedOutputFormatsInterface::DEFAULT_FORMAT) {
32+
return $this->feed->saveXml();
33+
}
34+
throw new \Magento\Framework\Exception\RuntimeException(
35+
__('Given feed format is not supported'),
36+
$e
37+
);
3138
}
3239
}

lib/internal/Magento/Framework/App/FeedFactory.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use Psr\Log\LoggerInterface;
1010

1111
/**
12-
* Feed importer
12+
* Feed factory
1313
*/
14-
class FeedFactory implements \Magento\Framework\App\FeedImporterInterface
14+
class FeedFactory implements \Magento\Framework\App\FeedFactoryInterface
1515
{
1616
/**
1717
* @var \Zend_Feed
@@ -43,9 +43,8 @@ public function __construct(
4343
* @param string $format
4444
* @return \Magento\Framework\App\FeedInterface
4545
*/
46-
public function importArray(array $data, $format = 'atom')
46+
public function importArray(array $data, $format = FeedFormatsInterface::DEFAULT_FORMAT)
4747
{
48-
4948
try {
5049
return $this->feedProcessor->importArray($data, $format);
5150
} catch (\Zend_Feed_Exception $e) {

lib/internal/Magento/Framework/App/FeedFormatsInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
interface FeedFormatsInterface
99
{
10-
const DEFAULT_FORMAT = 'atom';
10+
const DEFAULT_FORMAT = 'rss';
1111
}

lib/internal/Magento/Framework/App/FeedInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ interface FeedInterface
1010
/**
1111
* @return string
1212
*/
13-
public function asXml();
13+
public function getFormatedContentAs(
14+
$format = FeedOutputFormatsInterface::DEFAULT_FORMAT
15+
);
1416
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\App;
7+
8+
interface FeedOutputFormatsInterface
9+
{
10+
const DEFAULT_FORMAT = 'xml';
11+
}

0 commit comments

Comments
 (0)