mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-24 17:35:57 +03:00
merge
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project maintainer at <ben@benramsey.com>. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
||||
|
||||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery
|
||||
* Personal attacks
|
||||
* Trolling or insulting/derogatory comments
|
||||
* Public or private harassment
|
||||
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
|
||||
* Other unethical or unprofessional conduct.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
|
||||
|
||||
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
Contributions are welcome. We accept pull requests on [GitHub](https://github.com/ramsey/uuid).
|
||||
|
||||
This project adheres to a [Contributor Code of Conduct](https://github.com/ramsey/uuid/blob/master/CONDUCT.md). By participating in this project and its community, you are expected to uphold this code.
|
||||
This project adheres to a [Contributor Code of Conduct](https://github.com/ramsey/uuid/blob/master/CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code.
|
||||
|
||||
## Team members
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ The ramsey/uuid library is copyright © [Ben Ramsey](https://benramsey.com/) and
|
||||
|
||||
|
||||
[rfc4122]: http://tools.ietf.org/html/rfc4122
|
||||
[conduct]: https://github.com/ramsey/uuid/blob/master/CONDUCT.md
|
||||
[conduct]: https://github.com/ramsey/uuid/blob/master/CODE_OF_CONDUCT.md
|
||||
[javauuid]: http://docs.oracle.com/javase/6/docs/api/java/util/UUID.html
|
||||
[pyuuid]: http://docs.python.org/3/library/uuid.html
|
||||
[packagist]: https://packagist.org/packages/ramsey/uuid
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
"jakub-onderka/php-parallel-lint": "^0.9.0",
|
||||
"satooshi/php-coveralls": "^0.6.1",
|
||||
"apigen/apigen": "^4.1",
|
||||
"mockery/mockery": "^0.9.4",
|
||||
"goaop/framework": "1.0.0-alpha.2",
|
||||
"codeception/aspect-mock": "1.0.0"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Ramsey\Uuid\Test\Builder;
|
||||
|
||||
use Ramsey\Uuid\Generator\CombGenerator;
|
||||
|
||||
class CombGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
private $timestampBytes = 6;
|
||||
|
||||
public function testGenerateUsesRandomGeneratorWithLengthMinusTimestampBytes()
|
||||
{
|
||||
$length = 10;
|
||||
$expectedLength = ($length - $this->timestampBytes);
|
||||
$randomGenerator = $this->getMock('Ramsey\Uuid\Generator\RandomGeneratorInterface');
|
||||
$randomGenerator->expects($this->once())
|
||||
->method('generate')
|
||||
->with($expectedLength);
|
||||
$converter = $this->getMock('Ramsey\Uuid\Converter\NumberConverterInterface');
|
||||
$generator = new CombGenerator($randomGenerator, $converter);
|
||||
$generator->generate($length);
|
||||
}
|
||||
|
||||
public function testGenerateCalculatesPaddedHexStringFromCurrentTimestamp()
|
||||
{
|
||||
$randomGenerator = $this->getMock('Ramsey\Uuid\Generator\RandomGeneratorInterface');
|
||||
$converter = $this->getMock('Ramsey\Uuid\Converter\NumberConverterInterface');
|
||||
$converter->expects($this->once())
|
||||
->method('toHex')
|
||||
->with($this->isType('string'));
|
||||
$generator = new CombGenerator($randomGenerator, $converter);
|
||||
$generator->generate(10);
|
||||
}
|
||||
|
||||
public function testGenerateReturnsBinaryStringCreatedFromGeneratorAndConverter()
|
||||
{
|
||||
$length = 20;
|
||||
$hash = dechex(1234567891);
|
||||
$timeHash = dechex(1458147405);
|
||||
|
||||
$randomGenerator = $this->getMock('Ramsey\Uuid\Generator\RandomGeneratorInterface');
|
||||
$randomGenerator->method('generate')
|
||||
->with(($length - $this->timestampBytes))
|
||||
->willReturn($hash);
|
||||
|
||||
$converter = $this->getMock('Ramsey\Uuid\Converter\NumberConverterInterface');
|
||||
$converter->method('toHex')
|
||||
->with($this->isType('string'))
|
||||
->willReturn($timeHash);
|
||||
|
||||
$time = str_pad($timeHash, 12, '0', STR_PAD_LEFT);
|
||||
$expected = hex2bin(str_pad(bin2hex($hash), $length - $this->timestampBytes, '0')) . hex2bin($time);
|
||||
|
||||
$generator = new CombGenerator($randomGenerator, $converter);
|
||||
$returned = $generator->generate($length);
|
||||
$this->assertInternalType('string', $returned);
|
||||
$this->assertEquals($expected, $returned);
|
||||
}
|
||||
|
||||
public function lengthLessThanSix()
|
||||
{
|
||||
return [[0], [1], [2], [3], [4], [5]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider lengthLessThanSix
|
||||
*/
|
||||
public function testGenerateWithLessThanTimestampBytesThrowsException($length)
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$randomGenerator = $this->getMock('Ramsey\Uuid\Generator\RandomGeneratorInterface');
|
||||
$converter = $this->getMock('Ramsey\Uuid\Converter\NumberConverterInterface');
|
||||
$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');
|
||||
$randomGenerator = $this->getMock('Ramsey\Uuid\Generator\RandomGeneratorInterface');
|
||||
$converter = $this->getMock('Ramsey\Uuid\Converter\NumberConverterInterface');
|
||||
$generator = new CombGenerator($randomGenerator, $converter);
|
||||
$generator->generate(7);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Ramsey\Uuid\Test\Builder;
|
||||
|
||||
use Ramsey\Uuid\Builder\DefaultUuidBuilder;
|
||||
|
||||
class DefaultUuidBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testBuildCreatesUuid()
|
||||
{
|
||||
$converter = $this->getMock('Ramsey\Uuid\Converter\NumberConverterInterface');
|
||||
$builder = new DefaultUuidBuilder($converter);
|
||||
$codec = $this->getMock('Ramsey\Uuid\Codec\CodecInterface');
|
||||
|
||||
$fields = [
|
||||
'time_low' => '754cd475',
|
||||
'time_mid' => '7e58',
|
||||
'time_hi_and_version' => '5411',
|
||||
'clock_seq_hi_and_reserved' => '73',
|
||||
'clock_seq_low' => '22',
|
||||
'node' => 'be0725c8ce01'
|
||||
];
|
||||
|
||||
$result = $builder->build($codec, $fields);
|
||||
$this->assertInstanceOf('Ramsey\Uuid\Uuid', $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Ramsey\Uuid\Test\Builder;
|
||||
|
||||
use Ramsey\Uuid\Builder\DegradedUuidBuilder;
|
||||
|
||||
class DegradedUuidBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testBuildCreatesUuid()
|
||||
{
|
||||
$converter = $this->getMock('Ramsey\Uuid\Converter\NumberConverterInterface');
|
||||
$builder = new DegradedUuidBuilder($converter);
|
||||
$codec = $this->getMock('Ramsey\Uuid\Codec\CodecInterface');
|
||||
|
||||
$fields = [
|
||||
'time_low' => '754cd475',
|
||||
'time_mid' => '7e58',
|
||||
'time_hi_and_version' => '5411',
|
||||
'clock_seq_hi_and_reserved' => '73',
|
||||
'clock_seq_low' => '22',
|
||||
'node' => 'be0725c8ce01'
|
||||
];
|
||||
|
||||
$result = $builder->build($codec, $fields);
|
||||
$this->assertInstanceOf('Ramsey\Uuid\DegradedUuid', $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Ramsey\Uuid\Test\Converter;
|
||||
|
||||
use Ramsey\Uuid\Converter\Time\PhpTimeConverter;
|
||||
|
||||
class PhpTimeConverterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testCalculateTimeReturnsArrayOfTimeSegments()
|
||||
{
|
||||
$seconds = 5;
|
||||
$microSeconds = 3;
|
||||
$calculatedTime = ($seconds * 10000000) + ($microSeconds * 10) + 0x01b21dd213814000;
|
||||
$expectedArray = [
|
||||
'low' => sprintf('%08x', $calculatedTime & 0xffffffff),
|
||||
'mid' => sprintf('%04x', ($calculatedTime >> 32) & 0xffff),
|
||||
'hi' => sprintf('%04x', ($calculatedTime >> 48) & 0x0fff)
|
||||
];
|
||||
|
||||
$converter = new PhpTimeConverter();
|
||||
$returned = $converter->calculateTime($seconds, $microSeconds);
|
||||
$this->assertEquals($expectedArray, $returned);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Ramsey\Uuid\Test\Generator;
|
||||
|
||||
use Ramsey\Uuid\Generator\MtRandGenerator;
|
||||
|
||||
class MtRandGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function lengthDataProvider()
|
||||
{
|
||||
return [
|
||||
[0],
|
||||
[1],
|
||||
[2],
|
||||
[16],
|
||||
[1000]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider lengthDataProvider
|
||||
*/
|
||||
public function testGenerateReturnsStringOfGivenLength($length)
|
||||
{
|
||||
$generator = new MtRandGenerator();
|
||||
$returned = $generator->generate($length);
|
||||
$this->assertEquals($length, strlen($returned));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Ramsey\Uuid\Test\Generator;
|
||||
|
||||
use Ramsey\Uuid\Generator\RandomLibAdapter;
|
||||
use Ramsey\Uuid\Test\TestCase;
|
||||
use Mockery;
|
||||
|
||||
class RandomLibAdapterTest extends TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testAdapterWithGeneratorDoesNotCreateGenerator()
|
||||
{
|
||||
$factory = Mockery::mock('overload:RandomLib\Factory');
|
||||
$factory->shouldNotReceive('getMediumStrengthGenerator')
|
||||
->getMock();
|
||||
|
||||
$generator = $this->getMockBuilder('RandomLib\Generator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
new RandomLibAdapter($generator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testAdapterWithoutGeneratorGreatesGenerator()
|
||||
{
|
||||
$factory = Mockery::mock('overload:RandomLib\Factory');
|
||||
$factory->shouldReceive('getMediumStrengthGenerator')
|
||||
->once()
|
||||
->getMock();
|
||||
|
||||
new RandomLibAdapter();
|
||||
}
|
||||
|
||||
public function testGenerateUsesGenerator()
|
||||
{
|
||||
$length = 10;
|
||||
$generator = $this->getMockBuilder('RandomLib\Generator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$generator->expects($this->once())
|
||||
->method('generate')
|
||||
->with($length);
|
||||
|
||||
$adapter = new RandomLibAdapter($generator);
|
||||
$adapter->generate($length);
|
||||
}
|
||||
|
||||
public function testGenerateReturnsString()
|
||||
{
|
||||
$generator = $this->getMockBuilder('RandomLib\Generator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$generator->expects($this->once())
|
||||
->method('generate')
|
||||
->willReturn('random-string');
|
||||
|
||||
$adapter = new RandomLibAdapter($generator);
|
||||
$result = $adapter->generate(1);
|
||||
$this->assertEquals('random-string', $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user