2018-11-17 21:23:25 +03:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Common\Util;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
|
2019-02-27 00:56:43 +03:00
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
use function Functional\map;
|
|
|
|
use function range;
|
2018-11-17 21:23:25 +03:00
|
|
|
use function strlen;
|
|
|
|
|
|
|
|
class StringUtilsTraitTest extends TestCase
|
|
|
|
{
|
|
|
|
use StringUtilsTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideLengths
|
|
|
|
*/
|
2019-02-17 22:28:34 +03:00
|
|
|
public function generateRandomStringGeneratesStringOfProvidedLength(int $length): void
|
2018-11-17 21:23:25 +03:00
|
|
|
{
|
|
|
|
$this->assertEquals($length, strlen($this->generateRandomString($length)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideLengths(): array
|
|
|
|
{
|
2019-02-17 22:28:34 +03:00
|
|
|
return map(range(10, 50, 5), function (int $i) {
|
|
|
|
return [$i];
|
|
|
|
});
|
2018-11-17 21:23:25 +03:00
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2018-11-17 21:23:25 +03:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|