Skip to content

Commit 47b2218

Browse files
authored
Add PHPUnit (#54)
1 parent 641ada7 commit 47b2218

File tree

7 files changed

+100
-3
lines changed

7 files changed

+100
-3
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/.* export-ignore
22
/tpayLibs/examples export-ignore
3+
/tests export-ignore
4+
/phpunit.xml export-ignore

.github/workflows/ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- uses: shivammathur/setup-php@v2
3030
with:
3131
php-version: ${{ matrix.php-version }}
32-
extensions: none, curl, json, mbstring
32+
extensions: none, curl, dom, json, mbstring, tokenizer, xml, xmlwriter
3333
coverage: none
3434

3535
- id: composer-cache
@@ -44,3 +44,5 @@ jobs:
4444
- run: composer update --no-progress --classmap-authoritative
4545

4646
- run: ./vendor/bin/parallel-lint ./tpayLibs/
47+
48+
- run: ./vendor/bin/phpunit

.github/workflows/sca.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: shivammathur/setup-php@v2
1414
with:
1515
php-version: 8.2
16-
extensions: none, curl, dom, mbstring, simplexml, tokenizer
16+
extensions: none, curl, dom, mbstring, simplexml, tokenizer, xml, xmlwriter
1717
coverage: none
1818

1919
- run: composer validate --strict

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717
"ext-curl": "*"
1818
},
1919
"require-dev": {
20-
"php-parallel-lint/php-parallel-lint": "^1.3.2"
20+
"php-parallel-lint/php-parallel-lint": "^1.3.2",
21+
"phpunit/phpunit": "^5.7.27 || ^9.6.10"
2122
},
2223
"autoload": {
2324
"classmap": [
2425
"tpayLibs/src/"
2526
]
2627
},
28+
"autoload-dev": {
29+
"psr-4": {
30+
"Tpay\\Tests\\": "tests/"
31+
}
32+
},
2733
"extra": [
2834
{
2935
"engine": "PHP SDK"

phpunit.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
3+
<phpunit
4+
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
5+
xsi:noNamespaceSchemaLocation='vendor/phpunit/phpunit/phpunit.xsd'
6+
beStrictAboutChangesToGlobalState='true'
7+
beStrictAboutOutputDuringTests='true'
8+
beStrictAboutTodoAnnotatedTests='true'
9+
bootstrap='./vendor/autoload.php'
10+
cacheResult='false'
11+
colors='true'
12+
columns='max'
13+
defaultTimeLimit='10'
14+
enforceTimeLimit='true'
15+
failOnRisky='true'
16+
failOnWarning='true'
17+
timeoutForSmallTests='10'
18+
timeoutForMediumTests='20'
19+
timeoutForLargeTests='30'
20+
verbose='true'
21+
>
22+
<testsuites>
23+
<testsuite name='all'>
24+
<directory>./tests</directory>
25+
</testsuite>
26+
</testsuites>
27+
28+
<php>
29+
<ini name='display_errors' value='1' />
30+
<ini name='display_startup_errors' value='1' />
31+
<ini name='error_reporting' value='-1' />
32+
</php>
33+
</phpunit>

tests/LegacyNamespaceTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Tpay\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
/**
8+
* @coversNothing
9+
*/
10+
class LegacyNamespaceTest extends TestCase
11+
{
12+
public function testClassesHaveUniqueNames()
13+
{
14+
$legacyClassShortNames = array_map(
15+
function ($className) {
16+
return (new \ReflectionClass($className))->getShortName();
17+
},
18+
self::getLegacyClassNames()
19+
);
20+
21+
self::assertSame(
22+
array_unique($legacyClassShortNames),
23+
$legacyClassShortNames
24+
);
25+
}
26+
27+
private static function getLegacyClassNames()
28+
{
29+
$modelDirectory = realpath(__DIR__.'/../tpayLibs/src');
30+
31+
$legacyClassNames = [];
32+
33+
/** @var \SplFileInfo $fileInfo */
34+
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($modelDirectory)) as $fileInfo) {
35+
if (!$fileInfo->isFile()) {
36+
continue;
37+
}
38+
if ('php' !== $fileInfo->getExtension()) {
39+
continue;
40+
}
41+
42+
$className = 'tpayLibs\\src\\'.substr(
43+
$fileInfo->getRealPath(),
44+
strlen($modelDirectory) + 1,
45+
-4
46+
);
47+
$className = str_replace('/', '\\', $className);
48+
49+
$legacyClassNames[] = $className;
50+
}
51+
52+
return $legacyClassNames;
53+
}
54+
}

0 commit comments

Comments
 (0)