Merge pull request #353 from acelaya/feature/testing-tools

Updated testing tools
This commit is contained in:
Alejandro Celaya 2019-02-16 20:50:22 +01:00 committed by GitHub
commit 25927a296d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
91 changed files with 192 additions and 192 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ data/shlink-tests.db
data/GeoLite2-City.mmdb
docs/swagger-ui*
docker-compose.override.yml
.phpunit.result.cache

View file

@ -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

View file

@ -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": "^6.0@dev || ^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": "<fg=blue;options=bold>Runs unit test suites and generates an HTML code coverage report</>",
"infect": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing</>",
"infect:ci": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing with existing reports and logs</>",
"infect:show": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing and shows applied mutators</>"
"infect:show": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing and shows applied mutators</>",
"infect:test": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing</>"
},
"config": {
"sort-packages": true

View file

@ -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();
}
}

View file

@ -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();
}

View file

@ -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);
}
}

View file

@ -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)

View file

@ -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();
}
}

View file

@ -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();

View file

@ -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();
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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
);

View file

@ -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();
}
}

View file

@ -11,7 +11,7 @@ class ConfigProviderTest extends TestCase
/** @var ConfigProvider */
private $configProvider;
public function setUp()
public function setUp(): void
{
$this->configProvider = new ConfigProvider();
}

View file

@ -18,7 +18,7 @@ class ApplicationFactoryTest extends TestCase
/** @var ApplicationFactory */
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new ApplicationFactory();
}

View file

@ -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();

View file

@ -11,7 +11,7 @@ class ConfigProviderTest extends TestCase
/** @var ConfigProvider */
private $configProvider;
public function setUp()
public function setUp(): void
{
$this->configProvider = new ConfigProvider();
}

View file

@ -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());

View file

@ -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');
}

View file

@ -14,7 +14,7 @@ class DottedAccessConfigAbstractFactoryTest extends TestCase
/** @var DottedAccessConfigAbstractFactory */
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new DottedAccessConfigAbstractFactory();
}

View file

@ -15,7 +15,7 @@ class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
/** @var EmptyResponseImplicitOptionsMiddlewareFactory */
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new EmptyResponseImplicitOptionsMiddlewareFactory();
}

View file

@ -13,7 +13,7 @@ class EntityManagerFactoryTest extends TestCase
/** @var EntityManagerFactory */
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new EntityManagerFactory();
}

View file

@ -14,7 +14,7 @@ class LoggerFactoryTest extends TestCase
/** @var LoggerFactory */
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new LoggerFactory();
}

View file

@ -13,7 +13,7 @@ class TranslatorFactoryTest extends TestCase
/** @var TranslatorFactory */
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new TranslatorFactory();
}

View file

@ -13,7 +13,7 @@ class ImageBuilderFactoryTest extends TestCase
/** @var ImageBuilderFactory */
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new ImageBuilderFactory();
}

View file

@ -14,7 +14,7 @@ class ImageFactoryTest extends TestCase
/** @var ImageFactory */
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new ImageFactory();
}

View file

@ -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);

View file

@ -26,7 +26,7 @@ class EmptyIpLocationResolverTest extends TestCase
/** @var EmptyIpLocationResolver */
private $resolver;
public function setUp()
public function setUp(): void
{
$this->resolver = new EmptyIpLocationResolver();
}

View file

@ -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);

View file

@ -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());

View file

@ -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');
}
}

View file

@ -12,7 +12,7 @@ class ExceptionWithNewLineProcessorTest extends TestCase
/** @var ExceptionWithNewLineProcessor */
private $processor;
public function setUp()
public function setUp(): void
{
$this->processor = new ExceptionWithNewLineProcessor();
}

View file

@ -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);

View file

@ -13,7 +13,7 @@ class IpAddressMiddlewareFactoryTest extends TestCase
{
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new IpAddressMiddlewareFactory();
}

View file

@ -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);

View file

@ -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');

View file

@ -11,7 +11,7 @@ class PixelResponseTest extends TestCase
/** @var PixelResponse */
private $resp;
public function setUp()
public function setUp(): void
{
$this->resp = new PixelResponse();
}

View file

@ -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);
}
}

View file

@ -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());
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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);

View file

@ -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');

View file

@ -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);

View file

@ -11,7 +11,7 @@ class ConfigProviderTest extends TestCase
/** @var ConfigProvider */
private $configProvider;
public function setUp()
public function setUp(): void
{
$this->configProvider = new ConfigProvider();
}

View file

@ -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);

View file

@ -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());

View file

@ -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 () {

View file

@ -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);

View file

@ -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());

View file

@ -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('&/(');
}
}

View file

@ -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());

View file

@ -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());

View file

@ -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);

View file

@ -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();
}

View file

@ -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']));

View file

@ -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());
}
/**

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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(), [

View file

@ -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(), []);

View file

@ -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);

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -13,7 +13,7 @@ class AuthenticationPluginManagerFactoryTest extends TestCase
/** @var AuthenticationPluginManagerFactory */
private $factory;
public function setUp()
public function setUp(): void
{
$this->factory = new AuthenticationPluginManagerFactory();
}

View file

@ -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');
}
}

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -11,7 +11,7 @@ class ConfigProviderTest extends TestCase
/** @var ConfigProvider */
private $configProvider;
public function setUp()
public function setUp(): void
{
$this->configProvider = new ConfigProvider();
}

View file

@ -13,7 +13,7 @@ class JsonErrorResponseGeneratorTest extends TestCase
/** @var JsonErrorResponseGenerator */
private $errorHandler;
public function setUp()
public function setUp(): void
{
$this->errorHandler = new JsonErrorResponseGenerator();
}

View file

@ -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]);

View file

@ -19,7 +19,7 @@ class BodyParserMiddlewareTest extends TestCase
/** @var BodyParserMiddleware */
private $middleware;
public function setUp()
public function setUp(): void
{
$this->middleware = new BodyParserMiddleware();
}

View file

@ -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);

View file

@ -19,7 +19,7 @@ class PathVersionMiddlewareTest extends TestCase
/** @var PathVersionMiddleware */
private $middleware;
public function setUp()
public function setUp(): void
{
$this->middleware = new PathVersionMiddleware();
}

View file

@ -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);

View file

@ -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());

View file

@ -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');
}