mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Increased MSI to 65%
This commit is contained in:
40
module/Core/test/Entity/VisitTest.php
Normal file
40
module/Core/test/Entity/VisitTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Entity;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||
|
||||
class VisitTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideDates
|
||||
*/
|
||||
public function isProperlyJsonSerialized(?Chronos $date)
|
||||
{
|
||||
$visit = new Visit(new ShortUrl(''), new Visitor('Chrome', 'some site', '1.2.3.4'), $date);
|
||||
|
||||
$this->assertEquals([
|
||||
'referer' => 'some site',
|
||||
'date' => ($date ?? $visit->getDate())->toAtomString(),
|
||||
'userAgent' => 'Chrome',
|
||||
'visitLocation' => null,
|
||||
|
||||
// Deprecated
|
||||
'remoteAddr' => null,
|
||||
], $visit->jsonSerialize());
|
||||
}
|
||||
|
||||
public function provideDates(): array
|
||||
{
|
||||
return [
|
||||
[null],
|
||||
[Chronos::now()->subDays(10)],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ class DeleteShortUrlExceptionTest extends TestCase
|
||||
) {
|
||||
$e = DeleteShortUrlException::fromVisitsThreshold($threshold, $shortCode);
|
||||
$this->assertEquals($expectedMessage, $e->getMessage());
|
||||
$this->assertEquals(0, $e->getCode());
|
||||
}
|
||||
|
||||
public function provideMessages(): array
|
||||
|
||||
43
module/Core/test/Exception/InvalidShortCodeExceptionTest.php
Normal file
43
module/Core/test/Exception/InvalidShortCodeExceptionTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Exception;
|
||||
|
||||
use Exception;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Throwable;
|
||||
|
||||
class InvalidShortCodeExceptionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider providePrevious
|
||||
*/
|
||||
public function properlyCreatesExceptionFromCharset(?Throwable $prev)
|
||||
{
|
||||
$e = InvalidShortCodeException::fromCharset('abc123', 'def456', $prev);
|
||||
|
||||
$this->assertEquals('Provided short code "abc123" does not match the char set "def456"', $e->getMessage());
|
||||
$this->assertEquals($prev !== null ? $prev->getCode() : -1, $e->getCode());
|
||||
$this->assertEquals($prev, $e->getPrevious());
|
||||
}
|
||||
|
||||
public function providePrevious(): array
|
||||
{
|
||||
return [
|
||||
[null],
|
||||
[new Exception('Previos error', 10)],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function properlyCreatesExceptionFromNotFoundShortCode()
|
||||
{
|
||||
$e = InvalidShortCodeException::fromNotFoundShortCode('abc123');
|
||||
|
||||
$this->assertEquals('Provided short code "abc123" does not belong to a short URL', $e->getMessage());
|
||||
}
|
||||
}
|
||||
33
module/Core/test/Exception/InvalidUrlExceptionTest.php
Normal file
33
module/Core/test/Exception/InvalidUrlExceptionTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Exception;
|
||||
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
|
||||
use Throwable;
|
||||
|
||||
class InvalidUrlExceptionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider providePrevious
|
||||
*/
|
||||
public function properlyCreatesExceptionFromUrl(?Throwable $prev)
|
||||
{
|
||||
$e = InvalidUrlException::fromUrl('http://the_url.com', $prev);
|
||||
|
||||
$this->assertEquals('Provided URL "http://the_url.com" is not an existing and valid URL', $e->getMessage());
|
||||
$this->assertEquals($prev !== null ? $prev->getCode() : -1, $e->getCode());
|
||||
$this->assertEquals($prev, $e->getPrevious());
|
||||
}
|
||||
|
||||
public function providePrevious(): array
|
||||
{
|
||||
return [
|
||||
[null],
|
||||
[new Exception('Previos error', 10)],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user