Skip to content

Commit

Permalink
Add PHPUnit (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Aug 16, 2023
1 parent ade2dc4 commit 8d2e671
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
@@ -1,2 +1,4 @@
/.* export-ignore
/Examples export-ignore
/tests export-ignore
/phpunit.xml export-ignore
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: none, curl, json, mbstring
extensions: none, curl, dom, json, mbstring, tokenizer, xml, xmlwriter
coverage: none

- id: composer-cache
Expand All @@ -44,3 +44,5 @@ jobs:
- run: composer update --no-progress --classmap-authoritative

- run: ./vendor/bin/parallel-lint . --exclude vendor

- run: ./vendor/bin/phpunit
2 changes: 1 addition & 1 deletion .github/workflows/sca.yaml
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: none, curl, dom, mbstring, simplexml, tokenizer
extensions: none, curl, dom, mbstring, simplexml, tokenizer, xml, xmlwriter
coverage: none

- run: composer update --no-progress --classmap-authoritative
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Expand Up @@ -21,7 +21,8 @@
"phpseclib/phpseclib": "^2 || ^3"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.3.2"
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpunit/phpunit": "^5.7.27 || ^9.6.10"
},
"autoload": {
"psr-4": {
Expand All @@ -31,6 +32,11 @@
"**/Examples/"
]
},
"autoload-dev": {
"psr-4": {
"Tpay\\Tests\\": "tests/"
}
},
"extra": [
{
"engine": "PHP SDK"
Expand Down
33 changes: 33 additions & 0 deletions phpunit.xml
@@ -0,0 +1,33 @@
<?xml version='1.0' encoding='UTF-8'?>

<phpunit
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='vendor/phpunit/phpunit/phpunit.xsd'
beStrictAboutChangesToGlobalState='true'
beStrictAboutOutputDuringTests='true'
beStrictAboutTodoAnnotatedTests='true'
bootstrap='./vendor/autoload.php'
cacheResult='false'
colors='true'
columns='max'
defaultTimeLimit='10'
enforceTimeLimit='true'
failOnRisky='true'
failOnWarning='true'
timeoutForSmallTests='10'
timeoutForMediumTests='20'
timeoutForLargeTests='30'
verbose='true'
>
<testsuites>
<testsuite name='all'>
<directory>./tests</directory>
</testsuite>
</testsuites>

<php>
<ini name='display_errors' value='1' />
<ini name='display_startup_errors' value='1' />
<ini name='error_reporting' value='-1' />
</php>
</phpunit>
42 changes: 42 additions & 0 deletions tests/Model/ModelsTest.php
@@ -0,0 +1,42 @@
<?php

namespace Tpay\Tests\Model;

use PHPUnit\Framework\TestCase;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;

class ModelsTest extends TestCase
{
/**
* @coversNothing
*
* @dataProvider dataModel
*/
public function testModel($class)
{
self::assertTrue(class_exists($class) || interface_exists($class));
}

public static function dataModel()
{
$modelDirectory = realpath(__DIR__.'/../../Model');

/** @var SplFileInfo $fileInfo */
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($modelDirectory)) as $fileInfo) {
if (!$fileInfo->isFile()) {
continue;
}

$className = 'tpaySDK\\Model\\'.substr(
$fileInfo->getRealPath(),
strlen($modelDirectory) + 1,
-4
);
$className = str_replace('/', '\\', $className);

yield $className => [$className];
}
}
}

0 comments on commit 8d2e671

Please sign in to comment.