mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Invoke PHPUnit's assertions statically
This commit is contained in:
@@ -57,25 +57,25 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertSame($regularOne, $this->repo->findOneWithDomainFallback($regularOne->getShortCode()));
|
||||
$this->assertSame($regularOne, $this->repo->findOneWithDomainFallback(
|
||||
self::assertSame($regularOne, $this->repo->findOneWithDomainFallback($regularOne->getShortCode()));
|
||||
self::assertSame($regularOne, $this->repo->findOneWithDomainFallback(
|
||||
$withDomainDuplicatingRegular->getShortCode(),
|
||||
));
|
||||
$this->assertSame($withDomain, $this->repo->findOneWithDomainFallback(
|
||||
self::assertSame($withDomain, $this->repo->findOneWithDomainFallback(
|
||||
$withDomain->getShortCode(),
|
||||
'example.com',
|
||||
));
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
$withDomainDuplicatingRegular,
|
||||
$this->repo->findOneWithDomainFallback($withDomainDuplicatingRegular->getShortCode(), 'doma.in'),
|
||||
);
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
$regularOne,
|
||||
$this->repo->findOneWithDomainFallback($withDomainDuplicatingRegular->getShortCode(), 'other-domain.com'),
|
||||
);
|
||||
$this->assertNull($this->repo->findOneWithDomainFallback('invalid'));
|
||||
$this->assertNull($this->repo->findOneWithDomainFallback($withDomain->getShortCode()));
|
||||
$this->assertNull($this->repo->findOneWithDomainFallback($withDomain->getShortCode(), 'other-domain.com'));
|
||||
self::assertNull($this->repo->findOneWithDomainFallback('invalid'));
|
||||
self::assertNull($this->repo->findOneWithDomainFallback($withDomain->getShortCode()));
|
||||
self::assertNull($this->repo->findOneWithDomainFallback($withDomain->getShortCode(), 'other-domain.com'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -87,7 +87,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
}
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertEquals($count, $this->repo->countList());
|
||||
self::assertEquals($count, $this->repo->countList());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -116,37 +116,37 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$result = $this->repo->findList(null, null, 'foo', ['bar']);
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals(1, $this->repo->countList('foo', ['bar']));
|
||||
$this->assertSame($foo, $result[0]);
|
||||
self::assertCount(1, $result);
|
||||
self::assertEquals(1, $this->repo->countList('foo', ['bar']));
|
||||
self::assertSame($foo, $result[0]);
|
||||
|
||||
$result = $this->repo->findList();
|
||||
$this->assertCount(3, $result);
|
||||
self::assertCount(3, $result);
|
||||
|
||||
$result = $this->repo->findList(2);
|
||||
$this->assertCount(2, $result);
|
||||
self::assertCount(2, $result);
|
||||
|
||||
$result = $this->repo->findList(2, 1);
|
||||
$this->assertCount(2, $result);
|
||||
self::assertCount(2, $result);
|
||||
|
||||
$this->assertCount(1, $this->repo->findList(2, 2));
|
||||
self::assertCount(1, $this->repo->findList(2, 2));
|
||||
|
||||
$result = $this->repo->findList(null, null, null, [], ShortUrlsOrdering::fromRawData([
|
||||
'orderBy' => ['visits' => 'DESC'],
|
||||
]));
|
||||
$this->assertCount(3, $result);
|
||||
$this->assertSame($bar, $result[0]);
|
||||
self::assertCount(3, $result);
|
||||
self::assertSame($bar, $result[0]);
|
||||
|
||||
$result = $this->repo->findList(null, null, null, [], null, new DateRange(null, Chronos::now()->subDays(2)));
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals(1, $this->repo->countList(null, [], new DateRange(null, Chronos::now()->subDays(2))));
|
||||
$this->assertSame($foo2, $result[0]);
|
||||
self::assertCount(1, $result);
|
||||
self::assertEquals(1, $this->repo->countList(null, [], new DateRange(null, Chronos::now()->subDays(2))));
|
||||
self::assertSame($foo2, $result[0]);
|
||||
|
||||
$this->assertCount(
|
||||
self::assertCount(
|
||||
2,
|
||||
$this->repo->findList(null, null, null, [], null, new DateRange(Chronos::now()->subDays(2))),
|
||||
);
|
||||
$this->assertEquals(2, $this->repo->countList(null, [], new DateRange(Chronos::now()->subDays(2))));
|
||||
self::assertEquals(2, $this->repo->countList(null, [], new DateRange(Chronos::now()->subDays(2))));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -163,11 +163,11 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
'orderBy' => ['longUrl' => 'ASC'],
|
||||
]));
|
||||
|
||||
$this->assertCount(count($urls), $result);
|
||||
$this->assertEquals('a', $result[0]->getLongUrl());
|
||||
$this->assertEquals('b', $result[1]->getLongUrl());
|
||||
$this->assertEquals('c', $result[2]->getLongUrl());
|
||||
$this->assertEquals('z', $result[3]->getLongUrl());
|
||||
self::assertCount(count($urls), $result);
|
||||
self::assertEquals('a', $result[0]->getLongUrl());
|
||||
self::assertEquals('b', $result[1]->getLongUrl());
|
||||
self::assertEquals('c', $result[2]->getLongUrl());
|
||||
self::assertEquals('z', $result[3]->getLongUrl());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -184,12 +184,12 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertTrue($this->repo->shortCodeIsInUse('my-cool-slug'));
|
||||
$this->assertFalse($this->repo->shortCodeIsInUse('my-cool-slug', 'doma.in'));
|
||||
$this->assertFalse($this->repo->shortCodeIsInUse('slug-not-in-use'));
|
||||
$this->assertFalse($this->repo->shortCodeIsInUse('another-slug'));
|
||||
$this->assertFalse($this->repo->shortCodeIsInUse('another-slug', 'example.com'));
|
||||
$this->assertTrue($this->repo->shortCodeIsInUse('another-slug', 'doma.in'));
|
||||
self::assertTrue($this->repo->shortCodeIsInUse('my-cool-slug'));
|
||||
self::assertFalse($this->repo->shortCodeIsInUse('my-cool-slug', 'doma.in'));
|
||||
self::assertFalse($this->repo->shortCodeIsInUse('slug-not-in-use'));
|
||||
self::assertFalse($this->repo->shortCodeIsInUse('another-slug'));
|
||||
self::assertFalse($this->repo->shortCodeIsInUse('another-slug', 'example.com'));
|
||||
self::assertTrue($this->repo->shortCodeIsInUse('another-slug', 'doma.in'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -206,21 +206,21 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertNotNull($this->repo->findOne('my-cool-slug'));
|
||||
$this->assertNull($this->repo->findOne('my-cool-slug', 'doma.in'));
|
||||
$this->assertNull($this->repo->findOne('slug-not-in-use'));
|
||||
$this->assertNull($this->repo->findOne('another-slug'));
|
||||
$this->assertNull($this->repo->findOne('another-slug', 'example.com'));
|
||||
$this->assertNotNull($this->repo->findOne('another-slug', 'doma.in'));
|
||||
self::assertNotNull($this->repo->findOne('my-cool-slug'));
|
||||
self::assertNull($this->repo->findOne('my-cool-slug', 'doma.in'));
|
||||
self::assertNull($this->repo->findOne('slug-not-in-use'));
|
||||
self::assertNull($this->repo->findOne('another-slug'));
|
||||
self::assertNull($this->repo->findOne('another-slug', 'example.com'));
|
||||
self::assertNotNull($this->repo->findOne('another-slug', 'doma.in'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function findOneMatchingReturnsNullForNonExistingShortUrls(): void
|
||||
{
|
||||
$this->assertNull($this->repo->findOneMatching('', [], ShortUrlMeta::createEmpty()));
|
||||
$this->assertNull($this->repo->findOneMatching('foobar', [], ShortUrlMeta::createEmpty()));
|
||||
$this->assertNull($this->repo->findOneMatching('foobar', ['foo', 'bar'], ShortUrlMeta::createEmpty()));
|
||||
$this->assertNull($this->repo->findOneMatching('foobar', ['foo', 'bar'], ShortUrlMeta::fromRawData([
|
||||
self::assertNull($this->repo->findOneMatching('', [], ShortUrlMeta::createEmpty()));
|
||||
self::assertNull($this->repo->findOneMatching('foobar', [], ShortUrlMeta::createEmpty()));
|
||||
self::assertNull($this->repo->findOneMatching('foobar', ['foo', 'bar'], ShortUrlMeta::createEmpty()));
|
||||
self::assertNull($this->repo->findOneMatching('foobar', ['foo', 'bar'], ShortUrlMeta::fromRawData([
|
||||
'validSince' => Chronos::parse('2020-03-05 20:18:30'),
|
||||
'customSlug' => 'this_slug_does_not_exist',
|
||||
])));
|
||||
@@ -253,33 +253,33 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
$shortUrl,
|
||||
$this->repo->findOneMatching('foo', ['foo', 'bar'], ShortUrlMeta::fromRawData(['validSince' => $start])),
|
||||
);
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
$shortUrl2,
|
||||
$this->repo->findOneMatching('bar', [], ShortUrlMeta::fromRawData(['validUntil' => $end])),
|
||||
);
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
$shortUrl3,
|
||||
$this->repo->findOneMatching('baz', [], ShortUrlMeta::fromRawData([
|
||||
'validSince' => $start,
|
||||
'validUntil' => $end,
|
||||
])),
|
||||
);
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
$shortUrl4,
|
||||
$this->repo->findOneMatching('foo', [], ShortUrlMeta::fromRawData([
|
||||
'customSlug' => 'custom',
|
||||
'validUntil' => $end,
|
||||
])),
|
||||
);
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
$shortUrl5,
|
||||
$this->repo->findOneMatching('foo', [], ShortUrlMeta::fromRawData(['maxVisits' => 3])),
|
||||
);
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
$shortUrl6,
|
||||
$this->repo->findOneMatching('foo', [], ShortUrlMeta::fromRawData(['domain' => 'doma.in'])),
|
||||
);
|
||||
@@ -307,15 +307,15 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
$shortUrl1,
|
||||
$this->repo->findOneMatching('foo', $tags, ShortUrlMeta::fromRawData($meta)),
|
||||
);
|
||||
$this->assertNotSame(
|
||||
self::assertNotSame(
|
||||
$shortUrl2,
|
||||
$this->repo->findOneMatching('foo', $tags, ShortUrlMeta::fromRawData($meta)),
|
||||
);
|
||||
$this->assertNotSame(
|
||||
self::assertNotSame(
|
||||
$shortUrl3,
|
||||
$this->repo->findOneMatching('foo', $tags, ShortUrlMeta::fromRawData($meta)),
|
||||
);
|
||||
|
||||
@@ -32,7 +32,7 @@ class TagRepositoryTest extends DatabaseTestCase
|
||||
/** @test */
|
||||
public function deleteByNameDoesNothingWhenEmptyListIsProvided(): void
|
||||
{
|
||||
$this->assertEquals(0, $this->repo->deleteByName([]));
|
||||
self::assertEquals(0, $this->repo->deleteByName([]));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -46,7 +46,7 @@ class TagRepositoryTest extends DatabaseTestCase
|
||||
}
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertEquals(2, $this->repo->deleteByName($toDelete));
|
||||
self::assertEquals(2, $this->repo->deleteByName($toDelete));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -79,20 +79,20 @@ class TagRepositoryTest extends DatabaseTestCase
|
||||
|
||||
$result = $this->repo->findTagsWithInfo();
|
||||
|
||||
$this->assertCount(4, $result);
|
||||
$this->assertEquals(
|
||||
self::assertCount(4, $result);
|
||||
self::assertEquals(
|
||||
['tag' => $tags[3], 'shortUrlsCount' => 0, 'visitsCount' => 0],
|
||||
$result[0]->jsonSerialize(),
|
||||
);
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
['tag' => $tags[1], 'shortUrlsCount' => 1, 'visitsCount' => 3],
|
||||
$result[1]->jsonSerialize(),
|
||||
);
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
['tag' => $tags[2], 'shortUrlsCount' => 1, 'visitsCount' => 3],
|
||||
$result[2]->jsonSerialize(),
|
||||
);
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
['tag' => $tags[0], 'shortUrlsCount' => 2, 'visitsCount' => 4],
|
||||
$result[3]->jsonSerialize(),
|
||||
);
|
||||
|
||||
@@ -75,9 +75,9 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
|
||||
// Important! assertCount will not work here, as this iterable object loads data dynamically and the count
|
||||
// is 0 if not iterated
|
||||
$this->assertEquals(2, $countIterable($unlocated));
|
||||
$this->assertEquals(4, $countIterable($withEmptyLocation));
|
||||
$this->assertEquals(6, $countIterable($all));
|
||||
self::assertEquals(2, $countIterable($unlocated));
|
||||
self::assertEquals(4, $countIterable($withEmptyLocation));
|
||||
self::assertEquals(6, $countIterable($all));
|
||||
}
|
||||
|
||||
public function provideBlockSize(): iterable
|
||||
@@ -90,22 +90,22 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
{
|
||||
[$shortCode, $domain] = $this->createShortUrlsAndVisits();
|
||||
|
||||
$this->assertCount(0, $this->repo->findVisitsByShortCode('invalid'));
|
||||
$this->assertCount(6, $this->repo->findVisitsByShortCode($shortCode));
|
||||
$this->assertCount(3, $this->repo->findVisitsByShortCode($shortCode, $domain));
|
||||
$this->assertCount(2, $this->repo->findVisitsByShortCode($shortCode, null, new DateRange(
|
||||
self::assertCount(0, $this->repo->findVisitsByShortCode('invalid'));
|
||||
self::assertCount(6, $this->repo->findVisitsByShortCode($shortCode));
|
||||
self::assertCount(3, $this->repo->findVisitsByShortCode($shortCode, $domain));
|
||||
self::assertCount(2, $this->repo->findVisitsByShortCode($shortCode, null, new DateRange(
|
||||
Chronos::parse('2016-01-02'),
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
$this->assertCount(4, $this->repo->findVisitsByShortCode($shortCode, null, new DateRange(
|
||||
self::assertCount(4, $this->repo->findVisitsByShortCode($shortCode, null, new DateRange(
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
$this->assertCount(1, $this->repo->findVisitsByShortCode($shortCode, $domain, new DateRange(
|
||||
self::assertCount(1, $this->repo->findVisitsByShortCode($shortCode, $domain, new DateRange(
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
$this->assertCount(3, $this->repo->findVisitsByShortCode($shortCode, null, null, 3, 2));
|
||||
$this->assertCount(2, $this->repo->findVisitsByShortCode($shortCode, null, null, 5, 4));
|
||||
$this->assertCount(1, $this->repo->findVisitsByShortCode($shortCode, $domain, null, 3, 2));
|
||||
self::assertCount(3, $this->repo->findVisitsByShortCode($shortCode, null, null, 3, 2));
|
||||
self::assertCount(2, $this->repo->findVisitsByShortCode($shortCode, null, null, 5, 4));
|
||||
self::assertCount(1, $this->repo->findVisitsByShortCode($shortCode, $domain, null, 3, 2));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -113,17 +113,17 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
{
|
||||
[$shortCode, $domain] = $this->createShortUrlsAndVisits();
|
||||
|
||||
$this->assertEquals(0, $this->repo->countVisitsByShortCode('invalid'));
|
||||
$this->assertEquals(6, $this->repo->countVisitsByShortCode($shortCode));
|
||||
$this->assertEquals(3, $this->repo->countVisitsByShortCode($shortCode, $domain));
|
||||
$this->assertEquals(2, $this->repo->countVisitsByShortCode($shortCode, null, new DateRange(
|
||||
self::assertEquals(0, $this->repo->countVisitsByShortCode('invalid'));
|
||||
self::assertEquals(6, $this->repo->countVisitsByShortCode($shortCode));
|
||||
self::assertEquals(3, $this->repo->countVisitsByShortCode($shortCode, $domain));
|
||||
self::assertEquals(2, $this->repo->countVisitsByShortCode($shortCode, null, new DateRange(
|
||||
Chronos::parse('2016-01-02'),
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
$this->assertEquals(4, $this->repo->countVisitsByShortCode($shortCode, null, new DateRange(
|
||||
self::assertEquals(4, $this->repo->countVisitsByShortCode($shortCode, null, new DateRange(
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
$this->assertEquals(1, $this->repo->countVisitsByShortCode($shortCode, $domain, new DateRange(
|
||||
self::assertEquals(1, $this->repo->countVisitsByShortCode($shortCode, $domain, new DateRange(
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
}
|
||||
@@ -147,13 +147,13 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertCount(0, $this->repo->findVisitsByTag('invalid'));
|
||||
$this->assertCount(18, $this->repo->findVisitsByTag((string) $foo));
|
||||
$this->assertCount(6, $this->repo->findVisitsByTag((string) $foo, new DateRange(
|
||||
self::assertCount(0, $this->repo->findVisitsByTag('invalid'));
|
||||
self::assertCount(18, $this->repo->findVisitsByTag((string) $foo));
|
||||
self::assertCount(6, $this->repo->findVisitsByTag((string) $foo, new DateRange(
|
||||
Chronos::parse('2016-01-02'),
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
$this->assertCount(12, $this->repo->findVisitsByTag((string) $foo, new DateRange(
|
||||
self::assertCount(12, $this->repo->findVisitsByTag((string) $foo, new DateRange(
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
}
|
||||
@@ -174,13 +174,13 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertEquals(0, $this->repo->countVisitsByTag('invalid'));
|
||||
$this->assertEquals(12, $this->repo->countVisitsByTag((string) $foo));
|
||||
$this->assertEquals(4, $this->repo->countVisitsByTag((string) $foo, new DateRange(
|
||||
self::assertEquals(0, $this->repo->countVisitsByTag('invalid'));
|
||||
self::assertEquals(12, $this->repo->countVisitsByTag((string) $foo));
|
||||
self::assertEquals(4, $this->repo->countVisitsByTag((string) $foo, new DateRange(
|
||||
Chronos::parse('2016-01-02'),
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
$this->assertEquals(8, $this->repo->countVisitsByTag((string) $foo, new DateRange(
|
||||
self::assertEquals(8, $this->repo->countVisitsByTag((string) $foo, new DateRange(
|
||||
Chronos::parse('2016-01-03'),
|
||||
)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user