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

@@ -25,7 +25,7 @@ class PixelActionTest extends TestCase
/** @var ObjectProphecy */
private $visitTracker;
public function setUp()
public function setUp(): void
{
$this->urlShortener = $this->prophesize(UrlShortener::class);
$this->visitTracker = $this->prophesize(VisitsTracker::class);

View File

@@ -30,7 +30,7 @@ class PreviewActionTest extends TestCase
/** @var ObjectProphecy */
private $urlShortener;
public function setUp()
public function setUp(): void
{
$this->previewGenerator = $this->prophesize(PreviewGenerator::class);
$this->urlShortener = $this->prophesize(UrlShortener::class);

View File

@@ -25,7 +25,7 @@ class QrCodeActionTest extends TestCase
/** @var ObjectProphecy */
private $urlShortener;
public function setUp()
public function setUp(): void
{
$router = $this->prophesize(RouterInterface::class);
$router->generateUri(Argument::cetera())->willReturn('/foo/bar');

View File

@@ -28,7 +28,7 @@ class RedirectActionTest extends TestCase
/** @var Options\NotFoundShortUrlOptions */
private $notFoundOptions;
public function setUp()
public function setUp(): void
{
$this->urlShortener = $this->prophesize(UrlShortener::class);
$this->visitTracker = $this->prophesize(VisitsTracker::class);

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

@@ -20,7 +20,7 @@ class QrCodeCacheMiddlewareTest extends TestCase
/** @var Cache */
private $cache;
public function setUp()
public function setUp(): void
{
$this->cache = new ArrayCache();
$this->middleware = new QrCodeCacheMiddleware($this->cache);

View File

@@ -19,7 +19,7 @@ class NotFoundHandlerTest extends TestCase
/** @var ObjectProphecy */
private $renderer;
public function setUp()
public function setUp(): void
{
$this->renderer = $this->prophesize(TemplateRendererInterface::class);
$this->delegate = new NotFoundHandler($this->renderer->reveal());

View File

@@ -25,7 +25,7 @@ class DeleteShortUrlServiceTest extends TestCase
/** @var ObjectProphecy */
private $em;
public function setUp()
public function setUp(): void
{
$shortUrl = (new ShortUrl(''))->setShortCode('abc123')
->setVisits(new ArrayCollection(map(range(0, 10), function () {

View File

@@ -24,7 +24,7 @@ class ShortUrlServiceTest extends TestCase
/** @var ObjectProphecy|EntityManagerInterface */
private $em;
public function setUp()
public function setUp(): void
{
$this->em = $this->prophesize(EntityManagerInterface::class);
$this->em->persist(Argument::any())->willReturn(null);

View File

@@ -21,7 +21,7 @@ class TagServiceTest extends TestCase
/** @var ObjectProphecy */
private $em;
public function setUp()
public function setUp(): void
{
$this->em = $this->prophesize(EntityManagerInterface::class);
$this->service = new TagService($this->em->reveal());

View File

@@ -17,7 +17,10 @@ use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException;
use Shlinkio\Shlink\Core\Exception\RuntimeException;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Options\UrlShortenerOptions;
use Shlinkio\Shlink\Core\Repository\ShortUrlRepository;
@@ -80,10 +83,7 @@ class UrlShortenerTest extends TestCase
$this->assertEquals('0Q1Y', $shortUrl->getShortCode());
}
/**
* @test
* @expectedException \Shlinkio\Shlink\Core\Exception\RuntimeException
*/
/** @test */
public function exceptionIsThrownWhenOrmThrowsException(): void
{
$conn = $this->prophesize(Connection::class);
@@ -93,6 +93,8 @@ class UrlShortenerTest extends TestCase
$this->em->close()->shouldBeCalledOnce();
$this->em->flush()->willThrow(new ORMException());
$this->expectException(RuntimeException::class);
$this->urlShortener->urlToShortCode(
new Uri('http://foobar.com/12345/hello?foo=bar'),
[],
@@ -100,10 +102,7 @@ class UrlShortenerTest extends TestCase
);
}
/**
* @test
* @expectedException \Shlinkio\Shlink\Core\Exception\InvalidUrlException
*/
/** @test */
public function exceptionIsThrownWhenUrlDoesNotExist(): void
{
$this->setUrlShortener(true);
@@ -111,6 +110,8 @@ class UrlShortenerTest extends TestCase
$this->httpClient->request(Argument::cetera())->willThrow(
new ClientException('', $this->prophesize(Request::class)->reveal())
);
$this->expectException(InvalidUrlException::class);
$this->urlShortener->urlToShortCode(
new Uri('http://foobar.com/12345/hello?foo=bar'),
[],
@@ -227,12 +228,10 @@ class UrlShortenerTest extends TestCase
$this->assertSame($shortUrl, $url);
}
/**
* @test
* @expectedException \Shlinkio\Shlink\Core\Exception\InvalidShortCodeException
*/
/** @test */
public function invalidCharSetThrowsException(): void
{
$this->expectException(InvalidShortCodeException::class);
$this->urlShortener->shortCodeToUrl('&/(');
}
}

View File

@@ -25,7 +25,7 @@ class VisitServiceTest extends TestCase
/** @var ObjectProphecy */
private $em;
public function setUp()
public function setUp(): void
{
$this->em = $this->prophesize(EntityManager::class);
$this->visitService = new VisitService($this->em->reveal());

View File

@@ -25,7 +25,7 @@ class VisitsTrackerTest extends TestCase
/** @var ObjectProphecy */
private $em;
public function setUp()
public function setUp(): void
{
$this->em = $this->prophesize(EntityManager::class);
$this->visitsTracker = new VisitsTracker($this->em->reveal());