Skip to content

Commit 703a575

Browse files
authored
composer (#18)
* composer
1 parent 1998d30 commit 703a575

7 files changed

Lines changed: 81 additions & 16 deletions

File tree

.github/workflows/main.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
php-version: '8.0'
2222
tools: cs2pr, phpcs
2323
- name: Run phpcs
24-
run: phpcs -q --report=checkstyle *.php tests/*.php | cs2pr
24+
run: phpcs -q --report=checkstyle src/*.php tests/*.php | cs2pr
2525

2626
unit-tests:
2727
runs-on: ubuntu-20.04
@@ -34,6 +34,12 @@ jobs:
3434
uses: shivammathur/setup-php@2.15.0
3535
with:
3636
php-version: ${{ matrix.php-versions }}
37-
tools: phpunit
37+
tools: composer, phpunit
38+
- name: Install dependencies
39+
run: composer install
3840
- name: PHPUnit
39-
run: phpunit --coverage-text --whitelist uuid.php --bootstrap uuid.php tests
41+
run: phpunit --coverage-clover coverage.xml
42+
- name: Upload coverage to Codecov
43+
uses: codecov/codecov-action@v2.1.0
44+
with:
45+
flags: unittests

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
composer.lock
2+
coverage.xml
23
vendor/*
34
phpcs-report.xml
45
.php-cs-fixer.cache
6+
.phpunit.cache

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ A small PHP class for generating [RFC 4122](http://tools.ietf.org/html/rfc4122)
66

77
If all you want is a unique ID, you should call `uuid4()`.
88

9-
## Examples
9+
## Installation
10+
11+
```bash
12+
composer require oittaa/uuid
13+
```
14+
15+
## Usage
1016

1117
```php
1218
<?php
1319

14-
require_once 'uuid.php';
20+
require 'vendor/autoload.php';
1521

1622
use UUID\UUID;
1723

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "oittaa/uuid",
3+
"type": "library",
4+
"description": "A small PHP class for generating RFC 4122 version 3, 4, 5, and 6 (draft) universally unique identifiers (UUID).",
5+
"keywords": [
6+
"uuid",
7+
"identifier",
8+
"guid"
9+
],
10+
"license": "MIT",
11+
"require": {
12+
"php": "^7.4 || ^8.0"
13+
},
14+
"autoload": {
15+
"psr-4": {
16+
"UUID\\": "src/"
17+
}
18+
}
19+
}

phpunit.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheResultFile=".phpunit.cache/test-results"
6+
executionOrder="depends,defects"
7+
forceCoversAnnotation="true"
8+
beStrictAboutCoversAnnotation="true"
9+
beStrictAboutOutputDuringTests="true"
10+
beStrictAboutTodoAnnotatedTests="true"
11+
convertDeprecationsToExceptions="true"
12+
failOnRisky="true"
13+
failOnWarning="true"
14+
verbose="true">
15+
<testsuites>
16+
<testsuite name="default">
17+
<directory>tests</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<coverage cacheDirectory=".phpunit.cache/code-coverage"
22+
processUncoveredFiles="true">
23+
<include>
24+
<directory suffix=".php">src</directory>
25+
</include>
26+
</coverage>
27+
</phpunit>

uuid.php renamed to src/UUID.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace UUID;
46

57
/**

tests/UuidTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22

3-
namespace UUID;
3+
declare(strict_types=1);
4+
5+
namespace UUID\Test;
46

57
use PHPUnit\Framework\TestCase;
8+
use UUID\UUID;
69

710
/**
811
* @covers \UUID\UUID
@@ -11,7 +14,7 @@ final class UuidTest extends TestCase
1114
{
1215
public function testCanGenerateValidVersion3()
1316
{
14-
$this->assertEquals(
17+
$this->assertSame(
1518
'11a38b9a-b3da-360f-9353-a5a725514269',
1619
UUID::uuid3(UUID::NAMESPACE_DNS, 'php.net')
1720
);
@@ -33,7 +36,7 @@ public function testCanGenerateValidVersion4()
3336

3437
public function testCanGenerateValidVersion5()
3538
{
36-
$this->assertEquals(
39+
$this->assertSame(
3740
'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62',
3841
UUID::uuid5(UUID::NAMESPACE_DNS, 'php.net')
3942
);
@@ -97,19 +100,19 @@ public function testCanValidate()
97100

98101
public function testCanGetVersion()
99102
{
100-
$this->assertEquals(
103+
$this->assertSame(
101104
3,
102105
UUID::getVersion('11a38b9a-b3da-360f-9353-a5a725514269')
103106
);
104-
$this->assertEquals(
107+
$this->assertSame(
105108
5,
106109
UUID::getVersion('c4a760a8-dbcf-5254-a0d9-6a4474bd1b62')
107110
);
108111
}
109112

110113
public function testCanCompare()
111114
{
112-
$this->assertEquals(
115+
$this->assertSame(
113116
0,
114117
UUID::cmp('c4a760a8-dbcf-5254-a0d9-6a4474bd1b62', 'C4A760A8-DBCF-5254-A0D9-6A4474BD1B62')
115118
);
@@ -121,27 +124,27 @@ public function testCanCompare()
121124

122125
public function testToString()
123126
{
124-
$this->assertEquals(
127+
$this->assertSame(
125128
'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62',
126129
UUID::toString('{C4A760A8-DBCF-5254-A0D9-6A4474BD1B62}')
127130
);
128131
}
129132

130133
public function testCanUseAliases()
131134
{
132-
$this->assertEquals(
135+
$this->assertSame(
133136
'11a38b9a-b3da-360f-9353-a5a725514269',
134137
UUID::v3(UUID::NAMESPACE_DNS, 'php.net')
135138
);
136-
$this->assertEquals(
139+
$this->assertSame(
137140
4,
138141
UUID::getVersion(UUID::v4())
139142
);
140-
$this->assertEquals(
143+
$this->assertSame(
141144
'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62',
142145
UUID::v5(UUID::NAMESPACE_DNS, 'php.net')
143146
);
144-
$this->assertEquals(
147+
$this->assertSame(
145148
6,
146149
UUID::getVersion(UUID::v6())
147150
);

0 commit comments

Comments
 (0)