From b8cb38ae5cbe0bc1abcccc24031bacbe86913c77 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 16 Feb 2019 10:53:45 +0100 Subject: [PATCH 1/2] Updated testing tools --- .gitignore | 1 + bin/test/run-api-tests.sh | 2 +- composer.json | 13 +++---- .../Command/Api/DisableKeyCommandTest.php | 6 ++-- .../Command/Api/GenerateKeyCommandTest.php | 4 +-- .../test/Command/Api/ListKeysCommandTest.php | 34 ++++++++----------- .../Config/GenerateCharsetCommandTest.php | 4 +-- .../ShortUrl/DeleteShortCodeCommandTest.php | 20 +++++++---- .../ShortUrl/GeneratePreviewCommandTest.php | 10 +++--- .../ShortUrl/GenerateShortUrlCommandTest.php | 8 ++--- .../Command/ShortUrl/GetVisitsCommandTest.php | 8 ++--- .../ShortUrl/ListShortUrlsCommandTest.php | 24 ++++++------- .../ShortUrl/ResolveUrlCommandTest.php | 6 ++-- .../test/Command/Tag/CreateTagCommandTest.php | 6 ++-- .../Command/Tag/DeleteTagsCommandTest.php | 6 ++-- .../test/Command/Tag/ListTagsCommandTest.php | 8 ++--- .../test/Command/Tag/RenameTagCommandTest.php | 6 ++-- .../Visit/ProcessVisitsCommandTest.php | 10 +++--- .../Command/Visit/UpdateDbCommandTest.php | 6 ++-- module/CLI/test/ConfigProviderTest.php | 2 +- .../test/Factory/ApplicationFactoryTest.php | 2 +- .../test-db/DbTest/DatabaseTestCase.php | 2 +- module/Common/test/ConfigProviderTest.php | 2 +- .../Common/test/Console/ShlinkTableTest.php | 2 +- .../Common/test/Factory/CacheFactoryTest.php | 4 +-- .../DottedAccessConfigAbstractFactoryTest.php | 2 +- ...seImplicitOptionsMiddlewareFactoryTest.php | 2 +- .../test/Factory/EntityManagerFactoryTest.php | 2 +- .../Common/test/Factory/LoggerFactoryTest.php | 2 +- .../test/Factory/TranslatorFactoryTest.php | 2 +- .../test/Image/ImageBuilderFactoryTest.php | 2 +- module/Common/test/Image/ImageFactoryTest.php | 2 +- .../ChainIpLocationResolverTest.php | 2 +- .../EmptyIpLocationResolverTest.php | 2 +- .../IpGeolocation/GeoLite2/DbUpdaterTest.php | 2 +- .../GeoLite2LocationResolverTest.php | 2 +- .../IpApiLocationResolverTest.php | 9 +++-- .../ExceptionWithNewLineProcessorTest.php | 2 +- .../CloseDbConnectionMiddlewareTest.php | 2 +- .../IpAddressMiddlewareFactoryTest.php | 2 +- .../test/Middleware/LocaleMiddlewareTest.php | 2 +- .../PaginableRepositoryAdapterTest.php | 2 +- .../test/Response/PixelResponseTest.php | 2 +- .../test/Service/PreviewGeneratorTest.php | 10 +++--- .../Extension/TranslatorExtensionTest.php | 2 +- .../test/Type/ChronosDateTimeTypeTest.php | 2 +- .../Repository/ShortUrlRepositoryTest.php | 2 +- .../test-db/Repository/TagRepositoryTest.php | 2 +- .../Repository/VisitRepositoryTest.php | 2 +- module/Core/test/Action/PixelActionTest.php | 2 +- module/Core/test/Action/PreviewActionTest.php | 2 +- module/Core/test/Action/QrCodeActionTest.php | 2 +- .../Core/test/Action/RedirectActionTest.php | 2 +- module/Core/test/ConfigProviderTest.php | 2 +- .../Middleware/QrCodeCacheMiddlewareTest.php | 2 +- .../test/Response/NotFoundHandlerTest.php | 2 +- .../ShortUrl/DeleteShortUrlServiceTest.php | 2 +- .../Core/test/Service/ShortUrlServiceTest.php | 2 +- .../Core/test/Service/Tag/TagServiceTest.php | 2 +- module/Core/test/Service/UrlShortenerTest.php | 23 ++++++------- module/Core/test/Service/VisitServiceTest.php | 2 +- .../Core/test/Service/VisitsTrackerTest.php | 2 +- .../test/Action/AuthenticateActionTest.php | 2 +- .../test/Action/HealthActionFactoryTest.php | 2 +- module/Rest/test/Action/HealthActionTest.php | 2 +- .../ShortUrl/CreateShortUrlActionTest.php | 4 +-- .../ShortUrl/DeleteShortUrlActionTest.php | 2 +- .../ShortUrl/EditShortUrlActionTest.php | 2 +- .../ShortUrl/EditShortUrlTagsActionTest.php | 2 +- .../ShortUrl/ListShortUrlsActionTest.php | 2 +- .../ShortUrl/ResolveShortUrlActionTest.php | 2 +- .../SingleStepCreateShortUrlActionTest.php | 2 +- .../test/Action/Tag/CreateTagsActionTest.php | 2 +- .../test/Action/Tag/DeleteTagsActionTest.php | 2 +- .../test/Action/Tag/ListTagsActionTest.php | 2 +- .../test/Action/Tag/UpdateTagActionTest.php | 2 +- .../test/Action/Visit/GetVisitsActionTest.php | 2 +- ...AuthenticationPluginManagerFactoryTest.php | 2 +- .../test/Authentication/JWTServiceTest.php | 9 +++-- .../Plugin/ApiKeyHeaderPluginTest.php | 2 +- .../Plugin/AuthorizationHeaderPluginTest.php | 2 +- .../RequestToAuthPluginTest.php | 2 +- module/Rest/test/ConfigProviderTest.php | 2 +- .../JsonErrorResponseGeneratorTest.php | 2 +- .../AuthenticationMiddlewareTest.php | 2 +- .../Middleware/BodyParserMiddlewareTest.php | 2 +- .../Middleware/CrossDomainMiddlewareTest.php | 2 +- .../Middleware/PathVersionMiddlewareTest.php | 2 +- ...ortUrlContentNegotiationMiddlewareTest.php | 2 +- .../ShortUrl/ShortCodePathMiddlewareTest.php | 6 ++-- .../Rest/test/Service/ApiKeyServiceTest.php | 9 +++-- 91 files changed, 192 insertions(+), 192 deletions(-) diff --git a/.gitignore b/.gitignore index 9c2b2223..a5163a27 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ data/shlink-tests.db data/GeoLite2-City.mmdb docs/swagger-ui* docker-compose.override.yml +.phpunit.result.cache diff --git a/bin/test/run-api-tests.sh b/bin/test/run-api-tests.sh index 5086ce41..2182a43f 100755 --- a/bin/test/run-api-tests.sh +++ b/bin/test/run-api-tests.sh @@ -10,5 +10,5 @@ echo 'Starting server...' vendor/bin/zend-expressive-swoole start -d sleep 2 -vendor/bin/phpunit --order-by=random -c phpunit-api.xml +vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox vendor/bin/zend-expressive-swoole stop diff --git a/composer.json b/composer.json index 0e347200..2d12ff9e 100644 --- a/composer.json +++ b/composer.json @@ -55,8 +55,8 @@ "filp/whoops": "^2.0", "infection/infection": "^0.11.0", "phpstan/phpstan": "^0.10.0", - "phpunit/phpcov": "^5.0", - "phpunit/phpunit": "^7.3", + "phpunit/phpcov": "dev-master#68702e4ec8563d118a5103b5f49031877692a63c || ^5.0", + "phpunit/phpunit": "^8.0 || ^7.5", "roave/security-advisories": "dev-master", "shlinkio/php-coding-standard": "~1.0.0", "symfony/dotenv": "^4.2", @@ -112,9 +112,9 @@ "@test:db", "@test:api" ], - "test:unit": "phpdbg -qrr vendor/bin/phpunit --order-by=random --coverage-php build/coverage-unit.cov", - "test:unit:ci": "phpdbg -qrr vendor/bin/phpunit --order-by=random --coverage-php build/coverage-unit.cov --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/phpunit.junit.xml", - "test:db": "APP_ENV=test phpdbg -qrr vendor/bin/phpunit --order-by=random -c phpunit-db.xml --coverage-php build/coverage-db.cov", + "test:unit": "phpdbg -qrr vendor/bin/phpunit --order-by=random --coverage-php build/coverage-unit.cov --testdox", + "test:unit:ci": "phpdbg -qrr vendor/bin/phpunit --order-by=random --coverage-php build/coverage-unit.cov --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/phpunit.junit.xml --testdox", + "test:db": "APP_ENV=test phpdbg -qrr vendor/bin/phpunit --order-by=random -c phpunit-db.xml --coverage-php build/coverage-db.cov --testdox", "test:api": "bin/test/run-api-tests.sh", "test:pretty": [ @@ -147,7 +147,8 @@ "test:unit:pretty": "Runs unit test suites and generates an HTML code coverage report", "infect": "Checks unit tests quality applying mutation testing", "infect:ci": "Checks unit tests quality applying mutation testing with existing reports and logs", - "infect:show": "Checks unit tests quality applying mutation testing and shows applied mutators" + "infect:show": "Checks unit tests quality applying mutation testing and shows applied mutators", + "infect:test": "Checks unit tests quality applying mutation testing" }, "config": { "sort-packages": true diff --git a/module/CLI/test/Command/Api/DisableKeyCommandTest.php b/module/CLI/test/Command/Api/DisableKeyCommandTest.php index c0a36f1d..a63b94b6 100644 --- a/module/CLI/test/Command/Api/DisableKeyCommandTest.php +++ b/module/CLI/test/Command/Api/DisableKeyCommandTest.php @@ -18,7 +18,7 @@ class DisableKeyCommandTest extends TestCase /** @var ObjectProphecy */ private $apiKeyService; - public function setUp() + public function setUp(): void { $this->apiKeyService = $this->prophesize(ApiKeyService::class); $command = new DisableKeyCommand($this->apiKeyService->reveal()); @@ -41,7 +41,7 @@ class DisableKeyCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('API key "abcd1234" properly disabled', $output); + $this->assertStringContainsString('API key "abcd1234" properly disabled', $output); } /** @@ -58,7 +58,7 @@ class DisableKeyCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('API key "abcd1234" does not exist.', $output); + $this->assertStringContainsString('API key "abcd1234" does not exist.', $output); $disable->shouldHaveBeenCalledOnce(); } } diff --git a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php index 104af2b3..1ffee677 100644 --- a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php +++ b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php @@ -20,7 +20,7 @@ class GenerateKeyCommandTest extends TestCase /** @var ObjectProphecy */ private $apiKeyService; - public function setUp() + public function setUp(): void { $this->apiKeyService = $this->prophesize(ApiKeyService::class); $command = new GenerateKeyCommand($this->apiKeyService->reveal()); @@ -41,7 +41,7 @@ class GenerateKeyCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Generated API key: ', $output); + $this->assertStringContainsString('Generated API key: ', $output); $create->shouldHaveBeenCalledOnce(); } diff --git a/module/CLI/test/Command/Api/ListKeysCommandTest.php b/module/CLI/test/Command/Api/ListKeysCommandTest.php index 5a656073..c7b081f3 100644 --- a/module/CLI/test/Command/Api/ListKeysCommandTest.php +++ b/module/CLI/test/Command/Api/ListKeysCommandTest.php @@ -18,7 +18,7 @@ class ListKeysCommandTest extends TestCase /** @var ObjectProphecy */ private $apiKeyService; - public function setUp() + public function setUp(): void { $this->apiKeyService = $this->prophesize(ApiKeyService::class); $command = new ListKeysCommand($this->apiKeyService->reveal()); @@ -27,10 +27,8 @@ class ListKeysCommandTest extends TestCase $this->commandTester = new CommandTester($command); } - /** - * @test - */ - public function everythingIsListedIfEnabledOnlyIsNotProvided() + /** @test */ + public function everythingIsListedIfEnabledOnlyIsNotProvided(): void { $this->apiKeyService->listKeys(false)->willReturn([ new ApiKey(), @@ -43,17 +41,15 @@ class ListKeysCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Key', $output); - $this->assertContains('Is enabled', $output); - $this->assertContains(' +++ ', $output); - $this->assertNotContains(' --- ', $output); - $this->assertContains('Expiration date', $output); + $this->assertStringContainsString('Key', $output); + $this->assertStringContainsString('Is enabled', $output); + $this->assertStringContainsString(' +++ ', $output); + $this->assertStringNotContainsString(' --- ', $output); + $this->assertStringContainsString('Expiration date', $output); } - /** - * @test - */ - public function onlyEnabledKeysAreListedIfEnabledOnlyIsProvided() + /** @test */ + public function onlyEnabledKeysAreListedIfEnabledOnlyIsProvided(): void { $this->apiKeyService->listKeys(true)->willReturn([ (new ApiKey())->disable(), @@ -66,10 +62,10 @@ class ListKeysCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Key', $output); - $this->assertNotContains('Is enabled', $output); - $this->assertNotContains(' +++ ', $output); - $this->assertNotContains(' --- ', $output); - $this->assertContains('Expiration date', $output); + $this->assertStringContainsString('Key', $output); + $this->assertStringNotContainsString('Is enabled', $output); + $this->assertStringNotContainsString(' +++ ', $output); + $this->assertStringNotContainsString(' --- ', $output); + $this->assertStringContainsString('Expiration date', $output); } } diff --git a/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php b/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php index 33e0d173..941ff0e8 100644 --- a/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php +++ b/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php @@ -16,7 +16,7 @@ class GenerateCharsetCommandTest extends TestCase /** @var CommandTester */ private $commandTester; - public function setUp() + public function setUp(): void { $command = new GenerateCharsetCommand(); $app = new Application(); @@ -38,7 +38,7 @@ class GenerateCharsetCommandTest extends TestCase $output = $this->commandTester->getDisplay(); // Both default character set and the new one should have the same length - $this->assertContains($prefix, $output); + $this->assertStringContainsString($prefix, $output); } protected function orderStringLetters($string) diff --git a/module/CLI/test/Command/ShortUrl/DeleteShortCodeCommandTest.php b/module/CLI/test/Command/ShortUrl/DeleteShortCodeCommandTest.php index f6fae5d1..ee514109 100644 --- a/module/CLI/test/Command/ShortUrl/DeleteShortCodeCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/DeleteShortCodeCommandTest.php @@ -21,7 +21,7 @@ class DeleteShortCodeCommandTest extends TestCase /** @var ObjectProphecy */ private $service; - public function setUp() + public function setUp(): void { $this->service = $this->prophesize(DeleteShortUrlServiceInterface::class); @@ -44,7 +44,10 @@ class DeleteShortCodeCommandTest extends TestCase $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); - $this->assertContains(sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output); + $this->assertStringContainsString( + sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), + $output + ); $deleteByShortCode->shouldHaveBeenCalledOnce(); } @@ -61,7 +64,7 @@ class DeleteShortCodeCommandTest extends TestCase $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); - $this->assertContains(sprintf('Provided short code "%s" could not be found.', $shortCode), $output); + $this->assertStringContainsString(sprintf('Provided short code "%s" could not be found.', $shortCode), $output); $deleteByShortCode->shouldHaveBeenCalledOnce(); } @@ -85,11 +88,14 @@ class DeleteShortCodeCommandTest extends TestCase $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); - $this->assertContains(sprintf( + $this->assertStringContainsString(sprintf( 'It was not possible to delete the short URL with short code "%s" because it has more than 10 visits.', $shortCode ), $output); - $this->assertContains(sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output); + $this->assertStringContainsString( + sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), + $output + ); $deleteByShortCode->shouldHaveBeenCalledTimes(2); } @@ -107,11 +113,11 @@ class DeleteShortCodeCommandTest extends TestCase $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); - $this->assertContains(sprintf( + $this->assertStringContainsString(sprintf( 'It was not possible to delete the short URL with short code "%s" because it has more than 10 visits.', $shortCode ), $output); - $this->assertContains('Short URL was not deleted.', $output); + $this->assertStringContainsString('Short URL was not deleted.', $output); $deleteByShortCode->shouldHaveBeenCalledOnce(); } } diff --git a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php index a9fa2844..aaf0a5e1 100644 --- a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php @@ -27,7 +27,7 @@ class GeneratePreviewCommandTest extends TestCase /** @var ObjectProphecy */ private $shortUrlService; - public function setUp() + public function setUp(): void { $this->previewGenerator = $this->prophesize(PreviewGenerator::class); $this->shortUrlService = $this->prophesize(ShortUrlService::class); @@ -60,10 +60,10 @@ class GeneratePreviewCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Processing URL http://foo.com', $output); - $this->assertContains('Processing URL https://bar.com', $output); - $this->assertContains('Processing URL http://baz.com/something', $output); - $this->assertContains('Finished processing all URLs', $output); + $this->assertStringContainsString('Processing URL http://foo.com', $output); + $this->assertStringContainsString('Processing URL https://bar.com', $output); + $this->assertStringContainsString('Processing URL http://baz.com/something', $output); + $this->assertStringContainsString('Finished processing all URLs', $output); $generatePreview1->shouldHaveBeenCalledOnce(); $generatePreview2->shouldHaveBeenCalledOnce(); $generatePreview3->shouldHaveBeenCalledOnce(); diff --git a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php index 03db0d61..36125fa1 100644 --- a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php @@ -22,7 +22,7 @@ class GenerateShortUrlCommandTest extends TestCase /** @var ObjectProphecy */ private $urlShortener; - public function setUp() + public function setUp(): void { $this->urlShortener = $this->prophesize(UrlShortener::class); $command = new GenerateShortUrlCommand($this->urlShortener->reveal(), [ @@ -50,7 +50,7 @@ class GenerateShortUrlCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('http://foo.com/abc123', $output); + $this->assertStringContainsString('http://foo.com/abc123', $output); $urlToShortCode->shouldHaveBeenCalledOnce(); } @@ -67,7 +67,7 @@ class GenerateShortUrlCommandTest extends TestCase 'longUrl' => 'http://domain.com/invalid', ]); $output = $this->commandTester->getDisplay(); - $this->assertContains( + $this->assertStringContainsString( 'Provided URL "http://domain.com/invalid" is invalid.', $output ); @@ -94,7 +94,7 @@ class GenerateShortUrlCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('http://foo.com/abc123', $output); + $this->assertStringContainsString('http://foo.com/abc123', $output); $urlToShortCode->shouldHaveBeenCalledOnce(); } } diff --git a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php index 87ee003d..6e0f830d 100644 --- a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php @@ -27,7 +27,7 @@ class GetVisitsCommandTest extends TestCase /** @var ObjectProphecy */ private $visitsTracker; - public function setUp() + public function setUp(): void { $this->visitsTracker = $this->prophesize(VisitsTrackerInterface::class); $command = new GetVisitsCommand($this->visitsTracker->reveal()); @@ -94,8 +94,8 @@ class GetVisitsCommandTest extends TestCase 'shortCode' => $shortCode, ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('foo', $output); - $this->assertContains('Spain', $output); - $this->assertContains('bar', $output); + $this->assertStringContainsString('foo', $output); + $this->assertStringContainsString('Spain', $output); + $this->assertStringContainsString('bar', $output); } } diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index d21b4625..f8b3a920 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -21,7 +21,7 @@ class ListShortUrlsCommandTest extends TestCase /** @var ObjectProphecy */ private $shortUrlService; - public function setUp() + public function setUp(): void { $this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class); $app = new Application(); @@ -61,9 +61,9 @@ class ListShortUrlsCommandTest extends TestCase $this->commandTester->execute(['command' => 'shortcode:list']); $output = $this->commandTester->getDisplay(); - $this->assertContains('Continue with page 2?', $output); - $this->assertContains('Continue with page 3?', $output); - $this->assertContains('Continue with page 4?', $output); + $this->assertStringContainsString('Continue with page 2?', $output); + $this->assertStringContainsString('Continue with page 3?', $output); + $this->assertStringContainsString('Continue with page 4?', $output); } /** @@ -84,13 +84,13 @@ class ListShortUrlsCommandTest extends TestCase $this->commandTester->execute(['command' => 'shortcode:list']); $output = $this->commandTester->getDisplay(); - $this->assertContains('url_1', $output); - $this->assertContains('url_9', $output); - $this->assertNotContains('url_10', $output); - $this->assertNotContains('url_20', $output); - $this->assertNotContains('url_30', $output); - $this->assertContains('Continue with page 2?', $output); - $this->assertNotContains('Continue with page 3?', $output); + $this->assertStringContainsString('url_1', $output); + $this->assertStringContainsString('url_9', $output); + $this->assertStringNotContainsString('url_10', $output); + $this->assertStringNotContainsString('url_20', $output); + $this->assertStringNotContainsString('url_30', $output); + $this->assertStringContainsString('Continue with page 2?', $output); + $this->assertStringNotContainsString('Continue with page 3?', $output); } /** @@ -123,6 +123,6 @@ class ListShortUrlsCommandTest extends TestCase '--showTags' => true, ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Tags', $output); + $this->assertStringContainsString('Tags', $output); } } diff --git a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php index 46ce05c6..fa9acdab 100644 --- a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php @@ -21,7 +21,7 @@ class ResolveUrlCommandTest extends TestCase /** @var ObjectProphecy */ private $urlShortener; - public function setUp() + public function setUp(): void { $this->urlShortener = $this->prophesize(UrlShortener::class); $command = new ResolveUrlCommand($this->urlShortener->reveal()); @@ -64,7 +64,7 @@ class ResolveUrlCommandTest extends TestCase 'shortCode' => $shortCode, ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Provided short code "' . $shortCode . '" could not be found.', $output); + $this->assertStringContainsString('Provided short code "' . $shortCode . '" could not be found.', $output); } /** @@ -81,6 +81,6 @@ class ResolveUrlCommandTest extends TestCase 'shortCode' => $shortCode, ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Provided short code "' . $shortCode . '" has an invalid format.', $output); + $this->assertStringContainsString('Provided short code "' . $shortCode . '" has an invalid format.', $output); } } diff --git a/module/CLI/test/Command/Tag/CreateTagCommandTest.php b/module/CLI/test/Command/Tag/CreateTagCommandTest.php index c7cf5949..84efc922 100644 --- a/module/CLI/test/Command/Tag/CreateTagCommandTest.php +++ b/module/CLI/test/Command/Tag/CreateTagCommandTest.php @@ -19,7 +19,7 @@ class CreateTagCommandTest extends TestCase /** @var ObjectProphecy */ private $tagService; - public function setUp() + public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); @@ -38,7 +38,7 @@ class CreateTagCommandTest extends TestCase $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); - $this->assertContains('You have to provide at least one tag name', $output); + $this->assertStringContainsString('You have to provide at least one tag name', $output); } /** @@ -55,7 +55,7 @@ class CreateTagCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Tags properly created', $output); + $this->assertStringContainsString('Tags properly created', $output); $createTags->shouldHaveBeenCalled(); } } diff --git a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php index 31cc8e0e..8169941c 100644 --- a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php +++ b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php @@ -20,7 +20,7 @@ class DeleteTagsCommandTest extends TestCase /** @var ObjectProphecy */ private $tagService; - public function setUp() + public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); @@ -39,7 +39,7 @@ class DeleteTagsCommandTest extends TestCase $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); - $this->assertContains('You have to provide at least one tag name', $output); + $this->assertStringContainsString('You have to provide at least one tag name', $output); } /** @@ -57,7 +57,7 @@ class DeleteTagsCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Tags properly deleted', $output); + $this->assertStringContainsString('Tags properly deleted', $output); $deleteTags->shouldHaveBeenCalled(); } } diff --git a/module/CLI/test/Command/Tag/ListTagsCommandTest.php b/module/CLI/test/Command/Tag/ListTagsCommandTest.php index a1c64331..2f88a861 100644 --- a/module/CLI/test/Command/Tag/ListTagsCommandTest.php +++ b/module/CLI/test/Command/Tag/ListTagsCommandTest.php @@ -21,7 +21,7 @@ class ListTagsCommandTest extends TestCase /** @var ObjectProphecy */ private $tagService; - public function setUp() + public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); @@ -43,7 +43,7 @@ class ListTagsCommandTest extends TestCase $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); - $this->assertContains('No tags yet', $output); + $this->assertStringContainsString('No tags yet', $output); $listTags->shouldHaveBeenCalled(); } @@ -61,8 +61,8 @@ class ListTagsCommandTest extends TestCase $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); - $this->assertContains('foo', $output); - $this->assertContains('bar', $output); + $this->assertStringContainsString('foo', $output); + $this->assertStringContainsString('bar', $output); $listTags->shouldHaveBeenCalled(); } } diff --git a/module/CLI/test/Command/Tag/RenameTagCommandTest.php b/module/CLI/test/Command/Tag/RenameTagCommandTest.php index b5e9b977..c6c8815b 100644 --- a/module/CLI/test/Command/Tag/RenameTagCommandTest.php +++ b/module/CLI/test/Command/Tag/RenameTagCommandTest.php @@ -22,7 +22,7 @@ class RenameTagCommandTest extends TestCase /** @var ObjectProphecy */ private $tagService; - public function setUp() + public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); @@ -49,7 +49,7 @@ class RenameTagCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('A tag with name "foo" was not found', $output); + $this->assertStringContainsString('A tag with name "foo" was not found', $output); $renameTag->shouldHaveBeenCalled(); } @@ -69,7 +69,7 @@ class RenameTagCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Tag properly renamed', $output); + $this->assertStringContainsString('Tag properly renamed', $output); $renameTag->shouldHaveBeenCalled(); } } diff --git a/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php b/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php index 6db2af0b..cd438637 100644 --- a/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php @@ -37,7 +37,7 @@ class ProcessVisitsCommandTest extends TestCase /** @var ObjectProphecy */ private $lock; - public function setUp() + public function setUp(): void { $this->visitService = $this->prophesize(VisitService::class); $this->ipResolver = $this->prophesize(IpApiLocationResolver::class); @@ -84,7 +84,7 @@ class ProcessVisitsCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - $this->assertContains('Processing IP 1.2.3.0', $output); + $this->assertStringContainsString('Processing IP 1.2.3.0', $output); $locateVisits->shouldHaveBeenCalledOnce(); $resolveIpLocation->shouldHaveBeenCalledOnce(); } @@ -118,7 +118,7 @@ class ProcessVisitsCommandTest extends TestCase $this->assertInstanceOf(IpCannotBeLocatedException::class, $e); - $this->assertContains($message, $output); + $this->assertStringContainsString($message, $output); $locateVisits->shouldHaveBeenCalledOnce(); $resolveIpLocation->shouldNotHaveBeenCalled(); } @@ -161,7 +161,7 @@ class ProcessVisitsCommandTest extends TestCase $this->assertInstanceOf(IpCannotBeLocatedException::class, $e); - $this->assertContains('An error occurred while locating IP. Skipped', $output); + $this->assertStringContainsString('An error occurred while locating IP. Skipped', $output); $locateVisits->shouldHaveBeenCalledOnce(); $resolveIpLocation->shouldHaveBeenCalledOnce(); } @@ -183,7 +183,7 @@ class ProcessVisitsCommandTest extends TestCase ], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); $output = $this->commandTester->getDisplay(); - $this->assertContains( + $this->assertStringContainsString( sprintf('There is already an instance of the "%s" command', ProcessVisitsCommand::NAME), $output ); diff --git a/module/CLI/test/Command/Visit/UpdateDbCommandTest.php b/module/CLI/test/Command/Visit/UpdateDbCommandTest.php index d6b6a494..b6d3caeb 100644 --- a/module/CLI/test/Command/Visit/UpdateDbCommandTest.php +++ b/module/CLI/test/Command/Visit/UpdateDbCommandTest.php @@ -19,7 +19,7 @@ class UpdateDbCommandTest extends TestCase /** @var ObjectProphecy */ private $dbUpdater; - public function setUp() + public function setUp(): void { $this->dbUpdater = $this->prophesize(DbUpdaterInterface::class); @@ -41,7 +41,7 @@ class UpdateDbCommandTest extends TestCase $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); - $this->assertContains('GeoLite2 database properly updated', $output); + $this->assertStringContainsString('GeoLite2 database properly updated', $output); $download->shouldHaveBeenCalledOnce(); } @@ -55,7 +55,7 @@ class UpdateDbCommandTest extends TestCase $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); - $this->assertContains('An error occurred while updating GeoLite2 database', $output); + $this->assertStringContainsString('An error occurred while updating GeoLite2 database', $output); $download->shouldHaveBeenCalledOnce(); } } diff --git a/module/CLI/test/ConfigProviderTest.php b/module/CLI/test/ConfigProviderTest.php index 1f9c33a5..8d937df2 100644 --- a/module/CLI/test/ConfigProviderTest.php +++ b/module/CLI/test/ConfigProviderTest.php @@ -11,7 +11,7 @@ class ConfigProviderTest extends TestCase /** @var ConfigProvider */ private $configProvider; - public function setUp() + public function setUp(): void { $this->configProvider = new ConfigProvider(); } diff --git a/module/CLI/test/Factory/ApplicationFactoryTest.php b/module/CLI/test/Factory/ApplicationFactoryTest.php index 00f05cfe..85d875fc 100644 --- a/module/CLI/test/Factory/ApplicationFactoryTest.php +++ b/module/CLI/test/Factory/ApplicationFactoryTest.php @@ -18,7 +18,7 @@ class ApplicationFactoryTest extends TestCase /** @var ApplicationFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new ApplicationFactory(); } diff --git a/module/Common/test-db/DbTest/DatabaseTestCase.php b/module/Common/test-db/DbTest/DatabaseTestCase.php index dc102c8c..b323b34c 100644 --- a/module/Common/test-db/DbTest/DatabaseTestCase.php +++ b/module/Common/test-db/DbTest/DatabaseTestCase.php @@ -23,7 +23,7 @@ abstract class DatabaseTestCase extends TestCase return self::$em; } - public function tearDown() + public function tearDown(): void { foreach (static::ENTITIES_TO_EMPTY as $entityClass) { $qb = $this->getEntityManager()->createQueryBuilder(); diff --git a/module/Common/test/ConfigProviderTest.php b/module/Common/test/ConfigProviderTest.php index a133ba61..e98a772a 100644 --- a/module/Common/test/ConfigProviderTest.php +++ b/module/Common/test/ConfigProviderTest.php @@ -11,7 +11,7 @@ class ConfigProviderTest extends TestCase /** @var ConfigProvider */ private $configProvider; - public function setUp() + public function setUp(): void { $this->configProvider = new ConfigProvider(); } diff --git a/module/Common/test/Console/ShlinkTableTest.php b/module/Common/test/Console/ShlinkTableTest.php index d38fb5bb..7a4c7135 100644 --- a/module/Common/test/Console/ShlinkTableTest.php +++ b/module/Common/test/Console/ShlinkTableTest.php @@ -19,7 +19,7 @@ class ShlinkTableTest extends TestCase /** @var ObjectProphecy */ private $baseTable; - public function setUp() + public function setUp(): void { $this->baseTable = $this->prophesize(Table::class); $this->shlinkTable = new ShlinkTable($this->baseTable->reveal()); diff --git a/module/Common/test/Factory/CacheFactoryTest.php b/module/Common/test/Factory/CacheFactoryTest.php index 24414903..16d143ca 100644 --- a/module/Common/test/Factory/CacheFactoryTest.php +++ b/module/Common/test/Factory/CacheFactoryTest.php @@ -22,12 +22,12 @@ class CacheFactoryTest extends TestCase /** @var CacheFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new CacheFactory(); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { putenv('APP_ENV'); } diff --git a/module/Common/test/Factory/DottedAccessConfigAbstractFactoryTest.php b/module/Common/test/Factory/DottedAccessConfigAbstractFactoryTest.php index 4e11f765..f5a3a6e1 100644 --- a/module/Common/test/Factory/DottedAccessConfigAbstractFactoryTest.php +++ b/module/Common/test/Factory/DottedAccessConfigAbstractFactoryTest.php @@ -14,7 +14,7 @@ class DottedAccessConfigAbstractFactoryTest extends TestCase /** @var DottedAccessConfigAbstractFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new DottedAccessConfigAbstractFactory(); } diff --git a/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php b/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php index a254e9f2..3d21f261 100644 --- a/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php +++ b/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php @@ -15,7 +15,7 @@ class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase /** @var EmptyResponseImplicitOptionsMiddlewareFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new EmptyResponseImplicitOptionsMiddlewareFactory(); } diff --git a/module/Common/test/Factory/EntityManagerFactoryTest.php b/module/Common/test/Factory/EntityManagerFactoryTest.php index c8f5ee0a..ec70f59e 100644 --- a/module/Common/test/Factory/EntityManagerFactoryTest.php +++ b/module/Common/test/Factory/EntityManagerFactoryTest.php @@ -13,7 +13,7 @@ class EntityManagerFactoryTest extends TestCase /** @var EntityManagerFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new EntityManagerFactory(); } diff --git a/module/Common/test/Factory/LoggerFactoryTest.php b/module/Common/test/Factory/LoggerFactoryTest.php index 5faf7503..adcb5865 100644 --- a/module/Common/test/Factory/LoggerFactoryTest.php +++ b/module/Common/test/Factory/LoggerFactoryTest.php @@ -14,7 +14,7 @@ class LoggerFactoryTest extends TestCase /** @var LoggerFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new LoggerFactory(); } diff --git a/module/Common/test/Factory/TranslatorFactoryTest.php b/module/Common/test/Factory/TranslatorFactoryTest.php index 858635a4..4b099d25 100644 --- a/module/Common/test/Factory/TranslatorFactoryTest.php +++ b/module/Common/test/Factory/TranslatorFactoryTest.php @@ -13,7 +13,7 @@ class TranslatorFactoryTest extends TestCase /** @var TranslatorFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new TranslatorFactory(); } diff --git a/module/Common/test/Image/ImageBuilderFactoryTest.php b/module/Common/test/Image/ImageBuilderFactoryTest.php index 26c38a3a..9cfbb2e5 100644 --- a/module/Common/test/Image/ImageBuilderFactoryTest.php +++ b/module/Common/test/Image/ImageBuilderFactoryTest.php @@ -13,7 +13,7 @@ class ImageBuilderFactoryTest extends TestCase /** @var ImageBuilderFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new ImageBuilderFactory(); } diff --git a/module/Common/test/Image/ImageFactoryTest.php b/module/Common/test/Image/ImageFactoryTest.php index cef305b2..f94221b6 100644 --- a/module/Common/test/Image/ImageFactoryTest.php +++ b/module/Common/test/Image/ImageFactoryTest.php @@ -14,7 +14,7 @@ class ImageFactoryTest extends TestCase /** @var ImageFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new ImageFactory(); } diff --git a/module/Common/test/IpGeolocation/ChainIpLocationResolverTest.php b/module/Common/test/IpGeolocation/ChainIpLocationResolverTest.php index 9d0225e0..49bb0873 100644 --- a/module/Common/test/IpGeolocation/ChainIpLocationResolverTest.php +++ b/module/Common/test/IpGeolocation/ChainIpLocationResolverTest.php @@ -18,7 +18,7 @@ class ChainIpLocationResolverTest extends TestCase /** @var ObjectProphecy */ private $secondInnerResolver; - public function setUp() + public function setUp(): void { $this->firstInnerResolver = $this->prophesize(IpLocationResolverInterface::class); $this->secondInnerResolver = $this->prophesize(IpLocationResolverInterface::class); diff --git a/module/Common/test/IpGeolocation/EmptyIpLocationResolverTest.php b/module/Common/test/IpGeolocation/EmptyIpLocationResolverTest.php index e18af901..2c2962bb 100644 --- a/module/Common/test/IpGeolocation/EmptyIpLocationResolverTest.php +++ b/module/Common/test/IpGeolocation/EmptyIpLocationResolverTest.php @@ -26,7 +26,7 @@ class EmptyIpLocationResolverTest extends TestCase /** @var EmptyIpLocationResolver */ private $resolver; - public function setUp() + public function setUp(): void { $this->resolver = new EmptyIpLocationResolver(); } diff --git a/module/Common/test/IpGeolocation/GeoLite2/DbUpdaterTest.php b/module/Common/test/IpGeolocation/GeoLite2/DbUpdaterTest.php index f425a4fd..05a9a68f 100644 --- a/module/Common/test/IpGeolocation/GeoLite2/DbUpdaterTest.php +++ b/module/Common/test/IpGeolocation/GeoLite2/DbUpdaterTest.php @@ -26,7 +26,7 @@ class DbUpdaterTest extends TestCase /** @var GeoLite2Options */ private $options; - public function setUp() + public function setUp(): void { $this->httpClient = $this->prophesize(ClientInterface::class); $this->filesystem = $this->prophesize(Filesystem::class); diff --git a/module/Common/test/IpGeolocation/GeoLite2LocationResolverTest.php b/module/Common/test/IpGeolocation/GeoLite2LocationResolverTest.php index f29854cb..2c5209f0 100644 --- a/module/Common/test/IpGeolocation/GeoLite2LocationResolverTest.php +++ b/module/Common/test/IpGeolocation/GeoLite2LocationResolverTest.php @@ -19,7 +19,7 @@ class GeoLite2LocationResolverTest extends TestCase /** @var ObjectProphecy */ private $reader; - public function setUp() + public function setUp(): void { $this->reader = $this->prophesize(Reader::class); $this->resolver = new GeoLite2LocationResolver($this->reader->reveal()); diff --git a/module/Common/test/IpGeolocation/IpApiLocationResolverTest.php b/module/Common/test/IpGeolocation/IpApiLocationResolverTest.php index 55a1cb07..c830fc19 100644 --- a/module/Common/test/IpGeolocation/IpApiLocationResolverTest.php +++ b/module/Common/test/IpGeolocation/IpApiLocationResolverTest.php @@ -8,6 +8,7 @@ use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; +use Shlinkio\Shlink\Common\Exception\WrongIpException; use Shlinkio\Shlink\Common\IpGeolocation\IpApiLocationResolver; use function json_encode; @@ -18,7 +19,7 @@ class IpApiLocationResolverTest extends TestCase /** @var ObjectProphecy */ private $client; - public function setUp() + public function setUp(): void { $this->client = $this->prophesize(Client::class); $this->ipResolver = new IpApiLocationResolver($this->client->reveal()); @@ -52,14 +53,12 @@ class IpApiLocationResolverTest extends TestCase $this->assertEquals($expected, $this->ipResolver->resolveIpLocation('1.2.3.4')); } - /** - * @test - * @expectedException \Shlinkio\Shlink\Common\Exception\WrongIpException - */ + /** @test */ public function guzzleExceptionThrowsShlinkException() { $this->client->get('http://ip-api.com/json/1.2.3.4')->willThrow(new TransferException()) ->shouldBeCalledOnce(); + $this->expectException(WrongIpException::class); $this->ipResolver->resolveIpLocation('1.2.3.4'); } } diff --git a/module/Common/test/Logger/Processor/ExceptionWithNewLineProcessorTest.php b/module/Common/test/Logger/Processor/ExceptionWithNewLineProcessorTest.php index c502e84f..182dc235 100644 --- a/module/Common/test/Logger/Processor/ExceptionWithNewLineProcessorTest.php +++ b/module/Common/test/Logger/Processor/ExceptionWithNewLineProcessorTest.php @@ -12,7 +12,7 @@ class ExceptionWithNewLineProcessorTest extends TestCase /** @var ExceptionWithNewLineProcessor */ private $processor; - public function setUp() + public function setUp(): void { $this->processor = new ExceptionWithNewLineProcessor(); } diff --git a/module/Common/test/Middleware/CloseDbConnectionMiddlewareTest.php b/module/Common/test/Middleware/CloseDbConnectionMiddlewareTest.php index 35cd6fe0..f187559d 100644 --- a/module/Common/test/Middleware/CloseDbConnectionMiddlewareTest.php +++ b/module/Common/test/Middleware/CloseDbConnectionMiddlewareTest.php @@ -21,7 +21,7 @@ class CloseDbConnectionMiddlewareTest extends TestCase /** @var ObjectProphecy */ private $em; - public function setUp() + public function setUp(): void { $this->handler = $this->prophesize(RequestHandlerInterface::class); $this->em = $this->prophesize(EntityManagerInterface::class); diff --git a/module/Common/test/Middleware/IpAddressMiddlewareFactoryTest.php b/module/Common/test/Middleware/IpAddressMiddlewareFactoryTest.php index 4c744b7c..bb93593e 100644 --- a/module/Common/test/Middleware/IpAddressMiddlewareFactoryTest.php +++ b/module/Common/test/Middleware/IpAddressMiddlewareFactoryTest.php @@ -13,7 +13,7 @@ class IpAddressMiddlewareFactoryTest extends TestCase { private $factory; - public function setUp() + public function setUp(): void { $this->factory = new IpAddressMiddlewareFactory(); } diff --git a/module/Common/test/Middleware/LocaleMiddlewareTest.php b/module/Common/test/Middleware/LocaleMiddlewareTest.php index 2329d915..0cac4546 100644 --- a/module/Common/test/Middleware/LocaleMiddlewareTest.php +++ b/module/Common/test/Middleware/LocaleMiddlewareTest.php @@ -16,7 +16,7 @@ class LocaleMiddlewareTest extends TestCase /** @var Translator */ private $translator; - public function setUp() + public function setUp(): void { $this->translator = Translator::factory(['locale' => 'ru']); $this->middleware = new LocaleMiddleware($this->translator); diff --git a/module/Common/test/Paginator/PaginableRepositoryAdapterTest.php b/module/Common/test/Paginator/PaginableRepositoryAdapterTest.php index 7b0de03b..b39b3573 100644 --- a/module/Common/test/Paginator/PaginableRepositoryAdapterTest.php +++ b/module/Common/test/Paginator/PaginableRepositoryAdapterTest.php @@ -15,7 +15,7 @@ class PaginableRepositoryAdapterTest extends TestCase /** @var ObjectProphecy */ private $repo; - public function setUp() + public function setUp(): void { $this->repo = $this->prophesize(PaginableRepositoryInterface::class); $this->adapter = new PaginableRepositoryAdapter($this->repo->reveal(), 'search', ['foo', 'bar'], 'order'); diff --git a/module/Common/test/Response/PixelResponseTest.php b/module/Common/test/Response/PixelResponseTest.php index 51f0bc5a..62e83f0d 100644 --- a/module/Common/test/Response/PixelResponseTest.php +++ b/module/Common/test/Response/PixelResponseTest.php @@ -11,7 +11,7 @@ class PixelResponseTest extends TestCase /** @var PixelResponse */ private $resp; - public function setUp() + public function setUp(): void { $this->resp = new PixelResponse(); } diff --git a/module/Common/test/Service/PreviewGeneratorTest.php b/module/Common/test/Service/PreviewGeneratorTest.php index 8e3a779c..ad961ca3 100644 --- a/module/Common/test/Service/PreviewGeneratorTest.php +++ b/module/Common/test/Service/PreviewGeneratorTest.php @@ -7,6 +7,7 @@ use mikehaertl\wkhtmlto\Image; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; +use Shlinkio\Shlink\Common\Exception\PreviewGenerationException; use Shlinkio\Shlink\Common\Image\ImageBuilder; use Shlinkio\Shlink\Common\Service\PreviewGenerator; use Symfony\Component\Filesystem\Filesystem; @@ -23,7 +24,7 @@ class PreviewGeneratorTest extends TestCase /** @var ObjectProphecy */ private $filesystem; - public function setUp() + public function setUp(): void { $this->image = $this->prophesize(Image::class); $this->filesystem = $this->prophesize(Filesystem::class); @@ -66,10 +67,7 @@ class PreviewGeneratorTest extends TestCase $this->assertEquals($expectedPath, $this->generator->generatePreview($url)); } - /** - * @test - * @expectedException \Shlinkio\Shlink\Common\Exception\PreviewGenerationException - */ + /** @test */ public function errorWhileGeneratingPreviewThrowsException() { $url = 'http://foo.com'; @@ -82,6 +80,8 @@ class PreviewGeneratorTest extends TestCase $this->image->saveAs($expectedPath)->shouldBeCalledOnce(); $this->image->getError()->willReturn('Error!!')->shouldBeCalledOnce(); + $this->expectException(PreviewGenerationException::class); + $this->generator->generatePreview($url); } } diff --git a/module/Common/test/Template/Extension/TranslatorExtensionTest.php b/module/Common/test/Template/Extension/TranslatorExtensionTest.php index dd3462bc..06deaa21 100644 --- a/module/Common/test/Template/Extension/TranslatorExtensionTest.php +++ b/module/Common/test/Template/Extension/TranslatorExtensionTest.php @@ -14,7 +14,7 @@ class TranslatorExtensionTest extends TestCase /** @var TranslatorExtension */ private $extension; - public function setUp() + public function setUp(): void { $this->extension = new TranslatorExtension($this->prophesize(Translator::class)->reveal()); } diff --git a/module/Common/test/Type/ChronosDateTimeTypeTest.php b/module/Common/test/Type/ChronosDateTimeTypeTest.php index 1c4e0d6c..e3744d82 100644 --- a/module/Common/test/Type/ChronosDateTimeTypeTest.php +++ b/module/Common/test/Type/ChronosDateTimeTypeTest.php @@ -19,7 +19,7 @@ class ChronosDateTimeTypeTest extends TestCase /** @var ChronosDateTimeType */ private $type; - public function setUp() + public function setUp(): void { if (! Type::hasType(ChronosDateTimeType::CHRONOS_DATETIME)) { Type::addType(ChronosDateTimeType::CHRONOS_DATETIME, ChronosDateTimeType::class); diff --git a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php index ae42e813..fdca0e87 100644 --- a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php @@ -25,7 +25,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase /** @var ShortUrlRepository */ private $repo; - public function setUp() + public function setUp(): void { $this->repo = $this->getEntityManager()->getRepository(ShortUrl::class); } diff --git a/module/Core/test-db/Repository/TagRepositoryTest.php b/module/Core/test-db/Repository/TagRepositoryTest.php index fb43bfe1..9f25cabd 100644 --- a/module/Core/test-db/Repository/TagRepositoryTest.php +++ b/module/Core/test-db/Repository/TagRepositoryTest.php @@ -16,7 +16,7 @@ class TagRepositoryTest extends DatabaseTestCase /** @var TagRepository */ private $repo; - protected function setUp() + protected function setUp(): void { $this->repo = $this->getEntityManager()->getRepository(Tag::class); } diff --git a/module/Core/test-db/Repository/VisitRepositoryTest.php b/module/Core/test-db/Repository/VisitRepositoryTest.php index ed059a37..a9ee6f35 100644 --- a/module/Core/test-db/Repository/VisitRepositoryTest.php +++ b/module/Core/test-db/Repository/VisitRepositoryTest.php @@ -24,7 +24,7 @@ class VisitRepositoryTest extends DatabaseTestCase /** @var VisitRepository */ private $repo; - protected function setUp() + protected function setUp(): void { $this->repo = $this->getEntityManager()->getRepository(Visit::class); } diff --git a/module/Core/test/Action/PixelActionTest.php b/module/Core/test/Action/PixelActionTest.php index 363a6a88..7914a2e9 100644 --- a/module/Core/test/Action/PixelActionTest.php +++ b/module/Core/test/Action/PixelActionTest.php @@ -25,7 +25,7 @@ class PixelActionTest extends TestCase /** @var ObjectProphecy */ private $visitTracker; - public function setUp() + public function setUp(): void { $this->urlShortener = $this->prophesize(UrlShortener::class); $this->visitTracker = $this->prophesize(VisitsTracker::class); diff --git a/module/Core/test/Action/PreviewActionTest.php b/module/Core/test/Action/PreviewActionTest.php index ec935433..56536a38 100644 --- a/module/Core/test/Action/PreviewActionTest.php +++ b/module/Core/test/Action/PreviewActionTest.php @@ -30,7 +30,7 @@ class PreviewActionTest extends TestCase /** @var ObjectProphecy */ private $urlShortener; - public function setUp() + public function setUp(): void { $this->previewGenerator = $this->prophesize(PreviewGenerator::class); $this->urlShortener = $this->prophesize(UrlShortener::class); diff --git a/module/Core/test/Action/QrCodeActionTest.php b/module/Core/test/Action/QrCodeActionTest.php index d3e0e924..a118451d 100644 --- a/module/Core/test/Action/QrCodeActionTest.php +++ b/module/Core/test/Action/QrCodeActionTest.php @@ -25,7 +25,7 @@ class QrCodeActionTest extends TestCase /** @var ObjectProphecy */ private $urlShortener; - public function setUp() + public function setUp(): void { $router = $this->prophesize(RouterInterface::class); $router->generateUri(Argument::cetera())->willReturn('/foo/bar'); diff --git a/module/Core/test/Action/RedirectActionTest.php b/module/Core/test/Action/RedirectActionTest.php index 57f69d52..a35550f6 100644 --- a/module/Core/test/Action/RedirectActionTest.php +++ b/module/Core/test/Action/RedirectActionTest.php @@ -28,7 +28,7 @@ class RedirectActionTest extends TestCase /** @var Options\NotFoundShortUrlOptions */ private $notFoundOptions; - public function setUp() + public function setUp(): void { $this->urlShortener = $this->prophesize(UrlShortener::class); $this->visitTracker = $this->prophesize(VisitsTracker::class); diff --git a/module/Core/test/ConfigProviderTest.php b/module/Core/test/ConfigProviderTest.php index 1c21f2cb..d271e929 100644 --- a/module/Core/test/ConfigProviderTest.php +++ b/module/Core/test/ConfigProviderTest.php @@ -11,7 +11,7 @@ class ConfigProviderTest extends TestCase /** @var ConfigProvider */ private $configProvider; - public function setUp() + public function setUp(): void { $this->configProvider = new ConfigProvider(); } diff --git a/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php b/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php index e9f9cbed..5b7bd00c 100644 --- a/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php +++ b/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php @@ -20,7 +20,7 @@ class QrCodeCacheMiddlewareTest extends TestCase /** @var Cache */ private $cache; - public function setUp() + public function setUp(): void { $this->cache = new ArrayCache(); $this->middleware = new QrCodeCacheMiddleware($this->cache); diff --git a/module/Core/test/Response/NotFoundHandlerTest.php b/module/Core/test/Response/NotFoundHandlerTest.php index 4bf34664..5c32fb0f 100644 --- a/module/Core/test/Response/NotFoundHandlerTest.php +++ b/module/Core/test/Response/NotFoundHandlerTest.php @@ -19,7 +19,7 @@ class NotFoundHandlerTest extends TestCase /** @var ObjectProphecy */ private $renderer; - public function setUp() + public function setUp(): void { $this->renderer = $this->prophesize(TemplateRendererInterface::class); $this->delegate = new NotFoundHandler($this->renderer->reveal()); diff --git a/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php b/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php index 36c52e01..ee6178b1 100644 --- a/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php +++ b/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php @@ -25,7 +25,7 @@ class DeleteShortUrlServiceTest extends TestCase /** @var ObjectProphecy */ private $em; - public function setUp() + public function setUp(): void { $shortUrl = (new ShortUrl(''))->setShortCode('abc123') ->setVisits(new ArrayCollection(map(range(0, 10), function () { diff --git a/module/Core/test/Service/ShortUrlServiceTest.php b/module/Core/test/Service/ShortUrlServiceTest.php index 1c21afae..88391a83 100644 --- a/module/Core/test/Service/ShortUrlServiceTest.php +++ b/module/Core/test/Service/ShortUrlServiceTest.php @@ -24,7 +24,7 @@ class ShortUrlServiceTest extends TestCase /** @var ObjectProphecy|EntityManagerInterface */ private $em; - public function setUp() + public function setUp(): void { $this->em = $this->prophesize(EntityManagerInterface::class); $this->em->persist(Argument::any())->willReturn(null); diff --git a/module/Core/test/Service/Tag/TagServiceTest.php b/module/Core/test/Service/Tag/TagServiceTest.php index 3ecc7542..32f3e036 100644 --- a/module/Core/test/Service/Tag/TagServiceTest.php +++ b/module/Core/test/Service/Tag/TagServiceTest.php @@ -21,7 +21,7 @@ class TagServiceTest extends TestCase /** @var ObjectProphecy */ private $em; - public function setUp() + public function setUp(): void { $this->em = $this->prophesize(EntityManagerInterface::class); $this->service = new TagService($this->em->reveal()); diff --git a/module/Core/test/Service/UrlShortenerTest.php b/module/Core/test/Service/UrlShortenerTest.php index 61dab2c9..83c3c223 100644 --- a/module/Core/test/Service/UrlShortenerTest.php +++ b/module/Core/test/Service/UrlShortenerTest.php @@ -17,7 +17,10 @@ use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Tag; +use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; +use Shlinkio\Shlink\Core\Exception\InvalidUrlException; use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException; +use Shlinkio\Shlink\Core\Exception\RuntimeException; use Shlinkio\Shlink\Core\Model\ShortUrlMeta; use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Repository\ShortUrlRepository; @@ -80,10 +83,7 @@ class UrlShortenerTest extends TestCase $this->assertEquals('0Q1Y', $shortUrl->getShortCode()); } - /** - * @test - * @expectedException \Shlinkio\Shlink\Core\Exception\RuntimeException - */ + /** @test */ public function exceptionIsThrownWhenOrmThrowsException(): void { $conn = $this->prophesize(Connection::class); @@ -93,6 +93,8 @@ class UrlShortenerTest extends TestCase $this->em->close()->shouldBeCalledOnce(); $this->em->flush()->willThrow(new ORMException()); + + $this->expectException(RuntimeException::class); $this->urlShortener->urlToShortCode( new Uri('http://foobar.com/12345/hello?foo=bar'), [], @@ -100,10 +102,7 @@ class UrlShortenerTest extends TestCase ); } - /** - * @test - * @expectedException \Shlinkio\Shlink\Core\Exception\InvalidUrlException - */ + /** @test */ public function exceptionIsThrownWhenUrlDoesNotExist(): void { $this->setUrlShortener(true); @@ -111,6 +110,8 @@ class UrlShortenerTest extends TestCase $this->httpClient->request(Argument::cetera())->willThrow( new ClientException('', $this->prophesize(Request::class)->reveal()) ); + + $this->expectException(InvalidUrlException::class); $this->urlShortener->urlToShortCode( new Uri('http://foobar.com/12345/hello?foo=bar'), [], @@ -227,12 +228,10 @@ class UrlShortenerTest extends TestCase $this->assertSame($shortUrl, $url); } - /** - * @test - * @expectedException \Shlinkio\Shlink\Core\Exception\InvalidShortCodeException - */ + /** @test */ public function invalidCharSetThrowsException(): void { + $this->expectException(InvalidShortCodeException::class); $this->urlShortener->shortCodeToUrl('&/('); } } diff --git a/module/Core/test/Service/VisitServiceTest.php b/module/Core/test/Service/VisitServiceTest.php index 49e3b1e9..8d8753f0 100644 --- a/module/Core/test/Service/VisitServiceTest.php +++ b/module/Core/test/Service/VisitServiceTest.php @@ -25,7 +25,7 @@ class VisitServiceTest extends TestCase /** @var ObjectProphecy */ private $em; - public function setUp() + public function setUp(): void { $this->em = $this->prophesize(EntityManager::class); $this->visitService = new VisitService($this->em->reveal()); diff --git a/module/Core/test/Service/VisitsTrackerTest.php b/module/Core/test/Service/VisitsTrackerTest.php index 3df44880..a39b4c82 100644 --- a/module/Core/test/Service/VisitsTrackerTest.php +++ b/module/Core/test/Service/VisitsTrackerTest.php @@ -25,7 +25,7 @@ class VisitsTrackerTest extends TestCase /** @var ObjectProphecy */ private $em; - public function setUp() + public function setUp(): void { $this->em = $this->prophesize(EntityManager::class); $this->visitsTracker = new VisitsTracker($this->em->reveal()); diff --git a/module/Rest/test/Action/AuthenticateActionTest.php b/module/Rest/test/Action/AuthenticateActionTest.php index 5ce5a313..5f10f4b1 100644 --- a/module/Rest/test/Action/AuthenticateActionTest.php +++ b/module/Rest/test/Action/AuthenticateActionTest.php @@ -22,7 +22,7 @@ class AuthenticateActionTest extends TestCase /** @var ObjectProphecy */ private $jwtService; - public function setUp() + public function setUp(): void { $this->apiKeyService = $this->prophesize(ApiKeyService::class); $this->jwtService = $this->prophesize(JWTService::class); diff --git a/module/Rest/test/Action/HealthActionFactoryTest.php b/module/Rest/test/Action/HealthActionFactoryTest.php index e5130d62..c16bb4c5 100644 --- a/module/Rest/test/Action/HealthActionFactoryTest.php +++ b/module/Rest/test/Action/HealthActionFactoryTest.php @@ -16,7 +16,7 @@ class HealthActionFactoryTest extends TestCase /** @var Action\HealthActionFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new Action\HealthActionFactory(); } diff --git a/module/Rest/test/Action/HealthActionTest.php b/module/Rest/test/Action/HealthActionTest.php index efca74b4..2e9a5e91 100644 --- a/module/Rest/test/Action/HealthActionTest.php +++ b/module/Rest/test/Action/HealthActionTest.php @@ -19,7 +19,7 @@ class HealthActionTest extends TestCase /** @var ObjectProphecy */ private $conn; - public function setUp() + public function setUp(): void { $this->conn = $this->prophesize(Connection::class); $this->action = new HealthAction($this->conn->reveal(), new AppOptions(['version' => '1.2.3'])); diff --git a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php index 7c84388d..edc64fb0 100644 --- a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php @@ -25,7 +25,7 @@ class CreateShortUrlActionTest extends TestCase /** @var ObjectProphecy */ private $urlShortener; - public function setUp() + public function setUp(): void { $this->urlShortener = $this->prophesize(UrlShortener::class); $this->action = new CreateShortUrlAction($this->urlShortener->reveal(), [ @@ -97,7 +97,7 @@ class CreateShortUrlActionTest extends TestCase ]); $response = $this->action->handle($request); $this->assertEquals(400, $response->getStatusCode()); - $this->assertContains(RestUtils::INVALID_SLUG_ERROR, (string) $response->getBody()); + $this->assertStringContainsString(RestUtils::INVALID_SLUG_ERROR, (string) $response->getBody()); } /** diff --git a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php index 725da352..dc928cb8 100644 --- a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php @@ -21,7 +21,7 @@ class DeleteShortUrlActionTest extends TestCase /** @var ObjectProphecy */ private $service; - public function setUp() + public function setUp(): void { $this->service = $this->prophesize(DeleteShortUrlServiceInterface::class); $this->action = new DeleteShortUrlAction($this->service->reveal()); diff --git a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php index 9f4832b5..05c94f40 100644 --- a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php @@ -21,7 +21,7 @@ class EditShortUrlActionTest extends TestCase /** @var ObjectProphecy */ private $shortUrlService; - public function setUp() + public function setUp(): void { $this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class); $this->action = new EditShortUrlAction($this->shortUrlService->reveal()); diff --git a/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php index 006dd83d..bd815c76 100644 --- a/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php @@ -18,7 +18,7 @@ class EditShortUrlTagsActionTest extends TestCase /** @var ObjectProphecy */ private $shortUrlService; - public function setUp() + public function setUp(): void { $this->shortUrlService = $this->prophesize(ShortUrlService::class); $this->action = new EditShortUrlTagsAction($this->shortUrlService->reveal()); diff --git a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php index 397de2c8..953c6277 100644 --- a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php @@ -19,7 +19,7 @@ class ListShortUrlsActionTest extends TestCase /** @var ObjectProphecy */ private $service; - public function setUp() + public function setUp(): void { $this->service = $this->prophesize(ShortUrlService::class); $this->action = new ListShortUrlsAction($this->service->reveal(), [ diff --git a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php index e1229e81..c5692456 100644 --- a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php @@ -22,7 +22,7 @@ class ResolveShortUrlActionTest extends TestCase /** @var ObjectProphecy */ private $urlShortener; - public function setUp() + public function setUp(): void { $this->urlShortener = $this->prophesize(UrlShortener::class); $this->action = new ResolveShortUrlAction($this->urlShortener->reveal(), []); diff --git a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php index 7a7dc4d7..673c8e29 100644 --- a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php @@ -25,7 +25,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase /** @var ObjectProphecy */ private $apiKeyService; - public function setUp() + public function setUp(): void { $this->urlShortener = $this->prophesize(UrlShortenerInterface::class); $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); diff --git a/module/Rest/test/Action/Tag/CreateTagsActionTest.php b/module/Rest/test/Action/Tag/CreateTagsActionTest.php index 9094cbfd..78907a68 100644 --- a/module/Rest/test/Action/Tag/CreateTagsActionTest.php +++ b/module/Rest/test/Action/Tag/CreateTagsActionTest.php @@ -18,7 +18,7 @@ class CreateTagsActionTest extends TestCase /** @var ObjectProphecy */ private $tagService; - public function setUp() + public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); $this->action = new CreateTagsAction($this->tagService->reveal()); diff --git a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php index 03869339..8eaac2ee 100644 --- a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php +++ b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php @@ -17,7 +17,7 @@ class DeleteTagsActionTest extends TestCase /** @var ObjectProphecy */ private $tagService; - public function setUp() + public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); $this->action = new DeleteTagsAction($this->tagService->reveal()); diff --git a/module/Rest/test/Action/Tag/ListTagsActionTest.php b/module/Rest/test/Action/Tag/ListTagsActionTest.php index 8004c550..0221931a 100644 --- a/module/Rest/test/Action/Tag/ListTagsActionTest.php +++ b/module/Rest/test/Action/Tag/ListTagsActionTest.php @@ -19,7 +19,7 @@ class ListTagsActionTest extends TestCase /** @var ObjectProphecy */ private $tagService; - public function setUp() + public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); $this->action = new ListTagsAction($this->tagService->reveal()); diff --git a/module/Rest/test/Action/Tag/UpdateTagActionTest.php b/module/Rest/test/Action/Tag/UpdateTagActionTest.php index cd6f88b6..6819539c 100644 --- a/module/Rest/test/Action/Tag/UpdateTagActionTest.php +++ b/module/Rest/test/Action/Tag/UpdateTagActionTest.php @@ -19,7 +19,7 @@ class UpdateTagActionTest extends TestCase /** @var ObjectProphecy */ private $tagService; - public function setUp() + public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); $this->action = new UpdateTagAction($this->tagService->reveal()); diff --git a/module/Rest/test/Action/Visit/GetVisitsActionTest.php b/module/Rest/test/Action/Visit/GetVisitsActionTest.php index b9a8a0b5..067118de 100644 --- a/module/Rest/test/Action/Visit/GetVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/GetVisitsActionTest.php @@ -23,7 +23,7 @@ class GetVisitsActionTest extends TestCase /** @var ObjectProphecy */ private $visitsTracker; - public function setUp() + public function setUp(): void { $this->visitsTracker = $this->prophesize(VisitsTracker::class); $this->action = new GetVisitsAction($this->visitsTracker->reveal()); diff --git a/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php b/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php index e932deb2..45c07fe6 100644 --- a/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php +++ b/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php @@ -13,7 +13,7 @@ class AuthenticationPluginManagerFactoryTest extends TestCase /** @var AuthenticationPluginManagerFactory */ private $factory; - public function setUp() + public function setUp(): void { $this->factory = new AuthenticationPluginManagerFactory(); } diff --git a/module/Rest/test/Authentication/JWTServiceTest.php b/module/Rest/test/Authentication/JWTServiceTest.php index 962c1665..8f21a14c 100644 --- a/module/Rest/test/Authentication/JWTServiceTest.php +++ b/module/Rest/test/Authentication/JWTServiceTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Rest\Authentication\JWTService; use Shlinkio\Shlink\Rest\Entity\ApiKey; +use Shlinkio\Shlink\Rest\Exception\AuthenticationException; use function time; class JWTServiceTest extends TestCase @@ -15,7 +16,7 @@ class JWTServiceTest extends TestCase /** @var JWTService */ private $service; - public function setUp() + public function setUp(): void { $this->service = new JWTService(new AppOptions([ 'name' => 'ShlinkTest', @@ -83,12 +84,10 @@ class JWTServiceTest extends TestCase $this->assertEquals($originalPayload, $this->service->getPayload($token)); } - /** - * @test - * @expectedException \Shlinkio\Shlink\Rest\Exception\AuthenticationException - */ + /** @test */ public function getPayloadThrowsExceptionWithIncorrectTokens() { + $this->expectException(AuthenticationException::class); $this->service->getPayload('invalidToken'); } } diff --git a/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php b/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php index 7bce54d7..df200601 100644 --- a/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php +++ b/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php @@ -19,7 +19,7 @@ class ApiKeyHeaderPluginTest extends TestCase /** @var ObjectProphecy */ private $apiKeyService; - public function setUp() + public function setUp(): void { $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $this->plugin = new ApiKeyHeaderPlugin($this->apiKeyService->reveal()); diff --git a/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php b/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php index ce0d9234..6f76f595 100644 --- a/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php +++ b/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php @@ -19,7 +19,7 @@ class AuthorizationHeaderPluginTest extends TestCase /** @var ObjectProphecy */ private $jwtService; - public function setUp() + public function setUp(): void { $this->jwtService = $this->prophesize(JWTServiceInterface::class); $this->plugin = new AuthorizationHeaderPlugin($this->jwtService->reveal()); diff --git a/module/Rest/test/Authentication/RequestToAuthPluginTest.php b/module/Rest/test/Authentication/RequestToAuthPluginTest.php index cadaf2e5..61832eb1 100644 --- a/module/Rest/test/Authentication/RequestToAuthPluginTest.php +++ b/module/Rest/test/Authentication/RequestToAuthPluginTest.php @@ -22,7 +22,7 @@ class RequestToAuthPluginTest extends TestCase /** @var ObjectProphecy */ private $pluginManager; - public function setUp() + public function setUp(): void { $this->pluginManager = $this->prophesize(AuthenticationPluginManagerInterface::class); $this->requestToPlugin = new RequestToHttpAuthPlugin($this->pluginManager->reveal()); diff --git a/module/Rest/test/ConfigProviderTest.php b/module/Rest/test/ConfigProviderTest.php index f9fd0b3f..9fafc839 100644 --- a/module/Rest/test/ConfigProviderTest.php +++ b/module/Rest/test/ConfigProviderTest.php @@ -11,7 +11,7 @@ class ConfigProviderTest extends TestCase /** @var ConfigProvider */ private $configProvider; - public function setUp() + public function setUp(): void { $this->configProvider = new ConfigProvider(); } diff --git a/module/Rest/test/ErrorHandler/JsonErrorResponseGeneratorTest.php b/module/Rest/test/ErrorHandler/JsonErrorResponseGeneratorTest.php index 0690586d..3cb288da 100644 --- a/module/Rest/test/ErrorHandler/JsonErrorResponseGeneratorTest.php +++ b/module/Rest/test/ErrorHandler/JsonErrorResponseGeneratorTest.php @@ -13,7 +13,7 @@ class JsonErrorResponseGeneratorTest extends TestCase /** @var JsonErrorResponseGenerator */ private $errorHandler; - public function setUp() + public function setUp(): void { $this->errorHandler = new JsonErrorResponseGenerator(); } diff --git a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php index d553e680..9e079a76 100644 --- a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php +++ b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php @@ -39,7 +39,7 @@ class AuthenticationMiddlewareTest extends TestCase /** @var callable */ private $dummyMiddleware; - public function setUp() + public function setUp(): void { $this->requestToPlugin = $this->prophesize(RequestToHttpAuthPluginInterface::class); $this->middleware = new AuthenticationMiddleware($this->requestToPlugin->reveal(), [AuthenticateAction::class]); diff --git a/module/Rest/test/Middleware/BodyParserMiddlewareTest.php b/module/Rest/test/Middleware/BodyParserMiddlewareTest.php index 8359a044..31adc609 100644 --- a/module/Rest/test/Middleware/BodyParserMiddlewareTest.php +++ b/module/Rest/test/Middleware/BodyParserMiddlewareTest.php @@ -19,7 +19,7 @@ class BodyParserMiddlewareTest extends TestCase /** @var BodyParserMiddleware */ private $middleware; - public function setUp() + public function setUp(): void { $this->middleware = new BodyParserMiddleware(); } diff --git a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php index a96581b8..23e0fc01 100644 --- a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php +++ b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php @@ -18,7 +18,7 @@ class CrossDomainMiddlewareTest extends TestCase /** @var ObjectProphecy */ private $delegate; - public function setUp() + public function setUp(): void { $this->middleware = new CrossDomainMiddleware(); $this->delegate = $this->prophesize(RequestHandlerInterface::class); diff --git a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php index 115602d7..22d2e96d 100644 --- a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php +++ b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php @@ -19,7 +19,7 @@ class PathVersionMiddlewareTest extends TestCase /** @var PathVersionMiddleware */ private $middleware; - public function setUp() + public function setUp(): void { $this->middleware = new PathVersionMiddleware(); } diff --git a/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php index b3f8cf3b..1a97914d 100644 --- a/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php +++ b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php @@ -19,7 +19,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase /** @var RequestHandlerInterface */ private $requestHandler; - public function setUp() + public function setUp(): void { $this->middleware = new CreateShortUrlContentNegotiationMiddleware(); $this->requestHandler = $this->prophesize(RequestHandlerInterface::class); diff --git a/module/Rest/test/Middleware/ShortUrl/ShortCodePathMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/ShortCodePathMiddlewareTest.php index 234f133a..cc71c8f6 100644 --- a/module/Rest/test/Middleware/ShortUrl/ShortCodePathMiddlewareTest.php +++ b/module/Rest/test/Middleware/ShortUrl/ShortCodePathMiddlewareTest.php @@ -18,7 +18,7 @@ class ShortCodePathMiddlewareTest extends TestCase private $middleware; private $requestHandler; - public function setUp() + public function setUp(): void { $this->middleware = new ShortCodePathMiddleware(); $this->requestHandler = $this->prophesize(RequestHandlerInterface::class); @@ -37,8 +37,8 @@ class ShortCodePathMiddlewareTest extends TestCase $withUri = $request->withUri(Argument::that(function (UriInterface $uri) { $path = $uri->getPath(); - Assert::assertContains('/short-urls', $path); - Assert::assertNotContains('/short-codes', $path); + Assert::assertStringContainsString('/short-urls', $path); + Assert::assertStringNotContainsString('/short-codes', $path); return $uri; }))->willReturn($request->reveal()); diff --git a/module/Rest/test/Service/ApiKeyServiceTest.php b/module/Rest/test/Service/ApiKeyServiceTest.php index ae25c032..61335856 100644 --- a/module/Rest/test/Service/ApiKeyServiceTest.php +++ b/module/Rest/test/Service/ApiKeyServiceTest.php @@ -9,6 +9,7 @@ use Doctrine\ORM\EntityRepository; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; +use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Service\ApiKeyService; @@ -19,7 +20,7 @@ class ApiKeyServiceTest extends TestCase /** @var ObjectProphecy */ private $em; - public function setUp() + public function setUp(): void { $this->em = $this->prophesize(EntityManager::class); $this->service = new ApiKeyService($this->em->reveal()); @@ -105,10 +106,7 @@ class ApiKeyServiceTest extends TestCase $this->assertTrue($this->service->check('12345')); } - /** - * @test - * @expectedException \Shlinkio\Shlink\Common\Exception\InvalidArgumentException - */ + /** @test */ public function disableThrowsExceptionWhenNoTokenIsFound() { $repo = $this->prophesize(EntityRepository::class); @@ -116,6 +114,7 @@ class ApiKeyServiceTest extends TestCase ->shouldBeCalledOnce(); $this->em->getRepository(ApiKey::class)->willReturn($repo->reveal()); + $this->expectException(InvalidArgumentException::class); $this->service->disable('12345'); } From ee4db44fe8f77b9fce202c72b7f3c38372637492 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 16 Feb 2019 20:29:43 +0100 Subject: [PATCH 2/2] Fixed phpcov dep not properly resolved on PHP 7.1 envs --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2d12ff9e..a8f78431 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ "filp/whoops": "^2.0", "infection/infection": "^0.11.0", "phpstan/phpstan": "^0.10.0", - "phpunit/phpcov": "dev-master#68702e4ec8563d118a5103b5f49031877692a63c || ^5.0", + "phpunit/phpcov": "^6.0@dev || ^5.0", "phpunit/phpunit": "^8.0 || ^7.5", "roave/security-advisories": "dev-master", "shlinkio/php-coding-standard": "~1.0.0",