-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathHashidsDriverTest.php
49 lines (41 loc) · 2.07 KB
/
HashidsDriverTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace ElfSundae\Laravel\Hashid\Test;
use ElfSundae\Laravel\Hashid\HashidsDriver;
use ElfSundae\Laravel\Hashid\HashidsHexDriver;
use ElfSundae\Laravel\Hashid\HashidsIntegerDriver;
use ElfSundae\Laravel\Hashid\HashidsStringDriver;
class HashidsDriverTest extends DriverTestCase
{
protected $driver = HashidsDriver::class;
protected $hexDriver = HashidsHexDriver::class;
protected $integerDriver = HashidsIntegerDriver::class;
protected $stringDriver = HashidsStringDriver::class;
public function testInstantiation()
{
$this->assertInstanceOf($this->driver, $this->makeDriver());
$this->assertInstanceOf($this->hexDriver, $this->makeDriver($this->hexDriver));
$this->assertInstanceOf($this->integerDriver, $this->makeDriver($this->integerDriver));
$this->assertInstanceOf($this->stringDriver, $this->makeDriver($this->stringDriver));
}
public function testEncoding()
{
$this->assertEncodedData([1, 2, 3], 'o2fXhV');
$randomIntegers = array_map(function () {
return random_int(0, PHP_INT_MAX);
}, array_fill(0, 10, null));
$this->assertReversible($randomIntegers);
$this->assertUniformEncoding($randomIntegers);
$this->assertEncodedData('507f1f77bcf86cd799439011', 'y42LW46J9luq3Xq9XMly', $this->hexDriver);
$this->assertReversible(bin2hex(random_bytes(128)), $this->hexDriver);
$this->assertUniformEncoding(bin2hex(random_bytes(128)), $this->hexDriver);
$this->assertEncodedData(1, 'jR', $this->integerDriver);
$this->runForIntegers($this->integerDriver);
$this->assertUniformEncoding(random_int(0, PHP_INT_MAX), $this->integerDriver);
$integerDriver = $this->makeDriver($this->integerDriver);
$encoded = $integerDriver->encode([1, 2, 3]);
$this->assertSame(0, $integerDriver->decode($encoded));
$this->assertEncodedData('Hashid', 'mWxDrOkZ49', $this->stringDriver);
$this->runForBytes($this->stringDriver);
$this->assertUniformEncoding(random_bytes(128), $this->stringDriver);
}
}