-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* install Pest * refactor `AlternateTest` * refactor `CrawlProfileTest` * refactor `ImageTest` * refactor `SitemapGeneratorTest` * refactor `SitemapIndexTest` * refactor `SitemapTest` * refactor `UrlTest` * change test suit to Pest in `composer.json` * cleanup * change test suit in Github actions * refactor `temporaryDirectory` method * refactor helper functions * cleanup
- Loading branch information
1 parent
c93c535
commit 648f713
Showing
17 changed files
with
668 additions
and
714 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
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 |
---|---|---|
@@ -1,33 +1,19 @@ | ||
<?php | ||
|
||
namespace Spatie\Sitemap\Test; | ||
|
||
use Spatie\Sitemap\Tags\Alternate; | ||
|
||
class AlternateTest extends TestCase | ||
{ | ||
protected Alternate $alternate; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->alternate = new Alternate('defaultUrl', 'en'); | ||
} | ||
beforeEach(function () { | ||
$this->alternate = new Alternate('defaultUrl', 'en'); | ||
}); | ||
|
||
/** @test */ | ||
public function url_can_be_set() | ||
{ | ||
$this->alternate->setUrl('testUrl'); | ||
test('url can be set', function () { | ||
$this->alternate->setUrl('testUrl'); | ||
|
||
$this->assertEquals('testUrl', $this->alternate->url); | ||
} | ||
expect($this->alternate->url)->toEqual('testUrl'); | ||
}); | ||
|
||
/** @test */ | ||
public function locale_can_be_set() | ||
{ | ||
$this->alternate->setLocale('en'); | ||
test('locale can be set', function () { | ||
$this->alternate->setLocale('en'); | ||
|
||
$this->assertEquals('en', $this->alternate->locale); | ||
} | ||
} | ||
expect($this->alternate->locale)->toEqual('en'); | ||
}); |
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 |
---|---|---|
@@ -1,94 +1,74 @@ | ||
<?php | ||
|
||
namespace Spatie\Sitemap\Test; | ||
|
||
use Spatie\Crawler\Crawler; | ||
use Spatie\Crawler\CrawlProfiles\CrawlInternalUrls; | ||
use Spatie\Crawler\CrawlProfiles\CrawlSubdomains; | ||
use Spatie\Sitemap\Crawler\Profile; | ||
use Spatie\Sitemap\Sitemap; | ||
use Spatie\Sitemap\SitemapGenerator; | ||
use Spatie\Sitemap\Test\CustomCrawlProfile; | ||
|
||
class CrawlProfileTest extends TestCase | ||
{ | ||
/** | ||
* @var Crawler | ||
*/ | ||
protected $crawler; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->crawler = $this->createMock(Crawler::class); | ||
beforeEach(function () { | ||
$this->crawler = $this->createMock(Crawler::class); | ||
|
||
$this->crawler->method('setCrawlObserver')->willReturn($this->crawler); | ||
$this->crawler->method('setConcurrency')->willReturn($this->crawler); | ||
} | ||
$this->crawler->method('setCrawlObserver')->willReturn($this->crawler); | ||
$this->crawler->method('setConcurrency')->willReturn($this->crawler); | ||
}); | ||
|
||
/** @test */ | ||
public function it_can_use_the_default_profile() | ||
{ | ||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(Profile::class)) | ||
->willReturn($this->crawler); | ||
it('can use default profile', function () { | ||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(Profile::class)) | ||
->willReturn($this->crawler); | ||
|
||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
|
||
$sitemap = $sitemapGenerator->setUrl('')->getSitemap(); | ||
$sitemap = $sitemapGenerator->setUrl('')->getSitemap(); | ||
|
||
$this->assertInstanceOf(Sitemap::class, $sitemap); | ||
} | ||
expect($sitemap)->toBeInstanceOf(Sitemap::class); | ||
}); | ||
|
||
/** @test */ | ||
public function it_can_use_the_custom_profile() | ||
{ | ||
config(['sitemap.crawl_profile' => CustomCrawlProfile::class]); | ||
it('can use the custom profile', function () { | ||
config(['sitemap.crawl_profile' => CustomCrawlProfile::class]); | ||
|
||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(CustomCrawlProfile::class)) | ||
->willReturn($this->crawler); | ||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(CustomCrawlProfile::class)) | ||
->willReturn($this->crawler); | ||
|
||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
|
||
$sitemap = $sitemapGenerator->setUrl('')->getSitemap(); | ||
$sitemap = $sitemapGenerator->setUrl('')->getSitemap(); | ||
|
||
$this->assertInstanceOf(Sitemap::class, $sitemap); | ||
} | ||
expect($sitemap)->toBeInstanceOf(Sitemap::class); | ||
}); | ||
|
||
/** @test */ | ||
public function it_can_use_the_subdomain_profile() | ||
{ | ||
config(['sitemap.crawl_profile' => CrawlSubdomains::class]); | ||
it('can use the subdomain profile', function () { | ||
config(['sitemap.crawl_profile' => CrawlSubdomains::class]); | ||
|
||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(CrawlSubdomains::class)) | ||
->willReturn($this->crawler); | ||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(CrawlSubdomains::class)) | ||
->willReturn($this->crawler); | ||
|
||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
|
||
$sitemap = $sitemapGenerator->setUrl('')->getSitemap(); | ||
$sitemap = $sitemapGenerator->setUrl('')->getSitemap(); | ||
|
||
$this->assertInstanceOf(Sitemap::class, $sitemap); | ||
} | ||
expect($sitemap)->toBeInstanceOf(Sitemap::class); | ||
}); | ||
|
||
/** @test */ | ||
public function it_can_use_the_internal_profile() | ||
{ | ||
config(['sitemap.crawl_profile' => CrawlInternalUrls::class]); | ||
it('can use the internal profile', function () { | ||
config(['sitemap.crawl_profile' => CrawlInternalUrls::class]); | ||
|
||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(CrawlInternalUrls::class)) | ||
->willReturn($this->crawler); | ||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(CrawlInternalUrls::class)) | ||
->willReturn($this->crawler); | ||
|
||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
|
||
$sitemap = $sitemapGenerator->setUrl('')->getSitemap(); | ||
$sitemap = $sitemapGenerator->setUrl('')->getSitemap(); | ||
|
||
$this->assertInstanceOf(Sitemap::class, $sitemap); | ||
} | ||
} | ||
expect($sitemap)->toBeInstanceOf(Sitemap::class); | ||
}); |
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,63 @@ | ||
<?php | ||
|
||
use Carbon\Carbon; | ||
use Spatie\TemporaryDirectory\TemporaryDirectory; | ||
use function PHPUnit\Framework\assertXmlStringEqualsXmlString; | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
uses(\Spatie\Sitemap\Test\TestCase::class) | ||
->beforeEach(function () { | ||
$this->now = Carbon::create('2016', '1', '1', '0', '0', '0'); | ||
|
||
Carbon::setTestNow($this->now); | ||
}) | ||
->in('.'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Expectations | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
expect()->extend('toEqualXmlString', function (string $expected_xml) { | ||
/** @var string */ | ||
$value = $this->value; | ||
|
||
assertXmlStringEqualsXmlString($value, $expected_xml); | ||
|
||
return $this; | ||
}); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Functions | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
function checkIfTestServerIsRunning(): void | ||
{ | ||
try { | ||
file_get_contents('http://localhost:4020'); | ||
} catch (Throwable $e) { | ||
handleTestServerNotRunning(); | ||
} | ||
} | ||
|
||
function handleTestServerNotRunning(): void | ||
{ | ||
if (getenv('TRAVIS')) { | ||
test()->fail('The test server is not running on Travis.'); | ||
} | ||
|
||
test()->markTestSkipped('The test server is not running.'); | ||
} | ||
|
||
function temporaryDirectory(): TemporaryDirectory | ||
{ | ||
return (new TemporaryDirectory())->force()->create(); | ||
} |
Oops, something went wrong.