Skip to content

Commit

Permalink
Add factory for ResultMock
Browse files Browse the repository at this point in the history
  • Loading branch information
kesselb committed Jan 8, 2020
1 parent 34ed799 commit de2b081
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 71 deletions.
28 changes: 9 additions & 19 deletions tests/FeedIo/Reader/Fixer/HttpLastModifiedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

namespace FeedIo\Reader\Fixer;

use FeedIo\Adapter\NullResponse;
use FeedIo\Adapter\ResponseInterface;
use FeedIo\Feed;
use FeedIo\Reader\Document;
use FeedIo\Reader\Result;
use FeedIo\Reader\ResultMockFactory;
use Psr\Log\NullLogger;

use \PHPUnit\Framework\TestCase;
Expand All @@ -27,15 +23,21 @@ class HttpLastModifiedTest extends TestCase
*/
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->getResultMock();
$result = $this->resultMockFactory->make();
$feed = $result->getFeed();

$this->assertNull($feed->getLastModified());
Expand All @@ -46,7 +48,7 @@ public function testCorrect()

public function testSkipCorrectIfLastModifiedNotNull()
{
$result = $this->getResultMock();
$result = $this->resultMockFactory->make();
$feed = $result->getFeed();
$feed->setLastModified(new \DateTime('@3'));

Expand All @@ -55,16 +57,4 @@ public function testSkipCorrectIfLastModifiedNotNull()

$this->assertEquals(new \DateTime('@3'), $feed->getLastModified());
}

protected function getResultMock(): Result
{
/** @var Document $document */
$document = $this->createMock(Document::class);
/** @var Feed $feed */
$feed = new Feed();
/** @var ResponseInterface $response */
$response = new NullResponse();

return new Result($document, $feed, new \DateTime('@0'), $response, 'http://localhost/test.rss');
}
}
26 changes: 8 additions & 18 deletions tests/FeedIo/Reader/Fixer/LastModifiedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@

namespace FeedIo\Reader\Fixer;

use FeedIo\Adapter\NullResponse;
use FeedIo\Adapter\ResponseInterface;
use FeedIo\Feed;
use FeedIo\Feed\Item;
use FeedIo\Reader\Document;
use FeedIo\Reader\Result;
use FeedIo\Reader\ResultMockFactory;
use Psr\Log\NullLogger;

use \PHPUnit\Framework\TestCase;
Expand All @@ -33,12 +30,17 @@ class LastModifiedTest extends TestCase
*/
protected $newest;

/**
* @var ResultMockFactory
*/
protected $resultMockFactory;

protected function setUp()
{
$this->newest = new \DateTime('2014-01-01');

$this->object = new LastModified();
$this->object->setLogger(new NullLogger());
$this->resultMockFactory = new ResultMockFactory();
}

public function testSearchLastModified()
Expand All @@ -53,7 +55,7 @@ public function testSearchLastModified()

public function testCorrect()
{
$result = $this->getResultMock();
$result = $this->resultMockFactory->makeWithFeed($this->getFeed());
$feed = $result->getFeed();

$this->assertNull($feed->getLastModified());
Expand All @@ -75,16 +77,4 @@ protected function getFeed()

return $feed;
}

protected function getResultMock(): Result
{
/** @var Document $document */
$document = $this->createMock(Document::class);
/** @var Feed $feed */
$feed = $this->getFeed();
/** @var ResponseInterface $response */
$response = new NullResponse();

return new Result($document, $feed, new \DateTime('@0'), $response, 'http://localhost/test.rss');
}
}
25 changes: 8 additions & 17 deletions tests/FeedIo/Reader/Fixer/PublicIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@

namespace FeedIo\Reader\Fixer;

use FeedIo\Adapter\NullResponse;
use FeedIo\Adapter\ResponseInterface;
use FeedIo\Feed;
use FeedIo\Feed\Item;
use FeedIo\Reader\Document;
use FeedIo\Reader\Result;
use FeedIo\Reader\ResultMockFactory;
use Psr\Log\NullLogger;

use \PHPUnit\Framework\TestCase;
Expand All @@ -28,15 +25,21 @@ class PublicIdTest extends TestCase
*/
protected $object;

/**
* @var ResultMockFactory
*/
protected $resultMockFactory;

protected function setUp()
{
$this->object = new PublicId();
$this->object->setLogger(new NullLogger());
$this->resultMockFactory = new ResultMockFactory();
}

public function testCorrect()
{
$result = $this->getResultMock();
$result = $this->resultMockFactory->makeWithFeed($this->getFeed());
$feed = $result->getFeed();

$this->assertNull($feed->getPublicId());
Expand Down Expand Up @@ -68,16 +71,4 @@ protected function getFeed()

return $feed;
}

protected function getResultMock(): Result
{
/** @var Document $document */
$document = $this->createMock(Document::class);
/** @var Feed $feed */
$feed = $this->getFeed();
/** @var ResponseInterface $response */
$response = new NullResponse();

return new Result($document, $feed, new \DateTime('@0'), $response, 'http://localhost/test.rss');
}
}
28 changes: 11 additions & 17 deletions tests/FeedIo/Reader/FixerSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,31 @@

namespace FeedIo\Reader;

use FeedIo\Adapter\NullResponse;
use FeedIo\Adapter\ResponseInterface;
use FeedIo\Feed;

use \PHPUnit\Framework\TestCase;

class FixerSetTest extends TestCase
{
/**
* @var ResultMockFactory
*/
protected $resultMockFactory;

protected function setUp()
{
$this->resultMockFactory = new ResultMockFactory();
}

public function testCorrect()
{
$fixer = new FixerMock();
$fixerSet = new FixerSet();
$fixerSet->add($fixer);

$result = $this->getResultMock();
$result = $this->resultMockFactory->make();
$feed = $result->getFeed();

$fixerSet->correct($result);

$this->assertEquals('corrected', $feed->getTitle());
}

protected function getResultMock(): Result
{
/** @var Document $document */
$document = $this->createMock(Document::class);
/** @var Feed $feed */
$feed = new Feed();
/** @var ResponseInterface $response */
$response = new NullResponse();

return new Result($document, $feed, new \DateTime('@0'), $response, 'http://localhost/test.rss');
}
}
33 changes: 33 additions & 0 deletions tests/FeedIo/Reader/ResultMockFactory.php
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');
}
}

0 comments on commit de2b081

Please sign in to comment.