Fixed tests

This commit is contained in:
Alejandro Celaya
2018-03-26 19:02:41 +02:00
parent 16dd1838aa
commit a27b01b895
25 changed files with 104 additions and 148 deletions

View File

@@ -10,7 +10,6 @@ use Shlinkio\Shlink\Rest\Action\AuthenticateAction;
use Shlinkio\Shlink\Rest\Authentication\JWTService;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use Shlinkio\Shlink\Rest\Service\ApiKeyService;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
@@ -47,7 +46,7 @@ class AuthenticateActionTest extends TestCase
*/
public function notProvidingAuthDataReturnsError()
{
$resp = $this->action->process(ServerRequestFactory::fromGlobals(), TestUtils::createDelegateMock()->reveal());
$resp = $this->action->handle(ServerRequestFactory::fromGlobals());
$this->assertEquals(400, $resp->getStatusCode());
}
@@ -62,7 +61,7 @@ class AuthenticateActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'apiKey' => 'foo',
]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(200, $response->getStatusCode());
$response->getBody()->rewind();
@@ -80,7 +79,7 @@ class AuthenticateActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'apiKey' => 'foo',
]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(401, $response->getStatusCode());
}
}

View File

@@ -11,7 +11,6 @@ use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException;
use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Rest\Action\CreateShortcodeAction;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Uri;
use Zend\I18n\Translator\Translator;
@@ -41,10 +40,7 @@ class CreateShortcodeActionTest extends TestCase
*/
public function missingLongUrlParamReturnsError()
{
$response = $this->action->process(
ServerRequestFactory::fromGlobals(),
TestUtils::createDelegateMock()->reveal()
);
$response = $this->action->handle(ServerRequestFactory::fromGlobals());
$this->assertEquals(400, $response->getStatusCode());
}
@@ -60,7 +56,7 @@ class CreateShortcodeActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), 'http://foo.com/abc123') > 0);
}
@@ -77,7 +73,7 @@ class CreateShortcodeActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(400, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_URL_ERROR) > 0);
}
@@ -100,7 +96,7 @@ class CreateShortcodeActionTest extends TestCase
'longUrl' => 'http://www.domain.com/foo/bar',
'customSlug' => 'foo',
]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(400, $response->getStatusCode());
$this->assertContains(RestUtils::INVALID_SLUG_ERROR, (string) $response->getBody());
}
@@ -117,7 +113,7 @@ class CreateShortcodeActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0);
}

View File

@@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Rest\Action;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
@@ -43,7 +42,7 @@ class EditShortCodeActionTest extends TestCase
]);
/** @var JsonResponse $resp */
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal());
$resp = $this->action->handle($request);
$payload = $resp->getPayload();
$this->assertEquals(400, $resp->getStatusCode());
@@ -65,7 +64,7 @@ class EditShortCodeActionTest extends TestCase
);
/** @var JsonResponse $resp */
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal());
$resp = $this->action->handle($request);
$payload = $resp->getPayload();
$this->assertEquals(404, $resp->getStatusCode());
@@ -85,7 +84,7 @@ class EditShortCodeActionTest extends TestCase
]);
$updateMeta = $this->shortUrlService->updateMetadataByShortCode(Argument::cetera())->willReturn(new ShortUrl());
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal());
$resp = $this->action->handle($request);
$this->assertEquals(204, $resp->getStatusCode());
$updateMeta->shouldHaveBeenCalled();

View File

@@ -9,7 +9,6 @@ use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\EditShortcodeTagsAction;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
@@ -35,10 +34,7 @@ class EditShortcodeTagsActionTest extends TestCase
*/
public function notProvidingTagsReturnsError()
{
$response = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123'),
TestUtils::createDelegateMock()->reveal()
);
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123'));
$this->assertEquals(400, $response->getStatusCode());
}
@@ -51,10 +47,9 @@ class EditShortcodeTagsActionTest extends TestCase
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
$response = $this->action->process(
$response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')
->withParsedBody(['tags' => []]),
TestUtils::createDelegateMock()->reveal()
->withParsedBody(['tags' => []])
);
$this->assertEquals(404, $response->getStatusCode());
}
@@ -68,10 +63,9 @@ class EditShortcodeTagsActionTest extends TestCase
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl())
->shouldBeCalledTimes(1);
$response = $this->action->process(
$response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')
->withParsedBody(['tags' => []]),
TestUtils::createDelegateMock()->reveal()
->withParsedBody(['tags' => []])
);
$this->assertEquals(200, $response->getStatusCode());
}

View File

@@ -10,7 +10,6 @@ use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Service\VisitsTracker;
use Shlinkio\Shlink\Rest\Action\GetVisitsAction;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
@@ -40,10 +39,7 @@ class GetVisitsActionTest extends TestCase
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willReturn([])
->shouldBeCalledTimes(1);
$response = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
TestUtils::createDelegateMock()->reveal()
);
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(200, $response->getStatusCode());
}
@@ -57,10 +53,7 @@ class GetVisitsActionTest extends TestCase
InvalidArgumentException::class
)->shouldBeCalledTimes(1);
$response = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
TestUtils::createDelegateMock()->reveal()
);
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(404, $response->getStatusCode());
}
@@ -74,10 +67,7 @@ class GetVisitsActionTest extends TestCase
\Exception::class
)->shouldBeCalledTimes(1);
$response = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
TestUtils::createDelegateMock()->reveal()
);
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(500, $response->getStatusCode());
}
@@ -91,10 +81,9 @@ class GetVisitsActionTest extends TestCase
->willReturn([])
->shouldBeCalledTimes(1);
$response = $this->action->process(
$response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)
->withQueryParams(['endDate' => '2016-01-01 00:00:00']),
TestUtils::createDelegateMock()->reveal()
->withQueryParams(['endDate' => '2016-01-01 00:00:00'])
);
$this->assertEquals(200, $response->getStatusCode());
}

View File

@@ -7,7 +7,6 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\ListShortcodesAction;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
use Zend\Paginator\Adapter\ArrayAdapter;
@@ -39,12 +38,9 @@ class ListShortCodesActionTest extends TestCase
$this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1);
$response = $this->action->process(
ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
]),
TestUtils::createDelegateMock()->reveal()
);
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
]));
$this->assertEquals(200, $response->getStatusCode());
}
@@ -57,12 +53,9 @@ class ListShortCodesActionTest extends TestCase
$this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class)
->shouldBeCalledTimes(1);
$response = $this->action->process(
ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
]),
TestUtils::createDelegateMock()->reveal()
);
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
]));
$this->assertEquals(500, $response->getStatusCode());
}
}

View File

@@ -10,7 +10,6 @@ use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Rest\Action\ResolveUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
@@ -41,7 +40,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(404, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_ARGUMENT_ERROR) > 0);
}
@@ -56,7 +55,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), 'http://domain.com/foo/bar') > 0);
}
@@ -71,7 +70,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(400, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_SHORTCODE_ERROR) > 0);
}
@@ -86,7 +85,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$response = $this->action->handle($request);
$this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0);
}

View File

@@ -7,7 +7,6 @@ use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\CreateTagsAction;
use Zend\Diactoros\ServerRequestFactory;
@@ -40,7 +39,7 @@ class CreateTagsActionTest extends TestCase
/** @var MethodProphecy $deleteTags */
$deleteTags = $this->tagService->createTags($tags ?: [])->willReturn(new ArrayCollection());
$response = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal());
$response = $this->action->handle($request);
$this->assertEquals(200, $response->getStatusCode());
$deleteTags->shouldHaveBeenCalled();

View File

@@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Rest\Action\Tag;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\DeleteTagsAction;
use Zend\Diactoros\ServerRequestFactory;
@@ -39,7 +38,7 @@ class DeleteTagsActionTest extends TestCase
/** @var MethodProphecy $deleteTags */
$deleteTags = $this->tagService->deleteTags($tags ?: []);
$response = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal());
$response = $this->action->handle($request);
$this->assertEquals(204, $response->getStatusCode());
$deleteTags->shouldHaveBeenCalled();

View File

@@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Rest\Action\Tag;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\ListTagsAction;
@@ -37,10 +36,7 @@ class ListTagsActionTest extends TestCase
/** @var MethodProphecy $listTags */
$listTags = $this->tagService->listTags()->willReturn([new Tag('foo'), new Tag('bar')]);
$resp = $this->action->process(
ServerRequestFactory::fromGlobals(),
$this->prophesize(DelegateInterface::class)->reveal()
);
$resp = $this->action->handle(ServerRequestFactory::fromGlobals());
$this->assertEquals([
'tags' => [

View File

@@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Rest\Action\Tag;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
@@ -39,7 +38,7 @@ class UpdateTagActionTest extends TestCase
public function whenInvalidParamsAreProvidedAnErrorIsReturned(array $bodyParams)
{
$request = ServerRequestFactory::fromGlobals()->withParsedBody($bodyParams);
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal());
$resp = $this->action->handle($request);
$this->assertEquals(400, $resp->getStatusCode());
}
@@ -65,7 +64,7 @@ class UpdateTagActionTest extends TestCase
/** @var MethodProphecy $rename */
$rename = $this->tagService->renameTag('foo', 'bar')->willThrow(EntityDoesNotExistException::class);
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal());
$resp = $this->action->handle($request);
$this->assertEquals(404, $resp->getStatusCode());
$rename->shouldHaveBeenCalled();
@@ -83,7 +82,7 @@ class UpdateTagActionTest extends TestCase
/** @var MethodProphecy $rename */
$rename = $this->tagService->renameTag('foo', 'bar')->willReturn(new Tag());
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal());
$resp = $this->action->handle($request);
$this->assertEquals(204, $resp->getStatusCode());
$rename->shouldHaveBeenCalled();