Verified Commit 983c50d0 authored by Elias Häußler's avatar Elias Häußler 🐛
Browse files

Merge branch 'release/0.5.1'

parents 848f13e2 1cdbbbcb
......@@ -244,25 +244,28 @@ class CacheWarmupCommand extends Command
{
$crawler = $input->getOption('crawler');
// Use crawler specified by --crawler option
if (is_string($crawler)) {
// Use crawler specified by --crawler option
if (!class_exists($crawler)) {
throw new RuntimeException('The specified crawler class does not exist.', 1604261816);
}
if (!in_array(CrawlerInterface::class, class_implements($crawler) ?: [])) {
throw new RuntimeException('The specified crawler is not valid.', 1604261885);
}
return new $crawler();
}
if ($output->isVerbose() || $input->getOption('progress')) {
$crawler = new $crawler();
} elseif ($output->isVerbose() || $input->getOption('progress')) {
// Use default verbose crawler
$crawler = new OutputtingCrawler();
} else {
// Use default crawler
return new ConcurrentCrawler();
}
return $crawler->setOutput($output);
if ($crawler instanceof VerboseCrawlerInterface) {
$crawler->setOutput($output);
}
return new ConcurrentCrawler();
return $crawler;
}
protected function decorateSitemap(Sitemap $sitemap): string
......
......@@ -25,6 +25,7 @@ namespace EliasHaeussler\CacheWarmup\Tests\Unit\Command;
use EliasHaeussler\CacheWarmup\Command\CacheWarmupCommand;
use EliasHaeussler\CacheWarmup\Tests\Unit\Crawler\DummyCrawler;
use EliasHaeussler\CacheWarmup\Tests\Unit\Crawler\DummyVerboseCrawler;
use EliasHaeussler\CacheWarmup\Tests\Unit\RequestProphecyTrait;
use GuzzleHttp\Psr7\Uri;
use PHPUnit\Framework\TestCase;
......@@ -262,5 +263,29 @@ class CacheWarmupCommandTest extends TestCase
new Uri('https://www.example.com/foo'),
];
static::assertEquals($expected, DummyCrawler::$crawledUrls);
// Reset static variables
DummyCrawler::$crawledUrls = [];
}
/**
* @test
*
* @throws ClientExceptionInterface
*/
public function executeAppliesOutputToVerboseCrawler(): void
{
$this->prophesizeSitemapRequest('valid_sitemap_3');
$this->commandTester->execute([
'sitemaps' => [
'https://www.example.com/sitemap.xml',
],
'--crawler' => DummyVerboseCrawler::class,
]);
static::assertSame($this->commandTester->getOutput(), DummyVerboseCrawler::$output);
// Reset static variables
DummyVerboseCrawler::$output = null;
}
}
<?php
declare(strict_types=1);
namespace EliasHaeussler\CacheWarmup\Tests\Unit\Crawler;
/*
* This file is part of the Composer package "eliashaeussler/cache-warmup".
*
* Copyright (C) 2021 Elias Häußler <elias@haeussler.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use EliasHaeussler\CacheWarmup\Crawler\VerboseCrawlerInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* DummyVerboseCrawler.
*
* @author Elias Häußler <e.haeussler@familie-redlich.de>
* @license GPL-3.0-or-later
*/
class DummyVerboseCrawler extends DummyCrawler implements VerboseCrawlerInterface
{
/**
* @var OutputInterface|null
*/
public static $output;
public function setOutput(OutputInterface $output): VerboseCrawlerInterface
{
static::$output = $output;
return $this;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment