mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Increased MSI to 65%
This commit is contained in:
23
module/Common/test/Response/QrCodeResponseTest.php
Normal file
23
module/Common/test/Response/QrCodeResponseTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Common\Response;
|
||||
|
||||
use Endroid\QrCode\QrCode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Common\Response\QrCodeResponse;
|
||||
|
||||
class QrCodeResponseTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function providedQrCoideIsSetAsBody()
|
||||
{
|
||||
$qrCode = new QrCode('Hello');
|
||||
$resp = new QrCodeResponse($qrCode);
|
||||
|
||||
$this->assertEquals($qrCode->getContentType(), $resp->getHeaderLine('Content-Type'));
|
||||
$this->assertEquals($qrCode->get(), (string) $resp->getBody());
|
||||
}
|
||||
}
|
||||
@@ -32,4 +32,24 @@ class DateRangeTest extends TestCase
|
||||
$this->assertSame($endDate, $range->getEndDate());
|
||||
$this->assertFalse($range->isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideDates
|
||||
*/
|
||||
public function isConsideredEmptyOnlyIfNoneOfTheDatesIsSet(?Chronos $startDate, ?Chronos $endDate, bool $isEmpty)
|
||||
{
|
||||
$range = new DateRange($startDate, $endDate);
|
||||
$this->assertEquals($isEmpty, $range->isEmpty());
|
||||
}
|
||||
|
||||
public function provideDates(): array
|
||||
{
|
||||
return [
|
||||
[null, null, true],
|
||||
[null, Chronos::now(), false],
|
||||
[Chronos::now(), null, false],
|
||||
[Chronos::now(), Chronos::now(), false],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
45
module/Common/test/Util/StringUtilsTraitTest.php
Normal file
45
module/Common/test/Util/StringUtilsTraitTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Common\Util;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
|
||||
use function strlen;
|
||||
|
||||
class StringUtilsTraitTest extends TestCase
|
||||
{
|
||||
use StringUtilsTrait;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideLengths
|
||||
*/
|
||||
public function generateRandomStringGeneratesStringOfProvidedLength(int $length)
|
||||
{
|
||||
$this->assertEquals($length, strlen($this->generateRandomString($length)));
|
||||
}
|
||||
|
||||
public function provideLengths(): array
|
||||
{
|
||||
return [
|
||||
[1],
|
||||
[10],
|
||||
[15],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function generatesUuidV4()
|
||||
{
|
||||
$uuidPattern = '/[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/';
|
||||
|
||||
$this->assertRegExp($uuidPattern, $this->generateV4Uuid());
|
||||
$this->assertRegExp($uuidPattern, $this->generateV4Uuid());
|
||||
$this->assertRegExp($uuidPattern, $this->generateV4Uuid());
|
||||
$this->assertRegExp($uuidPattern, $this->generateV4Uuid());
|
||||
$this->assertRegExp($uuidPattern, $this->generateV4Uuid());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user