Skip to content

Commit 99dad94

Browse files
committed
Merge pull request #5 from php-middleware/up-code-coverage
Code coverage 100%
2 parents f1175c1 + 5a7b033 commit 99dad94

8 files changed

+178
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/vendor/
22
composer.lock
3-
phpunit-coverage-clover.xml
3+
tmp/

.scrutinizer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build:
77
tests:
88
override:
99
-
10-
command: 'phpunit --coverage-clover=phpunit-coverage-clover.xml'
10+
command: 'phpunit'
1111
coverage:
12-
file: 'phpunit-coverage-clover.xml'
12+
file: 'tmp/phpunit-coverage-clover.xml'
1313
format: 'php-clover'

phpunit.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
</testsuites>
99

1010
<logging>
11-
<log type="coverage-clover" target="phpunit-coverage-clover.xml"/>
11+
<log type="coverage-clover" target="tmp/phpunit-coverage-clover.xml"/>
12+
<log type="coverage-html" target="tmp/" />
1213
</logging>
1314

1415
<filter>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace PhpMiddlewareTestTest\RequestId\Generator;
4+
5+
use PhpMiddleware\RequestId\Generator\GeneratorInterface;
6+
use PhpMiddleware\RequestId\Generator\Md5Generator;
7+
use PHPUnit_Framework_TestCase;
8+
9+
class Md5GeneratorTest extends PHPUnit_Framework_TestCase
10+
{
11+
protected $generator;
12+
13+
protected function setUp()
14+
{
15+
$decoratedGenerator = $this->getMock(GeneratorInterface::class);
16+
$decoratedGenerator->method('generateRequestId')->willReturn('boo');
17+
18+
$this->generator = new Md5Generator($decoratedGenerator);
19+
}
20+
21+
public function testGetHashFromGeneratedValue()
22+
{
23+
$result = $this->generator->generateRequestId();
24+
25+
$this->assertSame('ae3e83e2fab3a7d8683d8eefabd1e74d', $result);
26+
}
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace PhpMiddlewareTestTest\RequestId\Generator;
4+
5+
use PhpMiddleware\RequestId\Generator\PhpUniqidGenerator;
6+
use PHPUnit_Framework_TestCase;
7+
8+
class PhpUniqidGeneratorTest extends PHPUnit_Framework_TestCase
9+
{
10+
protected $generator;
11+
12+
protected function setUp()
13+
{
14+
$this->generator = new PhpUniqidGenerator();
15+
}
16+
17+
public function testGetHashFromGeneratedValue()
18+
{
19+
$result = $this->generator->generateRequestId();
20+
21+
$this->assertNotEmpty($result);
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace PhpMiddlewareTestTest\RequestId\Generator;
4+
5+
use PhpMiddleware\RequestId\Generator\GeneratorInterface;
6+
use PhpMiddleware\RequestId\Generator\PrefixedGenerator;
7+
use PHPUnit_Framework_TestCase;
8+
9+
class PrefixedGeneratorTest extends PHPUnit_Framework_TestCase
10+
{
11+
protected $decoratedGenerator;
12+
13+
protected function setUp()
14+
{
15+
$this->decoratedGenerator = $this->getMock(GeneratorInterface::class);
16+
$this->decoratedGenerator->method('generateRequestId')->willReturn('boo');
17+
}
18+
19+
public function testGetHashFromGeneratedValue()
20+
{
21+
$result = $this->getGenerator('foo_')->generateRequestId();
22+
23+
$this->assertSame('foo_boo', $result);
24+
}
25+
26+
public function getGenerator($prefix)
27+
{
28+
return new PrefixedGenerator($prefix, $this->decoratedGenerator);
29+
}
30+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace PhpMiddlewareTestTest\RequestId\Generator;
4+
5+
use PhpMiddleware\RequestId\Generator\RamseyUuid4StaticGenerator;
6+
use PHPUnit_Framework_TestCase;
7+
use Ramsey\Uuid\Uuid;
8+
use Ramsey\Uuid\UuidInterface;
9+
10+
class RamseyUuid4StaticGeneratorTest extends PHPUnit_Framework_TestCase
11+
{
12+
protected $generator;
13+
14+
15+
protected function setUp()
16+
{
17+
$this->generator = new RamseyUuid4StaticGenerator();
18+
}
19+
20+
public function testGenerateId()
21+
{
22+
$uuidString = $this->generator->generateRequestId();
23+
24+
$uuid = Uuid::fromString($uuidString);
25+
26+
$this->assertInstanceOf(UuidInterface::class, $uuid);
27+
}
28+
}

0 commit comments

Comments
 (0)