|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PhpMiddlewareTestTest\RequestId\Generator; |
| 4 | + |
| 5 | +use PhpMiddleware\RequestId\Generator\RamseyUuid1Generator; |
| 6 | +use PhpMiddleware\RequestId\Generator\RamseyUuid3Generator; |
| 7 | +use PhpMiddleware\RequestId\Generator\RamseyUuid4Generator; |
| 8 | +use PhpMiddleware\RequestId\Generator\RamseyUuid5Generator; |
| 9 | +use PHPUnit_Framework_TestCase; |
| 10 | +use Ramsey\Uuid\UuidFactoryInterface; |
| 11 | +use Ramsey\Uuid\UuidInterface; |
| 12 | + |
| 13 | +class RamseyFactoryUuidGeneratorTest extends PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + protected $factory; |
| 16 | + protected $uuid; |
| 17 | + |
| 18 | + protected function setUp() |
| 19 | + { |
| 20 | + $this->factory = $this->getMock(UuidFactoryInterface::class); |
| 21 | + |
| 22 | + $this->uuid = $this->getMock(UuidInterface::class); |
| 23 | + $this->uuid->method('toString')->willReturn('uuid'); |
| 24 | + } |
| 25 | + |
| 26 | + public function testUuid1Generator() |
| 27 | + { |
| 28 | + $generator = new RamseyUuid1Generator($this->factory); |
| 29 | + $this->factory->method('uuid1')->willReturn($this->uuid); |
| 30 | + |
| 31 | + $result = $generator->generateRequestId(); |
| 32 | + |
| 33 | + $this->assertSame('uuid', $result); |
| 34 | + } |
| 35 | + |
| 36 | + public function testUuid3Generator() |
| 37 | + { |
| 38 | + $generator = new RamseyUuid3Generator($this->factory, 'ns', 'name'); |
| 39 | + $this->factory->method('uuid3')->with('ns', 'name')->willReturn($this->uuid); |
| 40 | + |
| 41 | + $result = $generator->generateRequestId(); |
| 42 | + |
| 43 | + $this->assertSame('uuid', $result); |
| 44 | + } |
| 45 | + |
| 46 | + public function testUuid4Generator() |
| 47 | + { |
| 48 | + $generator = new RamseyUuid4Generator($this->factory); |
| 49 | + $this->factory->method('uuid4')->willReturn($this->uuid); |
| 50 | + |
| 51 | + $result = $generator->generateRequestId(); |
| 52 | + |
| 53 | + $this->assertSame('uuid', $result); |
| 54 | + } |
| 55 | + |
| 56 | + public function testUuid5Generator() |
| 57 | + { |
| 58 | + $generator = new RamseyUuid5Generator($this->factory, 'ns', 'name'); |
| 59 | + $this->factory->method('uuid5')->with('ns', 'name')->willReturn($this->uuid); |
| 60 | + |
| 61 | + $result = $generator->generateRequestId(); |
| 62 | + |
| 63 | + $this->assertSame('uuid', $result); |
| 64 | + } |
| 65 | +} |
0 commit comments