OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
firebase
/
vendor
/
ramsey
/
uuid
/
tests
/
Generator
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
08/12/2024 10:36:11 AM
rwxr-xr-x
📄
CombGeneratorTest.php
4.65 KB
08/12/2024 10:34:38 AM
rw-r--r--
📄
DceSecurityGeneratorTest.php
11.4 KB
08/12/2024 10:34:38 AM
rw-r--r--
📄
DefaultNameGeneratorTest.php
2.48 KB
08/12/2024 10:34:38 AM
rw-r--r--
📄
DefaultTimeGeneratorTest.php
6.88 KB
08/12/2024 10:34:38 AM
rw-r--r--
📄
NameGeneratorFactoryTest.php
464 bytes
08/12/2024 10:34:38 AM
rw-r--r--
📄
PeclUuidNameGeneratorTest.php
3.48 KB
08/12/2024 10:34:38 AM
rw-r--r--
📄
PeclUuidRandomGeneratorTest.php
757 bytes
08/12/2024 10:34:38 AM
rw-r--r--
📄
PeclUuidTimeGeneratorTest.php
747 bytes
08/12/2024 10:34:38 AM
rw-r--r--
📄
RandomBytesGeneratorTest.php
1.89 KB
08/12/2024 10:34:38 AM
rw-r--r--
📄
RandomGeneratorFactoryTest.php
498 bytes
08/12/2024 10:34:38 AM
rw-r--r--
📄
RandomLibAdapterTest.php
2.28 KB
08/12/2024 10:34:38 AM
rw-r--r--
📄
TimeGeneratorFactoryTest.php
1.21 KB
08/12/2024 10:34:38 AM
rw-r--r--
📄
UnixTimeGeneratorTest.php
7.36 KB
08/12/2024 10:34:38 AM
rw-r--r--
Editing: UnixTimeGeneratorTest.php
Close
<?php declare(strict_types=1); namespace Ramsey\Uuid\Test\Generator; use DateTimeImmutable; use Mockery; use Mockery\MockInterface; use Ramsey\Uuid\Generator\RandomBytesGenerator; use Ramsey\Uuid\Generator\RandomGeneratorInterface; use Ramsey\Uuid\Generator\UnixTimeGenerator; use Ramsey\Uuid\Test\TestCase; class UnixTimeGeneratorTest extends TestCase { /** * @runInSeparateProcess since values are stored statically on the class * @preserveGlobalState disabled */ public function testGenerate(): void { $dateTime = new DateTimeImmutable('@1578612359.521023'); $expectedBytes = "\x01\x6f\x8c\xa1\x01\x61\x03\x00\xff\x00\xff\x00\xff\x00\xff\x00"; /** @var RandomGeneratorInterface&MockInterface $randomGenerator */ $randomGenerator = Mockery::mock(RandomGeneratorInterface::class); $randomGenerator->expects()->generate(16)->andReturns( "\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00", ); $unixTimeGenerator = new UnixTimeGenerator($randomGenerator); $bytes = $unixTimeGenerator->generate(null, null, $dateTime); $this->assertSame($expectedBytes, $bytes); } /** * @runInSeparateProcess since values are stored statically on the class * @preserveGlobalState disabled */ public function testGenerateProducesMonotonicResults(): void { $randomGenerator = new RandomBytesGenerator(); $unixTimeGenerator = new UnixTimeGenerator($randomGenerator); $previous = ''; for ($i = 0; $i < 25; $i++) { $bytes = $unixTimeGenerator->generate(); $this->assertTrue($bytes > $previous); } } /** * @runInSeparateProcess since values are stored statically on the class * @preserveGlobalState disabled */ public function testGenerateProducesMonotonicResultsWithSameDate(): void { $dateTime = new DateTimeImmutable('now'); $randomGenerator = new RandomBytesGenerator(); $unixTimeGenerator = new UnixTimeGenerator($randomGenerator); $previous = ''; for ($i = 0; $i < 25; $i++) { $bytes = $unixTimeGenerator->generate(null, null, $dateTime); $this->assertTrue($bytes > $previous); } } /** * @runInSeparateProcess since values are stored statically on the class * @preserveGlobalState disabled */ public function testGenerateProducesMonotonicResultsFor32BitPath(): void { $randomGenerator = new RandomBytesGenerator(); $unixTimeGenerator = new UnixTimeGenerator($randomGenerator, 4); $previous = ''; for ($i = 0; $i < 25; $i++) { $bytes = $unixTimeGenerator->generate(); $this->assertTrue($bytes > $previous); } } /** * @runInSeparateProcess since values are stored statically on the class * @preserveGlobalState disabled */ public function testGenerateProducesMonotonicResultsWithSameDateFor32BitPath(): void { $dateTime = new DateTimeImmutable('now'); $randomGenerator = new RandomBytesGenerator(); $unixTimeGenerator = new UnixTimeGenerator($randomGenerator, 4); $previous = ''; for ($i = 0; $i < 25; $i++) { $bytes = $unixTimeGenerator->generate(null, null, $dateTime); $this->assertTrue($bytes > $previous); } } /** * @runInSeparateProcess since values are stored statically on the class * @preserveGlobalState disabled */ public function testGenerateProducesMonotonicResultsStartingWithAllBitsSet(): void { /** @var RandomGeneratorInterface&MockInterface $randomGenerator */ $randomGenerator = Mockery::mock(RandomGeneratorInterface::class); $randomGenerator->expects()->generate(16)->andReturns( "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", ); $randomGenerator->expects()->generate(10)->times(24)->andReturns( "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", ); $unixTimeGenerator = new UnixTimeGenerator($randomGenerator); $previous = ''; for ($i = 0; $i < 25; $i++) { $bytes = $unixTimeGenerator->generate(); $this->assertTrue($bytes > $previous); } } /** * @runInSeparateProcess since values are stored statically on the class * @preserveGlobalState disabled */ public function testGenerateProducesMonotonicResultsStartingWithAllBitsSetWithSameDate(): void { $dateTime = new DateTimeImmutable('now'); /** @var RandomGeneratorInterface&MockInterface $randomGenerator */ $randomGenerator = Mockery::mock(RandomGeneratorInterface::class); $randomGenerator->expects()->generate(16)->andReturns( "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", ); $randomGenerator->expects()->generate(10)->times(24)->andReturns( "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", ); $unixTimeGenerator = new UnixTimeGenerator($randomGenerator); $previous = ''; for ($i = 0; $i < 25; $i++) { $bytes = $unixTimeGenerator->generate(null, null, $dateTime); $this->assertTrue($bytes > $previous); } } /** * @runInSeparateProcess since values are stored statically on the class * @preserveGlobalState disabled */ public function testGenerateProducesMonotonicResultsStartingWithAllBitsSetFor32BitPath(): void { /** @var RandomGeneratorInterface&MockInterface $randomGenerator */ $randomGenerator = Mockery::mock(RandomGeneratorInterface::class); $randomGenerator->expects()->generate(16)->andReturns( "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", ); $randomGenerator->expects()->generate(10)->times(24)->andReturns( "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", ); $unixTimeGenerator = new UnixTimeGenerator($randomGenerator, 4); $previous = ''; for ($i = 0; $i < 25; $i++) { $bytes = $unixTimeGenerator->generate(); $this->assertTrue($bytes > $previous); } } /** * @runInSeparateProcess since values are stored statically on the class * @preserveGlobalState disabled */ public function testGenerateProducesMonotonicResultsStartingWithAllBitsSetWithSameDateFor32BitPath(): void { $dateTime = new DateTimeImmutable('now'); /** @var RandomGeneratorInterface&MockInterface $randomGenerator */ $randomGenerator = Mockery::mock(RandomGeneratorInterface::class); $randomGenerator->expects()->generate(16)->andReturns( "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", ); $randomGenerator->expects()->generate(10)->times(24)->andReturns( "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", ); $unixTimeGenerator = new UnixTimeGenerator($randomGenerator, 4); $previous = ''; for ($i = 0; $i < 25; $i++) { $bytes = $unixTimeGenerator->generate(null, null, $dateTime); $this->assertTrue($bytes > $previous); } } }