Updated testing tools

This commit is contained in:
Alejandro Celaya
2019-02-16 10:53:45 +01:00
parent 899bfdce2b
commit b8cb38ae5c
91 changed files with 192 additions and 192 deletions

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