Improved NotifyVisitToWebHooksTest to kill more mutants

This commit is contained in:
Alejandro Celaya 2019-12-28 10:43:13 +01:00
parent 79cd3ba912
commit 4886825564
4 changed files with 24 additions and 6 deletions

View File

@ -10,6 +10,8 @@ use Fig\Http\Message\RequestMethodInterface;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Promise\RejectedPromise;
use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
@ -81,7 +83,17 @@ class NotifyVisitToWebHooksTest extends TestCase
$requestAsync = $this->httpClient->requestAsync(
RequestMethodInterface::METHOD_POST,
Argument::type('string'),
Argument::type('array')
Argument::that(function (array $requestOptions) {
Assert::assertArrayHasKey(RequestOptions::HEADERS, $requestOptions);
Assert::assertArrayHasKey(RequestOptions::JSON, $requestOptions);
Assert::assertArrayHasKey(RequestOptions::TIMEOUT, $requestOptions);
Assert::assertEquals($requestOptions[RequestOptions::TIMEOUT], 10);
Assert::assertEquals($requestOptions[RequestOptions::HEADERS], ['User-Agent' => 'Shlink:v1.2.3']);
Assert::assertArrayHasKey('shortUrl', $requestOptions[RequestOptions::JSON]);
Assert::assertArrayHasKey('visit', $requestOptions[RequestOptions::JSON]);
return $requestOptions;
})
)->will(function (array $args) use ($invalidWebhooks) {
[, $webhook] = $args;
$e = new Exception('');
@ -90,7 +102,13 @@ class NotifyVisitToWebHooksTest extends TestCase
});
$logWarning = $this->logger->warning(
'Failed to notify visit with id "{visitId}" to webhook "{webhook}". {e}',
Argument::type('array')
Argument::that(function (array $extra) {
Assert::assertArrayHasKey('webhook', $extra);
Assert::assertArrayHasKey('visitId', $extra);
Assert::assertArrayHasKey('e', $extra);
return $extra;
})
);
$this->createListener($webhooks)(new ShortUrlLocated('1'));
@ -108,7 +126,7 @@ class NotifyVisitToWebHooksTest extends TestCase
$this->logger->reveal(),
$webhooks,
[],
new AppOptions()
new AppOptions(['name' => 'Shlink', 'version' => '1.2.3'])
);
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
bootstrap="./config/test/bootstrap_api_tests.php"
colors="true"
>

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
bootstrap="./config/test/bootstrap_db_tests.php"
colors="true"
>

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
>