Increased MSI to 65%

This commit is contained in:
Alejandro Celaya
2018-11-17 19:23:25 +01:00
parent 6094d17718
commit 79b2a0839f
15 changed files with 227 additions and 17 deletions

View File

@@ -118,4 +118,12 @@ class Visit extends AbstractEntity implements JsonSerializable
'remoteAddr' => null,
];
}
/**
* @internal
*/
public function getDate(): Chronos
{
return $this->date;
}
}

View File

@@ -8,7 +8,7 @@ use function sprintf;
class InvalidShortCodeException extends RuntimeException
{
public static function fromCharset($shortCode, $charSet, Exception $previous = null)
public static function fromCharset(string $shortCode, string $charSet, Exception $previous = null): self
{
$code = $previous !== null ? $previous->getCode() : -1;
return new static(
@@ -18,7 +18,7 @@ class InvalidShortCodeException extends RuntimeException
);
}
public static function fromNotFoundShortCode($shortCode)
public static function fromNotFoundShortCode(string $shortCode): self
{
return new static(sprintf('Provided short code "%s" does not belong to a short URL', $shortCode));
}

View File

@@ -10,7 +10,7 @@ class InvalidUrlException extends RuntimeException
{
public static function fromUrl($url, Throwable $previous = null)
{
$code = isset($previous) ? $previous->getCode() : -1;
$code = $previous !== null ? $previous->getCode() : -1;
return new static(sprintf('Provided URL "%s" is not an existing and valid URL', $url), $code, $previous);
}
}

View 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)],
];
}
}

View File

@@ -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

View 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());
}
}

View 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)],
];
}
}