Prepare tests for running on PHP 8

This commit is contained in:
Ben Ramsey
2021-09-23 13:58:48 -05:00
parent e2ec78e3d9
commit c9ed6dd82f
25 changed files with 189 additions and 169 deletions
+7 -11
View File
@@ -68,7 +68,7 @@ jobs:
unit-tests:
name: "Unit Tests"
runs-on: "ubuntu-latest"
# continue-on-error: ${{ matrix.experimental }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
@@ -82,17 +82,13 @@ jobs:
- "7.2"
- "7.3"
- "7.4"
# Commenting out the following until I can work out a solution for the
# development libraries I use, since many of them or their dependencies
# do not support PHP 8.
#
# - "8.0"
# experimental:
# - false
- "8.0"
experimental:
- false
include:
# - php-version: "8.1"
# experimental: true
# composer-options: "--ignore-platform-req=php"
- php-version: "8.1"
experimental: true
composer-options: "--ignore-platform-req=php"
- php-version: "5.4"
extensions: ", libsodium-1.0.7, uuid-1.0.4"
- php-version: "5.5"
+3 -2
View File
@@ -34,10 +34,11 @@
"moontoast/math": "^1.1",
"nikic/php-parser": "<=4.5.0",
"paragonie/random-lib": "^2",
"php-mock/php-mock-phpunit": "^0.3 | ^1.1",
"php-mock/php-mock-phpunit": "^0.3 | ^1.1 | ^2.6",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpunit/phpunit": ">=4.8.36",
"squizlabs/php_codesniffer": "^3.5"
"squizlabs/php_codesniffer": "^3.5",
"yoast/phpunit-polyfills": "^1.0"
},
"suggest": {
"ext-ctype": "Provides support for PHP Ctype functions",
+4 -4
View File
@@ -22,9 +22,9 @@ class GuidStringCodecTest extends TestCase
/** @var array */
private $fields;
protected function setUp()
protected function set_up()
{
parent::setUp();
parent::set_up();
$this->builder = $this->getMockBuilder('Ramsey\Uuid\Builder\UuidBuilderInterface')->getMock();
$this->uuid = $this->getMockBuilder('Ramsey\Uuid\UuidInterface')->getMock();
$this->fields = ['time_low' => '12345678',
@@ -35,9 +35,9 @@ class GuidStringCodecTest extends TestCase
'node' => '1234abcd4321'];
}
protected function tearDown()
protected function tear_down()
{
parent::tearDown();
parent::tear_down();
$this->builder = null;
$this->fields = null;
$this->uuid = null;
+5 -5
View File
@@ -26,9 +26,9 @@ class OrderedTimeCodecTest extends TestCase
/** @var string */
private $optimizedHex = '11d8eebc58e0a7d796690800200c9a66';
protected function setUp()
protected function set_up()
{
parent::setUp();
parent::set_up();
$this->builder = $this->getMockBuilder('Ramsey\Uuid\Builder\UuidBuilderInterface')->getMock();
$this->uuid = $this->getMockBuilder('Ramsey\Uuid\UuidInterface')->getMock();
$this->fields = ['time_low' => '58e0a7d7',
@@ -39,9 +39,9 @@ class OrderedTimeCodecTest extends TestCase
'node' => '0800200c9a66'];
}
protected function tearDown()
protected function tear_down()
{
parent::tearDown();
parent::tear_down();
$this->builder = null;
$this->uuid = null;
$this->fields = null;
@@ -89,7 +89,7 @@ class OrderedTimeCodecTest extends TestCase
$string = '61';
$bytes = pack('H*', $string);
$codec = new OrderedTimeCodec($this->builder);
$this->setExpectedException('InvalidArgumentException', '$bytes string should contain 16 characters.');
$this->expectException('InvalidArgumentException', '$bytes string should contain 16 characters.');
$codec->decodeBytes($bytes);
}
+6 -6
View File
@@ -24,9 +24,9 @@ class StringCodecTest extends TestCase
/** @var string */
private $uuidString = '12345678-1234-abcd-abef-1234abcd4321';
protected function setUp()
protected function set_up()
{
parent::setUp();
parent::set_up();
$this->builder = $this->getMockBuilder('Ramsey\Uuid\Builder\UuidBuilderInterface')->getMock();
$this->uuid = $this->getMockBuilder('Ramsey\Uuid\UuidInterface')->getMock();
$this->fields = ['time_low' => '12345678',
@@ -37,9 +37,9 @@ class StringCodecTest extends TestCase
'node' => '1234abcd4321'];
}
protected function tearDown()
protected function tear_down()
{
parent::tearDown();
parent::tear_down();
$this->builder = null;
$this->uuid = null;
$this->fields = null;
@@ -95,7 +95,7 @@ class StringCodecTest extends TestCase
public function testDecodeThrowsExceptionOnInvalidUuid()
{
$string = 'invalid-uuid';
$this->setExpectedException('\InvalidArgumentException');
$this->expectException('\InvalidArgumentException');
$codec = new StringCodec($this->builder);
$codec->decode($string);
}
@@ -115,7 +115,7 @@ class StringCodecTest extends TestCase
$string = '61';
$bytes = pack('H*', $string);
$codec = new StringCodec($this->builder);
$this->setExpectedException('InvalidArgumentException', '$bytes string should contain 16 characters.');
$this->expectException('InvalidArgumentException', '$bytes string should contain 16 characters.');
$codec->decodeBytes($bytes);
}
@@ -12,23 +12,21 @@ use Ramsey\Uuid\Converter\Number\DegradedNumberConverter;
*/
class DegradedNumberConverterTest extends TestCase
{
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testConvertingFromHexThrowsException()
{
$converter = new DegradedNumberConverter();
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$converter->fromHex('ffff');
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testConvertingToHexThrowsException()
{
$converter = new DegradedNumberConverter();
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$converter->toHex(0);
}
}
@@ -18,8 +18,9 @@ class TimestampFirstCombCodecTest extends TestCase
*/
private $builderMock;
protected function setUp()
protected function set_up()
{
parent::set_up();
$this->builderMock = $this->getMockBuilder('Ramsey\Uuid\Builder\UuidBuilderInterface')->getMock();
$this->codec = new TimestampFirstCombCodec($this->builderMock);
}
+2 -1
View File
@@ -18,8 +18,9 @@ class TimestampLastCombCodecTest extends TestCase
*/
private $builderMock;
protected function setUp()
protected function set_up()
{
parent::set_up();
$this->builderMock = $this->getMockBuilder('Ramsey\Uuid\Builder\UuidBuilderInterface')->getMock();
$this->codec = new TimestampLastCombCodec($this->builderMock);
}
+11 -11
View File
@@ -32,27 +32,27 @@ class ExpectedBehaviorTest extends TestCase
$uuid = call_user_func_array(['Ramsey\Uuid\Uuid', $method], $args);
$this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid);
$this->assertInternalType('int', $uuid->compareTo(Uuid::uuid1()));
$this->assertIsInt($uuid->compareTo(Uuid::uuid1()));
$this->assertNotSame(0, $uuid->compareTo(Uuid::uuid4()));
$this->assertSame(0, $uuid->compareTo(clone $uuid));
$this->assertFalse($uuid->equals(new stdClass()));
$this->assertTrue($uuid->equals(clone $uuid));
$this->assertInternalType('string', $uuid->getBytes());
$this->assertIsString($uuid->getBytes());
$this->assertInstanceOf('Ramsey\Uuid\Converter\NumberConverterInterface', $uuid->getNumberConverter());
$this->assertInternalType('string', $uuid->getHex());
$this->assertInternalType('array', $uuid->getFieldsHex());
$this->assertIsString($uuid->getHex());
$this->assertIsArray($uuid->getFieldsHex());
$this->assertArrayHasKey('time_low', $uuid->getFieldsHex());
$this->assertArrayHasKey('time_mid', $uuid->getFieldsHex());
$this->assertArrayHasKey('time_hi_and_version', $uuid->getFieldsHex());
$this->assertArrayHasKey('clock_seq_hi_and_reserved', $uuid->getFieldsHex());
$this->assertArrayHasKey('clock_seq_low', $uuid->getFieldsHex());
$this->assertArrayHasKey('node', $uuid->getFieldsHex());
$this->assertInternalType('string', $uuid->getTimeLowHex());
$this->assertInternalType('string', $uuid->getTimeMidHex());
$this->assertInternalType('string', $uuid->getTimeHiAndVersionHex());
$this->assertInternalType('string', $uuid->getClockSeqHiAndReservedHex());
$this->assertInternalType('string', $uuid->getClockSeqLowHex());
$this->assertInternalType('string', $uuid->getNodeHex());
$this->assertIsString($uuid->getTimeLowHex());
$this->assertIsString($uuid->getTimeMidHex());
$this->assertIsString($uuid->getTimeHiAndVersionHex());
$this->assertIsString($uuid->getClockSeqHiAndReservedHex());
$this->assertIsString($uuid->getClockSeqLowHex());
$this->assertIsString($uuid->getNodeHex());
$this->assertSame($uuid->getFieldsHex()['time_low'], $uuid->getTimeLowHex());
$this->assertSame($uuid->getFieldsHex()['time_mid'], $uuid->getTimeMidHex());
$this->assertSame($uuid->getFieldsHex()['time_hi_and_version'], $uuid->getTimeHiAndVersionHex());
@@ -82,7 +82,7 @@ class ExpectedBehaviorTest extends TestCase
. $uuid->getFieldsHex()['node']
);
$this->assertInternalType('string', $uuid->getUrn());
$this->assertIsString($uuid->getUrn());
$this->assertStringStartsWith('urn:uuid:', $uuid->getUrn());
$this->assertSame('urn:uuid:' . $uuid->getHex(), str_replace('-', '', $uuid->getUrn()));
$this->assertSame($uuid->getHex(), str_replace('-', '', $uuid->toString()));
+4 -4
View File
@@ -10,7 +10,7 @@ class FunctionsTest extends TestCase
{
$v1 = \Ramsey\Uuid\v1();
$this->assertInternalType('string', $v1);
$this->assertIsString($v1);
$this->assertSame(Uuid::UUID_TYPE_TIME, Uuid::fromString($v1)->getVersion());
}
@@ -19,7 +19,7 @@ class FunctionsTest extends TestCase
$ns = Uuid::fromString(Uuid::NAMESPACE_URL);
$v3 = \Ramsey\Uuid\v3($ns, 'https://example.com/foo');
$this->assertInternalType('string', $v3);
$this->assertIsString($v3);
$this->assertSame(Uuid::UUID_TYPE_HASH_MD5, Uuid::fromString($v3)->getVersion());
}
@@ -27,7 +27,7 @@ class FunctionsTest extends TestCase
{
$v4 = \Ramsey\Uuid\v4();
$this->assertInternalType('string', $v4);
$this->assertIsString($v4);
$this->assertSame(Uuid::UUID_TYPE_RANDOM, Uuid::fromString($v4)->getVersion());
}
@@ -36,7 +36,7 @@ class FunctionsTest extends TestCase
$ns = Uuid::fromString(Uuid::NAMESPACE_URL);
$v5 = \Ramsey\Uuid\v5($ns, 'https://example.com/foo');
$this->assertInternalType('string', $v5);
$this->assertIsString($v5);
$this->assertSame(Uuid::UUID_TYPE_HASH_SHA1, Uuid::fromString($v5)->getVersion());
}
}
+3 -6
View File
@@ -59,7 +59,7 @@ class CombGeneratorTest extends TestCase
$generator = new CombGenerator($randomGenerator, $converter);
$returned = $generator->generate($length);
$this->assertInternalType('string', $returned);
$this->assertIsString($returned);
$this->assertEquals($expected, $returned);
}
@@ -75,19 +75,16 @@ class CombGeneratorTest extends TestCase
*/
public function testGenerateWithLessThanTimestampBytesThrowsException($length)
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
$randomGenerator = $this->getMockBuilder('Ramsey\Uuid\Generator\RandomGeneratorInterface')->getMock();
$converter = $this->getMockBuilder('Ramsey\Uuid\Converter\NumberConverterInterface')->getMock();
$generator = new CombGenerator($randomGenerator, $converter);
$generator->generate($length);
}
/**
* PHP Unit converts the error to an exception so we can test it.
*/
public function testGenerateWithOddNumberOverTimestampBytesCausesError()
{
$this->setExpectedException('PHPUnit_Framework_Error');
$this->expectError();
$randomGenerator = $this->getMockBuilder('Ramsey\Uuid\Generator\RandomGeneratorInterface')->getMock();
$converter = $this->getMockBuilder('Ramsey\Uuid\Converter\NumberConverterInterface')->getMock();
$generator = new CombGenerator($randomGenerator, $converter);
+6 -8
View File
@@ -27,10 +27,9 @@ class DefaultTimeGeneratorTest extends TestCase
/** @var int */
private $clockSeq = 4066;
protected function setUp()
protected function set_up()
{
parent::setUp();
parent::set_up();
$this->timeProvider = $this->getMockBuilder('Ramsey\Uuid\Provider\TimeProviderInterface')->getMock();
$this->nodeProvider = $this->getMockBuilder('Ramsey\Uuid\Provider\NodeProviderInterface')->getMock();
$this->timeConverter = $this->getMockBuilder('Ramsey\Uuid\Converter\TimeConverterInterface')->getMock();
@@ -38,14 +37,12 @@ class DefaultTimeGeneratorTest extends TestCase
$this->calculatedTime = ["low" => "83cb98e0", "mid" => "98e0", "hi" => "03cb"];
}
protected function tearDown()
protected function tear_down()
{
parent::tearDown();
parent::tear_down();
$this->timeProvider = null;
$this->nodeProvider = null;
$this->timeConverter = null;
Mockery::close();
AspectMock::clean();
}
public function testGenerateUsesNodeProviderWhenNodeIsNull()
@@ -125,7 +122,7 @@ class DefaultTimeGeneratorTest extends TestCase
$this->timeConverter,
$this->timeProvider
);
$defaultTimeGenerator->generate($this->nodeId, $this->clockSeq);
$this->assertIsString($defaultTimeGenerator->generate($this->nodeId, $this->clockSeq));
}
/**
@@ -170,6 +167,7 @@ class DefaultTimeGeneratorTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGenerateUsesRandomSequenceWhenClockSeqNull()
{
+2
View File
@@ -26,6 +26,7 @@ class OpenSslGeneratorTest extends TestCase
* @dataProvider lengthAndHexDataProvider
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
* @param $length
* @param $hex
*/
@@ -43,6 +44,7 @@ class OpenSslGeneratorTest extends TestCase
* @dataProvider lengthAndHexDataProvider
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
* @param $length
* @param $hex
*/
@@ -17,6 +17,8 @@ class PeclUuidRandomGeneratorTest extends PeclUuidTestCase
* This test is just to check collaboration with the PECL UUID extension - not to check
* the correctness of the methods defined in that extension.
* So we are just checking that the UUID methods are called with the right parameters.
*
* @requires PHP < 8
*/
public function testGenerateCreatesUuidUsingPeclUuidMethods()
{
@@ -33,6 +35,8 @@ class PeclUuidRandomGeneratorTest extends PeclUuidTestCase
/**
* This test is for the return type of the generate method
* It ensures that the generate method returns whatever value uuid_parse returns.
*
* @requires PHP < 8
*/
public function testGenerateReturnsUuidString()
{
@@ -16,6 +16,8 @@ class PeclUuidTimeGeneratorTest extends PeclUuidTestCase
* This test is just to check collaboration with the PECL UUID extension - not to check
* the correctness of the methods defined in that extension.
* So we are just checking that the UUID methods are called with the right parameters.
*
* @requires PHP < 8
*/
public function testGenerateCreatesUuidUsingPeclUuidMethods()
{
@@ -32,6 +34,8 @@ class PeclUuidTimeGeneratorTest extends PeclUuidTestCase
/**
* This test is for the return type of the generate method
* It ensures that the generate method returns whatever value uuid_parse returns.
*
* @requires PHP < 8
*/
public function testGenerateReturnsUuidString()
{
@@ -26,6 +26,7 @@ class RandomBytesGeneratorTest extends TestCase
* @dataProvider lengthAndHexDataProvider
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
* @param int $length
* @param string $hex
* @throws \Exception
@@ -44,6 +45,7 @@ class RandomBytesGeneratorTest extends TestCase
* @dataProvider lengthAndHexDataProvider
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
* @param int $length
* @param string $hex
* @throws \Exception
+9 -2
View File
@@ -26,7 +26,11 @@ class RandomLibAdapterTest extends TestCase
$generator = $this->getMockBuilder('RandomLib\Generator')
->disableOriginalConstructor()
->getMock();
new RandomLibAdapter($generator);
$this->assertInstanceOf(
'Ramsey\Uuid\Generator\RandomGeneratorInterface',
new RandomLibAdapter($generator)
);
}
/**
@@ -40,7 +44,10 @@ class RandomLibAdapterTest extends TestCase
->once()
->getMock();
new RandomLibAdapter();
$this->assertInstanceOf(
'Ramsey\Uuid\Generator\RandomGeneratorInterface',
new RandomLibAdapter()
);
}
public function testGenerateUsesGenerator()
@@ -28,7 +28,7 @@ class SodiumRandomGeneratorTest extends TestCase
$bytes = $generator->generate(16);
$this->assertInternalType('string', $bytes);
$this->assertIsString($bytes);
$this->assertEquals(16, strlen($bytes));
}
@@ -8,15 +8,10 @@ use AspectMock\Test as AspectMock;
class RandomNodeProviderTest extends TestCase
{
protected function tearDown()
{
parent::tearDown();
AspectMock::clean();
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGetNodeUsesRandomBytes()
{
@@ -31,6 +26,7 @@ class RandomNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGetNodeSetsMulticastBit()
{
@@ -48,6 +44,7 @@ class RandomNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGetNodeAlreadyHasMulticastBit()
{
@@ -66,6 +63,7 @@ class RandomNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGetNodeSetsMulticastBitForLowNodeValue()
{
@@ -50,6 +50,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*
* @dataProvider provideValidNetStatOutput
*
@@ -88,6 +89,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*
* @dataProvider provideInvalidNetStatOutput
*
@@ -119,6 +121,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*
* @dataProvider provideNotationalFormats
*
@@ -151,6 +154,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*
* @dataProvider provideInvalidNotationalFormats
*
@@ -182,6 +186,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGetNodeReturnsFirstMacAddressFound()
{
@@ -209,6 +214,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGetNodeReturnsFalseWhenNodeIsNotFound()
{
@@ -236,6 +242,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGetNodeWillNotExecuteSystemCallIfFailedFirstTime()
{
@@ -262,6 +269,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*
* @dataProvider provideCommandPerOs
*
@@ -306,6 +314,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGetNodeReturnsSameNodeUponSubsequentCalls()
{
@@ -334,6 +343,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testSubsequentCallsToGetNodeDoNotRecallIfconfig()
{
@@ -362,6 +372,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*
* @dataProvider provideCommandPerOs
*
@@ -420,6 +431,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testCallGetsysfsOnLinuxWhenGlobReturnsFalse()
{
@@ -453,6 +465,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testCallGetsysfsOnLinuxWhenGlobReturnsEmptyArray()
{
@@ -486,6 +499,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testCallGetsysfsOnLinuxWhenGlobFilesAreNotReadable()
{
@@ -522,6 +536,7 @@ class SystemNodeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testGetNodeReturnsFalseWhenPassthruIsDisabled()
{
@@ -10,7 +10,7 @@ class FixedTimeProviderTest extends TestCase
public function testConstructorRequiresSecAndUsec()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
$provider = new FixedTimeProvider([]);
}
@@ -20,6 +20,7 @@ class SystemTimeProviderTest extends TestCase
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @requires PHP < 8
*/
public function testCurrentTimeUsesGettimeofday()
{
+9 -5
View File
@@ -3,14 +3,18 @@ namespace Ramsey\Uuid\Test;
use AspectMock\Test as AspectMock;
use Mockery;
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase as YoastTestCase;
class TestCase extends PhpUnitTestCase
class TestCase extends YoastTestCase
{
protected function tearDown()
protected function tear_down()
{
parent::tearDown();
AspectMock::clean();
parent::tear_down();
if (PHP_MAJOR_VERSION < 8) {
AspectMock::clean();
}
Mockery::close();
}
+72 -83
View File
@@ -14,8 +14,9 @@ use stdClass;
class UuidTest extends TestCase
{
protected function setUp()
protected function set_up()
{
parent::set_up();
Uuid::setFactory(new UuidFactory());
}
@@ -80,21 +81,19 @@ class UuidTest extends TestCase
$this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString());
}
/**
* @expectedException Ramsey\Uuid\Exception\InvalidUuidStringException
* @expectedExceptionMessage Invalid UUID string:
*/
public function testFromStringWithInvalidUuidString()
{
$this->expectException('Ramsey\Uuid\Exception\InvalidUuidStringException');
$this->expectExceptionMessage('Invalid UUID string:');
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21');
}
/**
* @expectedException Ramsey\Uuid\Exception\InvalidUuidStringException
* @expectedExceptionMessage Invalid UUID string:
*/
public function testFromStringWithTrailingNewLine()
{
$this->expectException('Ramsey\Uuid\Exception\InvalidUuidStringException');
$this->expectExceptionMessage('Invalid UUID string:');
Uuid::fromString("d0d5f586-21d1-470c-8088-55c8857728dc\n");
}
@@ -225,9 +224,6 @@ class UuidTest extends TestCase
$this->assertSame('-12219292800', $uuid->getDateTime()->format('U'));
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testGetDateTimeThrownException()
{
Uuid::setFactory(new UuidFactory(new FeatureSet(false, true, true)));
@@ -237,15 +233,16 @@ class UuidTest extends TestCase
$this->assertInstanceOf('Ramsey\Uuid\DegradedUuid', $uuid);
$this->assertInstanceOf('Ramsey\Uuid\Converter\Number\DegradedNumberConverter', $uuid->getNumberConverter());
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$date = $uuid->getDateTime();
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsupportedOperationException
* @expectedExceptionMessage Not a time-based UUID
*/
public function testGetDateTimeFromNonVersion1Uuid()
{
$this->expectException('Ramsey\Uuid\Exception\UnsupportedOperationException');
$this->expectExceptionMessage('Not a time-based UUID');
// Using a version 4 UUID to test
$uuid = Uuid::fromString('bf17b594-41f2-474f-bf70-4c90220f75de');
$date = $uuid->getDateTime();
@@ -271,14 +268,14 @@ class UuidTest extends TestCase
$this->assertEquals($fields, $uuid->getFields());
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testGetFields32Bit()
{
Uuid::setFactory(new UuidFactory(new FeatureSet(false, true)));
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$fields = $uuid->getFields();
}
@@ -311,14 +308,14 @@ class UuidTest extends TestCase
$this->assertEquals('11178224546741000806', $uuid->getLeastSignificantBits()->getValue());
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testGetLeastSignificantBitsException()
{
Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, true)));
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$bn = $uuid->getLeastSignificantBits();
}
@@ -341,14 +338,14 @@ class UuidTest extends TestCase
$this->assertEquals('18406084892941947361', $uuid->getMostSignificantBits()->getValue());
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testGetMostSignificantBitsException()
{
Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, true)));
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$bn = $uuid->getMostSignificantBits();
}
@@ -370,14 +367,14 @@ class UuidTest extends TestCase
$this->assertEquals(8796630719078, $uuid->getNode());
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testGetNode32Bit()
{
Uuid::setFactory(new UuidFactory(new FeatureSet(false, true)));
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$node = $uuid->getNode();
}
@@ -415,14 +412,14 @@ class UuidTest extends TestCase
$this->assertEquals(4285500592, $uuid->getTimeLow());
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testGetTimeLow32Bit()
{
Uuid::setFactory(new UuidFactory(new FeatureSet(false, true)));
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$timeLow = $uuid->getTimeLow();
}
@@ -478,36 +475,36 @@ class UuidTest extends TestCase
$this->assertEquals('00001540901e600', $uuid->getTimestampHex());
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsupportedOperationException
* @expectedExceptionMessage Not a time-based UUID
*/
public function testGetTimestampFromNonVersion1Uuid()
{
// Using a version 4 UUID to test
$uuid = Uuid::fromString('bf17b594-41f2-474f-bf70-4c90220f75de');
$this->expectException('Ramsey\Uuid\Exception\UnsupportedOperationException');
$this->expectExceptionMessage('Not a time-based UUID');
$ts = $uuid->getTimestamp();
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsupportedOperationException
* @expectedExceptionMessage Not a time-based UUID
*/
public function testGetTimestampHexFromNonVersion1Uuid()
{
// Using a version 4 UUID to test
$uuid = Uuid::fromString('bf17b594-41f2-474f-bf70-4c90220f75de');
$this->expectException('Ramsey\Uuid\Exception\UnsupportedOperationException');
$this->expectExceptionMessage('Not a time-based UUID');
$ts = $uuid->getTimestampHex();
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testGetTimestamp32Bit()
{
Uuid::setFactory(new UuidFactory(new FeatureSet(false, true)));
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$ts = $uuid->getTimestamp();
}
@@ -721,30 +718,27 @@ class UuidTest extends TestCase
}
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid node value
*/
public function testUuid1WithOutOfBoundsNode()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid node value');
$uuid = Uuid::uuid1(9223372036854775808);
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid node value
*/
public function testUuid1WithNonHexadecimalNode()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid node value');
$uuid = Uuid::uuid1('db77e160355g');
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid node value
*/
public function testUuid1WithNon48bitNumber()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid node value');
$uuid = Uuid::uuid1('db77e160355ef');
}
@@ -1349,13 +1343,12 @@ class UuidTest extends TestCase
}
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testCalculateUuidTimeThrownException()
{
Uuid::setFactory(new UuidFactory(new FeatureSet(false, true, true)));
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$uuid = Uuid::uuid1(0x00007ffffffe, 0x1669);
}
@@ -1515,19 +1508,17 @@ class UuidTest extends TestCase
$this->assertEquals($guid->toString(), $parsedGuid->toString());
}
/**
* @expectedException InvalidArgumentException
*/
public function testFromBytesArgumentTooShort()
{
$this->expectException('InvalidArgumentException');
Uuid::fromBytes('thisisveryshort');
}
/**
* @expectedException InvalidArgumentException
*/
public function testFromBytesArgumentTooLong()
{
$this->expectException('InvalidArgumentException');
Uuid::fromBytes('thisisabittoolong');
}
@@ -1865,32 +1856,32 @@ class UuidTest extends TestCase
if ($this->hasMoontoastMath()) {
$this->assertEquals($test['int'], (string)$uuid->getInteger());
}
$this->assertEquals($test['fields'], $uuid->getFieldsHex());
$this->assertEquals($test['fields']['time_low'], $uuid->getTimeLowHex());
$this->assertEquals($test['fields']['time_mid'], $uuid->getTimeMidHex());
$this->assertEquals($test['fields']['time_hi_and_version'], $uuid->getTimeHiAndVersionHex());
$this->assertEquals($test['fields']['clock_seq_hi_and_reserved'], $uuid->getClockSeqHiAndReservedHex());
$this->assertEquals($test['fields']['clock_seq_low'], $uuid->getClockSeqLowHex());
$this->assertEquals($test['fields']['node'], $uuid->getNodeHex());
$this->assertTrue($test['fields'] == $uuid->getFieldsHex());
$this->assertTrue($test['fields']['time_low'] == $uuid->getTimeLowHex());
$this->assertTrue($test['fields']['time_mid'] == $uuid->getTimeMidHex());
$this->assertTrue($test['fields']['time_hi_and_version'] == $uuid->getTimeHiAndVersionHex());
$this->assertTrue($test['fields']['clock_seq_hi_and_reserved'] == $uuid->getClockSeqHiAndReservedHex());
$this->assertTrue($test['fields']['clock_seq_low'] == $uuid->getClockSeqLowHex());
$this->assertTrue($test['fields']['node'] == $uuid->getNodeHex());
$this->assertEquals($test['urn'], $uuid->getUrn());
if ($uuid->getVersion() == 1) {
$this->assertEquals($test['time'], $uuid->getTimestampHex());
$this->assertTrue($test['time'] == $uuid->getTimestampHex());
}
$this->assertEquals($test['clock_seq'], $uuid->getClockSequenceHex());
$this->assertTrue($test['clock_seq'] == $uuid->getClockSequenceHex());
$this->assertEquals($test['variant'], $uuid->getVariant());
$this->assertEquals($test['version'], $uuid->getVersion());
}
}
}
/**
* @expectedException Ramsey\Uuid\Exception\UnsatisfiedDependencyException
*/
public function testGetInteger()
{
Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, true)));
$uuid = Uuid::uuid1();
$this->expectException('Ramsey\Uuid\Exception\UnsatisfiedDependencyException');
$uuid->getInteger();
}
@@ -1912,12 +1903,11 @@ class UuidTest extends TestCase
$this->assertTrue($uuid->equals($unserializedUuid));
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid UUID string:
*/
public function testUuid3WithEmptyNamespace()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid UUID string:');
$uuid = Uuid::uuid3('', '');
}
@@ -1949,12 +1939,11 @@ class UuidTest extends TestCase
$this->assertEquals('19826852-5007-3022-a72a-212f66e9fac3', $uuid->toString());
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid UUID string:
*/
public function testUuid5WithEmptyNamespace()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid UUID string:');
$uuid = Uuid::uuid5('', '');
}
+8 -6
View File
@@ -8,9 +8,11 @@ use AspectMock\Kernel;
require_once __DIR__ . '/../vendor/autoload.php'; // composer autoload
require_once __DIR__ . '/phpstan-bootstrap.php';
$kernel = Kernel::getInstance();
$kernel->init([
'debug' => true,
'cacheDir' => sys_get_temp_dir(),
'includePaths' => [__DIR__ . '/../src']
]);
if (PHP_MAJOR_VERSION < 8) {
$kernel = Kernel::getInstance();
$kernel->init([
'debug' => true,
'cacheDir' => sys_get_temp_dir(),
'includePaths' => [__DIR__ . '/../src']
]);
}