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

@@ -8,7 +8,7 @@ use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Rest\Action\CreateShortcodeAction;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Uri;
use Zend\I18n\Translator\Translator;
@@ -38,7 +38,10 @@ class CreateShortcodeActionTest extends TestCase
*/
public function missingLongUrlParamReturnsError()
{
$response = $this->action->__invoke(ServerRequestFactory::fromGlobals(), new Response());
$response = $this->action->process(
ServerRequestFactory::fromGlobals(),
TestUtils::createDelegateMock()->reveal()
);
$this->assertEquals(400, $response->getStatusCode());
}
@@ -54,7 +57,7 @@ class CreateShortcodeActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
]);
$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://foo.com/abc123') > 0);
}
@@ -71,7 +74,7 @@ class CreateShortcodeActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
]);
$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_URL_ERROR) > 0);
}
@@ -88,7 +91,7 @@ class CreateShortcodeActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
]);
$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);
}