Reduced amount of dead lines in tests

This commit is contained in:
Alejandro Celaya
2019-02-17 20:28:34 +01:00
parent 1bcd03b150
commit 687a1cc9c7
100 changed files with 481 additions and 938 deletions
@@ -39,9 +39,7 @@ class DeleteShortUrlServiceTest extends TestCase
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
}
/**
* @test
*/
/** @test */
public function deleteByShortCodeThrowsExceptionWhenThresholdIsReached()
{
$service = $this->createService();
@@ -54,9 +52,7 @@ class DeleteShortUrlServiceTest extends TestCase
$service->deleteByShortCode('abc123');
}
/**
* @test
*/
/** @test */
public function deleteByShortCodeDeletesUrlWhenThresholdIsReachedButExplicitlyIgnored()
{
$service = $this->createService();
@@ -70,9 +66,7 @@ class DeleteShortUrlServiceTest extends TestCase
$flush->shouldHaveBeenCalledOnce();
}
/**
* @test
*/
/** @test */
public function deleteByShortCodeDeletesUrlWhenThresholdIsReachedButCheckIsDisabled()
{
$service = $this->createService(false);
@@ -86,9 +80,7 @@ class DeleteShortUrlServiceTest extends TestCase
$flush->shouldHaveBeenCalledOnce();
}
/**
* @test
*/
/** @test */
public function deleteByShortCodeDeletesUrlWhenThresholdIsNotReached()
{
$service = $this->createService(true, 100);
@@ -32,9 +32,7 @@ class ShortUrlServiceTest extends TestCase
$this->service = new ShortUrlService($this->em->reveal());
}
/**
* @test
*/
/** @test */
public function listedUrlsAreReturnedFromEntityManager()
{
$list = [
@@ -53,9 +51,7 @@ class ShortUrlServiceTest extends TestCase
$this->assertEquals(4, $list->getCurrentItemCount());
}
/**
* @test
*/
/** @test */
public function exceptionIsThrownWhenSettingTagsOnInvalidShortcode()
{
$shortCode = 'abc123';
@@ -68,9 +64,7 @@ class ShortUrlServiceTest extends TestCase
$this->service->setTagsByShortCode($shortCode);
}
/**
* @test
*/
/** @test */
public function providedTagsAreGetFromRepoAndSetToTheShortUrl()
{
$shortUrl = $this->prophesize(ShortUrl::class);
@@ -89,9 +83,7 @@ class ShortUrlServiceTest extends TestCase
$this->service->setTagsByShortCode($shortCode, ['foo', 'bar']);
}
/**
* @test
*/
/** @test */
public function updateMetadataByShortCodeUpdatesProvidedData()
{
$shortUrl = new ShortUrl('');
@@ -27,9 +27,7 @@ class TagServiceTest extends TestCase
$this->service = new TagService($this->em->reveal());
}
/**
* @test
*/
/** @test */
public function listTagsDelegatesOnRepository()
{
$expected = [new Tag('foo'), new Tag('bar')];
@@ -47,9 +45,7 @@ class TagServiceTest extends TestCase
$getRepo->shouldHaveBeenCalled();
}
/**
* @test
*/
/** @test */
public function deleteTagsDelegatesOnRepository()
{
$repo = $this->prophesize(TagRepository::class);
@@ -64,9 +60,7 @@ class TagServiceTest extends TestCase
$getRepo->shouldHaveBeenCalled();
}
/**
* @test
*/
/** @test */
public function createTagsPersistsEntities()
{
$repo = $this->prophesize(TagRepository::class);
@@ -88,9 +82,7 @@ class TagServiceTest extends TestCase
$flush->shouldHaveBeenCalled();
}
/**
* @test
*/
/** @test */
public function renameInvalidTagThrowsException()
{
$repo = $this->prophesize(TagRepository::class);
@@ -106,9 +98,7 @@ class TagServiceTest extends TestCase
$this->service->renameTag('foo', 'bar');
}
/**
* @test
*/
/** @test */
public function renameValidTagChangesItsName()
{
$expected = new Tag('foo');
+46 -54
View File
@@ -60,7 +60,7 @@ class UrlShortenerTest extends TestCase
$this->setUrlShortener(false);
}
public function setUrlShortener(bool $urlValidationEnabled): void
private function setUrlShortener(bool $urlValidationEnabled): void
{
$this->urlShortener = new UrlShortener(
$this->httpClient->reveal(),
@@ -69,9 +69,7 @@ class UrlShortenerTest extends TestCase
);
}
/**
* @test
*/
/** @test */
public function urlIsProperlyShortened(): void
{
// 10 -> 0Q1Y
@@ -119,9 +117,7 @@ class UrlShortenerTest extends TestCase
);
}
/**
* @test
*/
/** @test */
public function exceptionIsThrownWhenNonUniqueSlugIsProvided(): void
{
$repo = $this->prophesize(ShortUrlRepository::class);
@@ -143,7 +139,7 @@ class UrlShortenerTest extends TestCase
/**
* @test
* @dataProvider provideExsitingShortUrls
* @dataProvider provideExistingShortUrls
*/
public function existingShortUrlIsReturnedWhenRequested(
string $url,
@@ -162,58 +158,54 @@ class UrlShortenerTest extends TestCase
$getRepo->shouldHaveBeenCalledOnce();
}
public function provideExsitingShortUrls(): array
public function provideExistingShortUrls(): iterable
{
$url = 'http://foo.com';
return [
[$url, [], ShortUrlMeta::createFromRawData(['findIfExists' => true]), new ShortUrl($url)],
[$url, [], ShortUrlMeta::createFromRawData(
['findIfExists' => true, 'customSlug' => 'foo']
), new ShortUrl($url)],
[
$url,
['foo', 'bar'],
ShortUrlMeta::createFromRawData(['findIfExists' => true]),
(new ShortUrl($url))->setTags(new ArrayCollection([new Tag('bar'), new Tag('foo')])),
],
[
$url,
[],
ShortUrlMeta::createFromRawData(['findIfExists' => true, 'maxVisits' => 3]),
new ShortUrl($url, ShortUrlMeta::createFromRawData(['maxVisits' => 3])),
],
[
$url,
[],
ShortUrlMeta::createFromRawData(['findIfExists' => true, 'validSince' => Chronos::parse('2017-01-01')]),
new ShortUrl($url, ShortUrlMeta::createFromRawData(['validSince' => Chronos::parse('2017-01-01')])),
],
[
$url,
[],
ShortUrlMeta::createFromRawData(['findIfExists' => true, 'validUntil' => Chronos::parse('2017-01-01')]),
new ShortUrl($url, ShortUrlMeta::createFromRawData(['validUntil' => Chronos::parse('2017-01-01')])),
],
[
$url,
['baz', 'foo', 'bar'],
ShortUrlMeta::createFromRawData([
'findIfExists' => true,
'validUntil' => Chronos::parse('2017-01-01'),
'maxVisits' => 4,
]),
(new ShortUrl($url, ShortUrlMeta::createFromRawData([
'validUntil' => Chronos::parse('2017-01-01'),
'maxVisits' => 4,
])))->setTags(new ArrayCollection([new Tag('foo'), new Tag('bar'), new Tag('baz')])),
],
yield [$url, [], ShortUrlMeta::createFromRawData(['findIfExists' => true]), new ShortUrl($url)];
yield [$url, [], ShortUrlMeta::createFromRawData(
['findIfExists' => true, 'customSlug' => 'foo']
), new ShortUrl($url)];
yield [
$url,
['foo', 'bar'],
ShortUrlMeta::createFromRawData(['findIfExists' => true]),
(new ShortUrl($url))->setTags(new ArrayCollection([new Tag('bar'), new Tag('foo')])),
];
yield [
$url,
[],
ShortUrlMeta::createFromRawData(['findIfExists' => true, 'maxVisits' => 3]),
new ShortUrl($url, ShortUrlMeta::createFromRawData(['maxVisits' => 3])),
];
yield [
$url,
[],
ShortUrlMeta::createFromRawData(['findIfExists' => true, 'validSince' => Chronos::parse('2017-01-01')]),
new ShortUrl($url, ShortUrlMeta::createFromRawData(['validSince' => Chronos::parse('2017-01-01')])),
];
yield [
$url,
[],
ShortUrlMeta::createFromRawData(['findIfExists' => true, 'validUntil' => Chronos::parse('2017-01-01')]),
new ShortUrl($url, ShortUrlMeta::createFromRawData(['validUntil' => Chronos::parse('2017-01-01')])),
];
yield [
$url,
['baz', 'foo', 'bar'],
ShortUrlMeta::createFromRawData([
'findIfExists' => true,
'validUntil' => Chronos::parse('2017-01-01'),
'maxVisits' => 4,
]),
(new ShortUrl($url, ShortUrlMeta::createFromRawData([
'validUntil' => Chronos::parse('2017-01-01'),
'maxVisits' => 4,
])))->setTags(new ArrayCollection([new Tag('foo'), new Tag('bar'), new Tag('baz')])),
];
}
/**
* @test
*/
/** @test */
public function shortCodeIsProperlyParsed(): void
{
$shortCode = '12C1c';
@@ -67,9 +67,7 @@ class VisitServiceTest extends TestCase
$clear->shouldHaveBeenCalledTimes(count($unlocatedVisits));
}
/**
* @test
*/
/** @test */
public function visitsWhichCannotBeLocatedAreIgnored()
{
$unlocatedVisits = [
@@ -31,9 +31,7 @@ class VisitsTrackerTest extends TestCase
$this->visitsTracker = new VisitsTracker($this->em->reveal());
}
/**
* @test
*/
/** @test */
public function trackPersistsVisit()
{
$shortCode = '123ABC';
@@ -47,9 +45,7 @@ class VisitsTrackerTest extends TestCase
$this->visitsTracker->track($shortCode, Visitor::emptyInstance());
}
/**
* @test
*/
/** @test */
public function trackedIpAddressGetsObfuscated()
{
$shortCode = '123ABC';
@@ -67,9 +63,7 @@ class VisitsTrackerTest extends TestCase
$this->visitsTracker->track($shortCode, new Visitor('', '', '4.3.2.1'));
}
/**
* @test
*/
/** @test */
public function infoReturnsVisistForCertainShortCode()
{
$shortCode = '123ABC';