Skip to content

Commit

Permalink
Remove Testable* classes from the Sitemap test
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Feb 28, 2016
1 parent 8880c32 commit 4e01703
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions tests/SitemapTest.php
Expand Up @@ -9,47 +9,31 @@
use SitemapGenerator\Provider\DefaultValues;
use SitemapGenerator\Sitemap;

class TestableSitemap extends Sitemap
{
public function testableAdd(Url $url)
{
$this->add($url, DefaultValues::none());
}

public function getProviders()
{
return $this->providers;
}

public function getDumper()
{
return $this->dumper;
}
}

class TestableProvider implements \IteratorAggregate
{
public function getIterator()
{
yield new Url('http://www.google.fr/search');
}
}

class SitemapTest extends \PHPUnit_Framework_TestCase
{
public function testAddProvider()
{
$sitemap = new TestableSitemap(new Dumper\Memory(), new Formatter\Text());
$sitemap = new class($this->getDumper(), $this->getFormatter()) extends Sitemap {
public function getProviders()
{
return $this->providers;
}
};
$this->assertSame(0, count($sitemap->getProviders()));

$sitemap->addProvider(new TestableProvider());
$sitemap->addProvider(new \ArrayIterator([]));
$this->assertSame(1, count($sitemap->getProviders()));
}

public function testRelativeUrlsAreKeptIntact()
{
$dumper = new Dumper\Memory();
$sitemap = new TestableSitemap($dumper, new Formatter\Text());
$sitemap = new class($dumper, new Formatter\Text()) extends Sitemap {
public function testableAdd(Url $url)
{
$this->add($url, DefaultValues::none());
}
};
$url = new Url('/search');

$sitemap->testableAdd($url);
Expand All @@ -60,8 +44,8 @@ public function testRelativeUrlsAreKeptIntact()

public function testAddWithDefaultValues()
{
$formatter = $this->getMock('SitemapGenerator\SitemapFormatter');
$sitemap = new TestableSitemap($this->getMock('SitemapGenerator\Dumper'), $formatter);
$formatter = $this->getFormatter();
$sitemap = new Sitemap($this->getDumper(), $formatter);
$defaultValues = DefaultValues::create(0.7, ChangeFrequency::ALWAYS);

$formatter
Expand All @@ -71,15 +55,25 @@ public function testAddWithDefaultValues()
return $url->getPriority() === 0.7 && $url->getChangefreq() === ChangeFrequency::ALWAYS;
}));

$sitemap->addProvider(new TestableProvider(), $defaultValues);
$sitemap->addProvider(new \ArrayIterator([new Url('http://www.google.fr/search')]), $defaultValues);
$sitemap->build();
}

public function testBuild()
{
$sitemap = new TestableSitemap(new Dumper\Memory(), new Formatter\Text(), 'http://www.google.fr');
$sitemap->addProvider(new TestableProvider());
$sitemap = new Sitemap(new Dumper\Memory(), new Formatter\Text(), 'http://www.google.fr');
$sitemap->addProvider(new \ArrayIterator([new Url('http://www.google.fr/search')]));

$this->assertSame('http://www.google.fr/search' . "\n", $sitemap->build());
}

protected function getDumper()
{
return $this->getMock('SitemapGenerator\Dumper');
}

protected function getFormatter()
{
return $this->getMock('SitemapGenerator\SitemapFormatter');
}
}

0 comments on commit 4e01703

Please sign in to comment.