-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from kesselb/enh/read-lastmodified-from-response
Read last modified value from response
- Loading branch information
Showing
12 changed files
with
184 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the feed-io package. | ||
* | ||
* (c) Alexandre Debril <alex.debril@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FeedIo\Reader\Fixer; | ||
|
||
use FeedIo\Reader\FixerAbstract; | ||
use FeedIo\Reader\Result; | ||
|
||
class HttpLastModified extends FixerAbstract | ||
{ | ||
|
||
/** | ||
* @param Result $result | ||
* @return FixerAbstract | ||
*/ | ||
public function correct(Result $result): FixerAbstract | ||
{ | ||
$feed = $result->getFeed(); | ||
$response = $result->getResponse(); | ||
|
||
if ($feed->getLastModified() === null && $response->getLastModified() instanceof \DateTime) { | ||
$this->logger->debug("found last modified: " . $response->getLastModified()->format(\DateTime::RSS)); | ||
$feed->setLastModified($response->getLastModified()); | ||
} | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/* | ||
* This file is part of the feed-io package. | ||
* | ||
* (c) Alexandre Debril <alex.debril@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FeedIo\Reader\Fixer; | ||
|
||
use FeedIo\Reader\ResultMockFactory; | ||
use Psr\Log\NullLogger; | ||
|
||
use \PHPUnit\Framework\TestCase; | ||
|
||
class HttpLastModifiedTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var HttpLastModified | ||
*/ | ||
protected $object; | ||
|
||
/** | ||
* @var ResultMockFactory | ||
*/ | ||
protected $resultMockFactory; | ||
|
||
protected function setUp() | ||
{ | ||
$this->object = new HttpLastModified(); | ||
$this->object->setLogger(new NullLogger()); | ||
$this->resultMockFactory = new ResultMockFactory(); | ||
} | ||
|
||
public function testCorrect() | ||
{ | ||
$result = $this->resultMockFactory->make(); | ||
$feed = $result->getFeed(); | ||
|
||
$this->assertNull($feed->getLastModified()); | ||
$this->object->correct($result); | ||
|
||
$this->assertEquals(new \DateTime('@0'), $feed->getLastModified()); | ||
} | ||
|
||
public function testSkipCorrectIfLastModifiedNotNull() | ||
{ | ||
$result = $this->resultMockFactory->make(); | ||
$feed = $result->getFeed(); | ||
$feed->setLastModified(new \DateTime('@3')); | ||
|
||
$this->assertNotNull($feed->getLastModified()); | ||
$this->object->correct($result); | ||
|
||
$this->assertEquals(new \DateTime('@3'), $feed->getLastModified()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/* | ||
* This file is part of the feed-io package. | ||
* | ||
* (c) Alexandre Debril <alex.debril@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FeedIo\Reader; | ||
|
||
use FeedIo\Adapter\NullResponse; | ||
use FeedIo\Adapter\ResponseInterface; | ||
use FeedIo\Feed; | ||
|
||
class ResultMockFactory | ||
{ | ||
public function make(): Result | ||
{ | ||
return $this->makeWithFeed(new Feed()); | ||
} | ||
|
||
public function makeWithFeed(Feed $feed): Result | ||
{ | ||
/** @var Document $document */ | ||
$document = new Document(''); | ||
/** @var ResponseInterface $response */ | ||
$response = new NullResponse(); | ||
|
||
return new Result($document, $feed, new \DateTime('@0'), $response, 'http://localhost/test.rss'); | ||
} | ||
} |