mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Ensure that tests run even in cases when dev packages are not present
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
namespace Rhumsaa\Uuid\Console;
|
||||
|
||||
class TestCase extends \PHPUnit_Framework_TestCase
|
||||
use Rhumsaa\Uuid\TestCase as UuidTestCase;
|
||||
|
||||
class TestCase extends UuidTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Console\Application') || !class_exists('Moontoast\Math\BigNumber')) {
|
||||
$this->markTestSkipped(
|
||||
'symfony/console and moontoast/math are required to run these tests'
|
||||
);
|
||||
}
|
||||
$this->skipIfNoSymfonyConsole();
|
||||
$this->skipIfNoMoontoastMath();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,26 +3,24 @@ namespace Rhumsaa\Uuid;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Rhumsaa\Uuid\TestCase;
|
||||
|
||||
class UuidTypeTest extends PHPUnit_Framework_TestCase
|
||||
class UuidTypeTest extends TestCase
|
||||
{
|
||||
private $platform;
|
||||
private $type;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
Type::addType('uuid', 'Rhumsaa\Uuid\Doctrine\UuidType');
|
||||
if (class_exists('Doctrine\\DBAL\\Types\\Type')) {
|
||||
Type::addType('uuid', 'Rhumsaa\Uuid\Doctrine\UuidType');
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
// Skip these tests if run on a 32-bit build of PHP
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->markTestSkipped(
|
||||
'Running tests on a 32-bit build of PHP; 64-bit build required.'
|
||||
);
|
||||
}
|
||||
$this->skipIfNoDoctrineDbal();
|
||||
$this->skip64BitTest();
|
||||
|
||||
$this->platform = $this->getPlatformMock();
|
||||
$this->platform->expects($this->any())
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Rhumsaa\Uuid;
|
||||
|
||||
class TestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function skip64BitTest()
|
||||
{
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->markTestSkipped(
|
||||
'Skipping test that can run only on a 64-bit build of PHP.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function skipIfNoMoontoastMath()
|
||||
{
|
||||
if (!$this->hasMoontoastMath()) {
|
||||
$this->markTestSkipped(
|
||||
'Skipping test that requires moontoast/math.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function skipIfNoSymfonyConsole()
|
||||
{
|
||||
if (!$this->hasSymfonyConsole()) {
|
||||
$this->markTestSkipped(
|
||||
'Skipping test that requires symfony/console.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function skipIfNoDoctrineDbal()
|
||||
{
|
||||
if (!$this->hasDoctrineDbal()) {
|
||||
$this->markTestSkipped(
|
||||
'Skipping test that requires doctrine/dbal.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function hasMoontoastMath()
|
||||
{
|
||||
return class_exists('Moontoast\\Math\\BigNumber');
|
||||
}
|
||||
|
||||
protected function hasSymfonyConsole()
|
||||
{
|
||||
return class_exists('Symfony\\Component\\Console\\Application');
|
||||
}
|
||||
|
||||
protected function hasDoctrineDbal()
|
||||
{
|
||||
return class_exists('Doctrine\\DBAL\\Types\\Type');
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace Rhumsaa\Uuid;
|
||||
|
||||
class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
class UuidTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
@@ -12,18 +12,6 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
Uuid::$ignoreSystemNode = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the system is 32-bit, this will mark a test as skipped
|
||||
*/
|
||||
protected function skip64BitTest()
|
||||
{
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->markTestSkipped(
|
||||
'Skipping test that can run only on a 64-bit build of PHP.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Rhumsaa\Uuid\Uuid::fromString
|
||||
* @covers Rhumsaa\Uuid\Uuid::__construct
|
||||
@@ -160,6 +148,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testGetDateTime32Bit()
|
||||
{
|
||||
$this->skipIfNoMoontoastMath();
|
||||
Uuid::$force32Bit = true;
|
||||
|
||||
// Check a recent date
|
||||
@@ -265,6 +254,8 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testGetLeastSignificantBits()
|
||||
{
|
||||
$this->skipIfNoMoontoastMath();
|
||||
|
||||
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
|
||||
$this->assertInstanceOf('Moontoast\Math\BigNumber', $uuid->getLeastSignificantBits());
|
||||
$this->assertEquals('11178224546741000806', $uuid->getLeastSignificantBits()->getValue());
|
||||
@@ -295,6 +286,8 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testGetMostSignificantBits()
|
||||
{
|
||||
$this->skipIfNoMoontoastMath();
|
||||
|
||||
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
|
||||
$this->assertInstanceOf('Moontoast\Math\BigNumber', $uuid->getMostSignificantBits());
|
||||
$this->assertEquals('18406084892941947361', $uuid->getMostSignificantBits()->getValue());
|
||||
@@ -991,6 +984,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testCalculateUuidTimeForce32BitPath()
|
||||
{
|
||||
$this->skipIfNoMoontoastMath();
|
||||
Uuid::$force32Bit = true;
|
||||
|
||||
$timeOfDay = array(
|
||||
@@ -1078,6 +1072,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testCalculateUuidTimeUpperLowerBounds64BitThrough32BitPath()
|
||||
{
|
||||
$this->skipIfNoMoontoastMath();
|
||||
$this->skip64BitTest();
|
||||
|
||||
Uuid::$force32Bit = true;
|
||||
@@ -1121,6 +1116,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testCalculateUuidTimeUpperLowerBounds32Bit()
|
||||
{
|
||||
$this->skipIfNoMoontoastMath();
|
||||
Uuid::$force32Bit = true;
|
||||
|
||||
// 2038-01-19T03:14:07+00:00
|
||||
@@ -1206,6 +1202,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function test32BitMatch64BitForOneHourPeriod()
|
||||
{
|
||||
$this->skipIfNoMoontoastMath();
|
||||
$this->skip64BitTest();
|
||||
|
||||
$currentTime = strtotime('2012-12-11T00:00:00+00:00');
|
||||
@@ -1262,6 +1259,8 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testHasBigNumber()
|
||||
{
|
||||
$this->skipIfNoMoontoastMath();
|
||||
|
||||
$hasBigNumber = new \ReflectionMethod(
|
||||
'Rhumsaa\Uuid\Uuid', 'hasBigNumber'
|
||||
);
|
||||
@@ -1778,7 +1777,9 @@ class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($test['string'], (string) $uuid);
|
||||
$this->assertEquals($test['hex'], $uuid->getHex());
|
||||
$this->assertEquals(base64_decode($test['bytes']), $uuid->getBytes());
|
||||
$this->assertEquals($test['int'], (string) $uuid->getInteger());
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user