Migrated rest actions to psr-15 middleware

This commit is contained in:
Alejandro Celaya
2017-03-25 10:04:48 +01:00
parent 288249d0b8
commit 2e5a7d76df
13 changed files with 93 additions and 100 deletions

View File

@@ -7,7 +7,7 @@ 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 Zend\Diactoros\Response;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
@@ -38,7 +38,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->__invoke($request, new Response());
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$this->assertEquals(404, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_ARGUMENT_ERROR) > 0);
}
@@ -53,7 +53,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->__invoke($request, new Response());
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), 'http://domain.com/foo/bar') > 0);
}
@@ -68,7 +68,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->__invoke($request, new Response());
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$this->assertEquals(400, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_SHORTCODE_ERROR) > 0);
}
@@ -83,7 +83,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->__invoke($request, new Response());
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal());
$this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0);
}