Skip to content

Commit

Permalink
Fix the coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Jan 3, 2020
1 parent 0494791 commit c25eeb8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function shouldRequest(CrawlUri $crawlUri): string
{
// Only check URIs that are part of our base collection or were found on one
$fromBaseUriCollection = $this->escargot->getBaseUris()->containsHost($crawlUri->getUri()->getHost());

$foundOnBaseUriCollection = null !== $crawlUri->getFoundOn()
&& ($originalCrawlUri = $this->escargot->getCrawlUri($crawlUri->getFoundOn()))
&& $this->escargot->getBaseUris()->containsHost($originalCrawlUri->getUri()->getHost());
Expand All @@ -53,7 +54,7 @@ public function shouldRequest(CrawlUri $crawlUri): string
$this->escargot->log(
LogLevel::DEBUG,
$crawlUri->createLogMessage('Did not check because it is not part of the base URI collection or was not found on one of that is.'),
['source' => \get_class($this)]
['source' => static::class]
);

return SubscriberInterface::DECISION_NEGATIVE;
Expand Down Expand Up @@ -129,11 +130,8 @@ private function logError(CrawlUri $crawlUri, string $message): void

$this->escargot->log(
LogLevel::ERROR,
$crawlUri->createLogMessage(sprintf(
'Broken link! %s.',
$message
)),
['source' => \get_class($this)]
$crawlUri->createLogMessage(sprintf('Broken link! %s.', $message)),
['source' => static::class]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
use Contao\CoreBundle\Routing\ScopeMatcher;
use Contao\CoreBundle\Routing\UrlGenerator;
use Contao\CoreBundle\Search\Escargot\Factory;
use Contao\CoreBundle\Search\Escargot\Subscriber\BrokenLinkCheckerSubscriber;
use Contao\CoreBundle\Search\Escargot\Subscriber\SearchIndexSubscriber;
use Contao\CoreBundle\Search\Indexer\IndexerInterface;
use Contao\CoreBundle\Security\Authentication\AuthenticationEntryPoint;
Expand Down Expand Up @@ -1580,7 +1581,22 @@ public function testRegistersTheSearchEscargotFactory(): void
$this->assertSame('contao.framework', (string) $definition->getArgument(1));
}

public function testRegistersTheSearchEscargotSubscriber(): void
public function testRegistersTheSearchEscargotBrokenLinkCheckerSubscriber(): void
{
$this->assertTrue($this->container->has('contao.search.escargot_subscriber.broken_link_checker'));

$definition = $this->container->getDefinition('contao.search.escargot_subscriber.broken_link_checker');

$this->assertSame(BrokenLinkCheckerSubscriber::class, $definition->getClass());
$this->assertTrue($definition->isPrivate());
$this->assertSame([], $definition->getArguments());

$tags = $definition->getTags();

$this->assertArrayHasKey('contao.escargot_subscriber', $tags);
}

public function testRegistersTheSearchEscargotSearchIndexSubscriber(): void
{
$this->assertTrue($this->container->has('contao.search.escargot_subscriber.search_index'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Contao\CoreBundle\Search\Escargot\Subscriber\BrokenLinkCheckerSubscriber;
use Contao\CoreBundle\Search\Escargot\Subscriber\SubscriberResult;
use Nyholm\Psr7\Uri;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
Expand All @@ -35,6 +36,7 @@ class BrokenLinkCheckerSubscriberTest extends TestCase
public function testName(): void
{
$subscriber = new BrokenLinkCheckerSubscriber();

$this->assertSame('broken-link-checker', $subscriber->getName());
}

Expand Down Expand Up @@ -204,13 +206,7 @@ public function testOnException(ExceptionInterface $exception, ResponseInterface

$subscriber = new BrokenLinkCheckerSubscriber();
$subscriber->setEscargot($escargot);

$subscriber->onException(
new CrawlUri(new Uri('https://contao.org'), 0),
$exception,
$response,
$chunk
);
$subscriber->onException(new CrawlUri(new Uri('https://contao.org'), 0), $exception, $response, $chunk);

$previousResult = null;

Expand Down Expand Up @@ -255,32 +251,36 @@ public function onExceptionProvider(): \Generator
];
}

/**
* @return ResponseInterface&MockObject
*/
private function getResponse(int $statusCode = 200): ResponseInterface
{
$response = $this->createMock(ResponseInterface::class);

$response
->expects($this->any())
->method('getStatusCode')
->willReturn($statusCode)
;

$response
->expects($this->any())
->method('getInfo')
->willReturnCallback(static function (string $key) use ($statusCode) {
if ('http_code' === $key) {
return $statusCode;
}
->willReturnCallback(
static function (string $key) use ($statusCode) {
if ('http_code' === $key) {
return $statusCode;
}

if ('url' === $key) {
return '';
}
if ('url' === $key) {
return '';
}

if ('response_headers' === $key) {
return [];
}

if ('response_headers' === $key) {
return [];
throw new \InvalidArgumentException('Invalid key: '.$key);
}
})
)
;

return $response;
Expand Down

0 comments on commit c25eeb8

Please sign in to comment.