mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Improved CreateShortUrlAction test so that it cover more mutants
This commit is contained in:
@@ -4,14 +4,17 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
||||||
|
|
||||||
|
use Cake\Chronos\Chronos;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
use Prophecy\Prophecy\ObjectProphecy;
|
||||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
||||||
|
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
|
||||||
use Shlinkio\Shlink\Core\Service\UrlShortener;
|
use Shlinkio\Shlink\Core\Service\UrlShortener;
|
||||||
use Shlinkio\Shlink\Rest\Action\ShortUrl\CreateShortUrlAction;
|
use Shlinkio\Shlink\Rest\Action\ShortUrl\CreateShortUrlAction;
|
||||||
use Zend\Diactoros\ServerRequest;
|
use Zend\Diactoros\ServerRequest;
|
||||||
|
use Zend\Diactoros\ServerRequestFactory;
|
||||||
use Zend\Diactoros\Uri;
|
use Zend\Diactoros\Uri;
|
||||||
|
|
||||||
use function strpos;
|
use function strpos;
|
||||||
@@ -41,20 +44,41 @@ class CreateShortUrlActionTest extends TestCase
|
|||||||
$this->action->handle(new ServerRequest());
|
$this->action->handle(new ServerRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/**
|
||||||
public function properShortcodeConversionReturnsData(): void
|
* @test
|
||||||
|
* @dataProvider provideRequestBodies
|
||||||
|
*/
|
||||||
|
public function properShortcodeConversionReturnsData(array $body, ShortUrlMeta $expectedMeta): void
|
||||||
{
|
{
|
||||||
$shortUrl = new ShortUrl('');
|
$shortUrl = new ShortUrl('');
|
||||||
$this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'), Argument::cetera())
|
$shorten = $this->urlShortener->urlToShortCode(
|
||||||
->willReturn($shortUrl)
|
Argument::type(Uri::class),
|
||||||
->shouldBeCalledOnce();
|
Argument::type('array'),
|
||||||
|
$expectedMeta
|
||||||
|
)->willReturn($shortUrl);
|
||||||
|
|
||||||
$request = (new ServerRequest())->withParsedBody([
|
$request = ServerRequestFactory::fromGlobals()->withParsedBody($body);
|
||||||
'longUrl' => 'http://www.domain.com/foo/bar',
|
|
||||||
]);
|
|
||||||
$response = $this->action->handle($request);
|
$response = $this->action->handle($request);
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$this->assertTrue(strpos($response->getBody()->getContents(), $shortUrl->toString(self::DOMAIN_CONFIG)) > 0);
|
$this->assertTrue(strpos($response->getBody()->getContents(), $shortUrl->toString(self::DOMAIN_CONFIG)) > 0);
|
||||||
|
$shorten->shouldHaveBeenCalledOnce();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideRequestBodies(): iterable
|
||||||
|
{
|
||||||
|
$fullMeta = [
|
||||||
|
'longUrl' => 'http://www.domain.com/foo/bar',
|
||||||
|
'validSince' => Chronos::now()->toAtomString(),
|
||||||
|
'validUntil' => Chronos::now()->toAtomString(),
|
||||||
|
'customSlug' => 'foo-bar-baz',
|
||||||
|
'maxVisits' => 50,
|
||||||
|
'findIfExists' => true,
|
||||||
|
'domain' => 'my-domain.com',
|
||||||
|
];
|
||||||
|
|
||||||
|
yield [['longUrl' => 'http://www.domain.com/foo/bar'], ShortUrlMeta::createEmpty()];
|
||||||
|
yield [$fullMeta, ShortUrlMeta::createFromRawData($fullMeta)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user