Skip to content

Commit 7ea0611

Browse files
author
Stanislav Idolov
committed
MAGETWO-70886: Zend feed refactoring #9347
1 parent 0be90a9 commit 7ea0611

File tree

8 files changed

+30
-68
lines changed

8 files changed

+30
-68
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +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\FeedInterface;
1211
use Magento\Framework\App\FeedFactoryInterface;
13-
use Zend\Feed\Writer\FeedFactory;
1412

1513
/**
1614
* Provides functionality to work with RSS feeds
@@ -100,10 +98,12 @@ public function setDataProvider(DataProviderInterface $dataProvider)
10098

10199
/**
102100
* @return string
101+
* @throws \Magento\Framework\Exception\InputException
102+
* @throws \Magento\Framework\Exception\RuntimeException
103103
*/
104104
public function createRssXml()
105105
{
106-
$feed = FeedFactory::factory($this->getFeeds());
107-
return $feed->export('rss');
106+
$feed = $this->feedFactory->create($this->getFeeds(), FeedFactoryInterface::FORMAT_RSS);
107+
return $feed->getFormattedContent();
108108
}
109109
}

app/code/Magento/Rss/Test/Unit/Controller/Adminhtml/Feed/IndexTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testExecuteWithException()
119119
$this->rssFactory->expects($this->once())->method('create')->will($this->returnValue($rssModel));
120120
$this->rssManager->expects($this->once())->method('getProvider')->will($this->returnValue($dataProvider));
121121

122-
$this->expectException(InvalidArgumentException::class);
122+
$this->expectException(\Magento\Framework\Exception\RuntimeException::class);
123123
$this->controller->execute();
124124
}
125125
}

app/code/Magento/Rss/Test/Unit/Controller/Feed/IndexTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function testExecuteWithException()
107107
$this->rssFactory->expects($this->once())->method('create')->will($this->returnValue($rssModel));
108108
$this->rssManager->expects($this->once())->method('getProvider')->will($this->returnValue($dataProvider));
109109

110-
$this->expectException(InvalidArgumentException::class);
110+
$this->expectException(\Magento\Framework\Exception\RuntimeException::class);
111111
$this->controller->execute();
112112
}
113113
}

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,15 @@ public function testCreateRssXml()
152152
$dataProvider->expects($this->any())->method('getRssData')->will($this->returnValue($this->feedData));
153153

154154
$this->feedMock->expects($this->once())
155-
->method('getFormattedContentAs')
156-
->with(\Magento\Framework\App\FeedInterface::FORMAT_XML)
157-
->will($this->returnValue($this->feedXml));
155+
->method('getFormattedContent')
156+
->willReturn($this->feedXml);
158157

159158
$this->feedFactoryMock->expects($this->once())
160159
->method('create')
161160
->with($this->feedData, \Magento\Framework\App\FeedFactoryInterface::FORMAT_RSS)
162161
->will($this->returnValue($this->feedMock));
163162

164163
$this->rss->setDataProvider($dataProvider);
165-
$result = $this->rss->createRssXml();
166-
$this->assertContains('<?xml version="1.0" encoding="UTF-8"?>', $result);
167-
$this->assertContains('<title>Feed Title</title>', $result);
168-
$this->assertContains('<title>Feed 1 Title</title>', $result);
169-
$this->assertContains('<link>http://magento.com/rss/link</link>', $result);
170-
$this->assertContains('<link>http://magento.com/rss/link/id/1</link>', $result);
171-
$this->assertContains('<description>Feed Description</description>', $result);
172-
$this->assertContains('<description><![CDATA[Feed 1 Description]]></description>', $result);
164+
$this->assertNotNull($this->rss->createRssXml());
173165
}
174166
}

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

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,32 @@
55
*/
66
namespace Magento\Framework\App;
77

8+
use Zend\Feed\Writer\FeedFactory;
9+
810
/**
911
* Default XML feed class
1012
*/
1113
class Feed implements FeedInterface
1214
{
13-
/**
14-
* @var \Zend_Feed
15-
*/
16-
private $feedProcessor;
17-
1815
/**
1916
* @var array
2017
*/
21-
private $data;
18+
private $feeds;
2219

2320
/**
24-
* @param Zend_Feed $feedProcessor
25-
* @param array $data
21+
* Feed constructor.
22+
* @param array $feeds
2623
*/
27-
public function __construct(
28-
\Zend_Feed $feedProcessor,
29-
array $data
30-
) {
31-
$this->feedProcessor = $feedProcessor;
32-
$this->data = $data;
24+
public function __construct(array $feeds)
25+
{
26+
$this->feeds = $feeds;
3327
}
3428

3529
/**
36-
* Returns the formatted feed content
37-
*
38-
* @param string $format
39-
*
40-
* @return string
30+
* {@inheritdoc}
4131
*/
42-
public function getFormattedContentAs(
43-
$format = self::FORMAT_XML
44-
) {
45-
$feed = $this->feedProcessor::importArray(
46-
$this->data,
47-
FeedFactoryInterface::FORMAT_RSS
48-
);
49-
return $feed->saveXml();
32+
public function getFormattedContent() : string
33+
{
34+
return FeedFactory::factory($this->feeds)->export(FeedFactoryInterface::FORMAT_RSS);
5035
}
5136
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Framework\App;
77

8-
use Magento\Framework\App\FeedFactoryInterface;
98
use Magento\Framework\ObjectManagerInterface;
109
use Psr\Log\LoggerInterface;
1110

@@ -47,21 +46,17 @@ public function __construct(
4746
/**
4847
* {@inheritdoc}
4948
*/
50-
public function create(
51-
array $data,
52-
$format = FeedFactoryInterface::FORMAT_RSS
53-
) {
49+
public function create(array $data, $format = FeedFactoryInterface::FORMAT_RSS) : FeedInterface
50+
{
5451
if (!isset($this->formats[$format])) {
5552
throw new \Magento\Framework\Exception\InputException(
56-
new \Magento\Framework\Phrase('The format is not supported'),
57-
$e
53+
new \Magento\Framework\Phrase('The format is not supported')
5854
);
5955
}
6056

6157
if (!is_subclass_of($this->formats[$format], \Magento\Framework\App\FeedInterface::class)) {
6258
throw new \Magento\Framework\Exception\InputException(
63-
new \Magento\Framework\Phrase('Wrong format handler type'),
64-
$e
59+
new \Magento\Framework\Phrase('Wrong format handler type')
6560
);
6661
}
6762

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ interface FeedFactoryInterface
2020
*
2121
* @throws \Magento\Framework\Exception\InputException
2222
* @throws \Magento\Framework\Exception\RuntimeException
23-
* @param array $data
24-
* @param string $format
23+
* @param array $data
24+
* @param string $format
2525
* @return FeedInterface
2626
*/
27-
public function create(
28-
array $data,
29-
$format = self::FORMAT_RSS
30-
);
27+
public function create(array $data, $format = self::FORMAT_RSS) : FeedInterface;
3128
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,9 @@
1111
interface FeedInterface
1212
{
1313
/**
14-
* XML feed output format
15-
*/
16-
const FORMAT_XML = 'xml';
17-
18-
/**
19-
* @param string $format
14+
* Returns the formatted feed content
2015
*
2116
* @return string
2217
*/
23-
public function getFormattedContentAs(
24-
$format = self::FORMAT_XML
25-
);
18+
public function getFormattedContent() : string;
2619
}

0 commit comments

Comments
 (0)