diff --git a/.php_cs b/.php_cs index 181fd22..2c37782 100644 --- a/.php_cs +++ b/.php_cs @@ -1,6 +1,6 @@ =5.3.3" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.1", + "friendsofphp/php-cs-fixer": "~2.2.20", "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": "^4.8.35" }, @@ -1076,7 +1076,7 @@ "json", "schema" ], - "time": "2018-02-14T22:26:30+00:00" + "time": "2019-01-14T23:55:14+00:00" }, { "name": "localheinz/composer-json-normalizer", @@ -2568,16 +2568,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.11", + "version": "0.11.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "cfb0b43021fb75abe853ab8d88d22cdb37596697" + "reference": "a138b8a2731b2c19f1dffa2f1411984a638fe977" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/cfb0b43021fb75abe853ab8d88d22cdb37596697", - "reference": "cfb0b43021fb75abe853ab8d88d22cdb37596697", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a138b8a2731b2c19f1dffa2f1411984a638fe977", + "reference": "a138b8a2731b2c19f1dffa2f1411984a638fe977", "shasum": "" }, "require": { @@ -2637,7 +2637,7 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "time": "2019-01-15T14:21:47+00:00" + "time": "2019-01-19T20:23:08+00:00" }, { "name": "phpunit/php-code-coverage", @@ -4750,6 +4750,134 @@ "validate" ], "time": "2018-12-25T11:19:39+00:00" + }, + { + "name": "wyrihaximus/async-test-utilities", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/WyriHaximus/php-async-test-utilities.git", + "reference": "c8ac9644151ef72cca87a993288db5b4a413c8bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WyriHaximus/php-async-test-utilities/zipball/c8ac9644151ef72cca87a993288db5b4a413c8bf", + "reference": "c8ac9644151ef72cca87a993288db5b4a413c8bf", + "shasum": "" + }, + "require": { + "clue/block-react": "^1.3", + "php": "^7.2", + "wyrihaximus/cs-fixer-config": "^1.0.1", + "wyrihaximus/test-utilities": "^1.0.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "WyriHaximus\\AsyncTestUtilities\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Cees-Jan Kiewiet", + "email": "ceesjank@gmail.com" + } + ], + "description": "Test utilities for api-clients packages", + "time": "2019-01-20T18:10:41+00:00" + }, + { + "name": "wyrihaximus/cs-fixer-config", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/WyriHaximus/php-cs-fixer-config.git", + "reference": "a36a4f35c8b499252518ec6094a1de5f010fc999" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WyriHaximus/php-cs-fixer-config/zipball/a36a4f35c8b499252518ec6094a1de5f010fc999", + "reference": "a36a4f35c8b499252518ec6094a1de5f010fc999", + "shasum": "" + }, + "require": { + "friendsofphp/php-cs-fixer": "^2.14", + "php": "^7.2" + }, + "require-dev": { + "wyrihaximus/test-utilities": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "WyriHaximus\\CsFixerConfig\\": "src/" + }, + "files": [ + "src/rules_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Cees-Jan Kiewiet", + "email": "ceesjank@gmail.com" + } + ], + "description": "friendsofphp/php-cs-fixer config", + "time": "2019-01-20T17:38:15+00:00" + }, + { + "name": "wyrihaximus/test-utilities", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/WyriHaximus/php-test-utilities.git", + "reference": "d292de1799f96de76c794a516ab13b19057d2e9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WyriHaximus/php-test-utilities/zipball/d292de1799f96de76c794a516ab13b19057d2e9a", + "reference": "d292de1799f96de76c794a516ab13b19057d2e9a", + "shasum": "" + }, + "require": { + "composer/composer": "^1.8", + "friendsofphp/php-cs-fixer": "^2.14", + "infection/infection": "^0.11.4", + "jakub-onderka/php-console-highlighter": "^0.4", + "jakub-onderka/php-parallel-lint": "^1.0.0", + "localheinz/composer-normalize": "^1.0.0", + "nunomaduro/collision": "^2.1", + "php": "^7.2", + "phpstan/phpstan": "^0.10.7 || ^0.11.0", + "phpunit/phpunit": "^7.5", + "wyrihaximus/cs-fixer-config": "^1.0.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "WyriHaximus\\TestUtilities\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Cees-Jan Kiewiet", + "email": "ceesjank@gmail.com" + } + ], + "description": "Test utilities for api-clients packages", + "time": "2019-01-20T17:45:21+00:00" } ], "packages-dev": [], diff --git a/src/TestCase.php b/src/TestCase.php index 91721e7..0b667b4 100644 --- a/src/TestCase.php +++ b/src/TestCase.php @@ -2,193 +2,8 @@ namespace ApiClients\Tools\TestUtilities; -use function Clue\React\Block\await; -use function Clue\React\Block\awaitAll; -use function Clue\React\Block\awaitAny; -use FilesystemIterator; -use PHPUnit\Framework\TestCase as PHPUnitTestCase; -use React\EventLoop\Factory; -use React\EventLoop\LoopInterface; -use React\Promise\PromiseInterface; -use RecursiveDirectoryIterator; -use RecursiveIteratorIterator; +use WyriHaximus\AsyncTestUtilities\AsyncTestCase; -abstract class TestCase extends PHPUnitTestCase +abstract class TestCase extends AsyncTestCase { - const DEFAULT_AWAIT_TIMEOUT = 60; - - /** - * @var string - */ - private $baseTmpDir; - - /** - * @var string - */ - private $tmpDir; - - /** - * @var string - */ - private $tmpNamespace; - - protected function setUp(): void - { - parent::setUp(); - - $this->baseTmpDir = $this->getSysTempDir() . - \DIRECTORY_SEPARATOR . - 'p-a-c-t-' . - \uniqid() . - \DIRECTORY_SEPARATOR; - $this->tmpDir = $this->baseTmpDir . - \uniqid() . - \DIRECTORY_SEPARATOR; - ; - - $this->tmpNamespace = \uniqid('PACTN'); - } - - protected function tearDown(): void - { - parent::tearDown(); - - if (\file_exists($this->baseTmpDir)) { - $this->rmdir($this->baseTmpDir); - } - } - - /** - * @return array - */ - public function provideTrueFalse(): array - { - return [ - [ - true, - ], - [ - false, - ], - ]; - } - - /** - * @return string - */ - protected function getSysTempDir(): string - { - if (\strtoupper(\substr(\PHP_OS, 0, 3)) === 'WIN') { - return 'C:\\t\\'; - } - - return \sys_get_temp_dir(); - } - - /** - * @param string $dir - */ - protected function rmdir(string $dir): void - { - $directory = new FilesystemIterator($dir); - - /** @var \SplFileInfo $node */ - foreach ($directory as $node) { - if (\is_dir($node->getPathname())) { - $this->rmdir($node->getPathname()); - continue; - } - - if (\is_file($node->getPathname())) { - \unlink($node->getPathname()); - continue; - } - } - - \rmdir($dir); - } - - /** - * @return string - */ - protected function getTmpDir(): string - { - if (!\file_exists($this->tmpDir)) { - \mkdir($this->tmpDir, 0777, true); - } - - return $this->tmpDir; - } - - /** - * @return string - */ - protected function getRandomNameSpace(): string - { - return $this->tmpNamespace; - } - - /** - * @param string $path - * @return array - */ - protected function getFilesInDirectory(string $path): array - { - $files = []; - - $directory = new RecursiveDirectoryIterator($path); - $directory = new RecursiveIteratorIterator($directory); - - foreach ($directory as $node) { - if (!\is_file($node->getPathname())) { - continue; - } - - $files[] = $node->getPathname(); - } - - return $files; - } - - /** - * @param PromiseInterface $promise - * @param LoopInterface|null $loop - * @return mixed - */ - protected function await(PromiseInterface $promise, LoopInterface $loop = null, float $timeout = self::DEFAULT_AWAIT_TIMEOUT) - { - if (!($loop instanceof LoopInterface)) { - $loop = Factory::create(); - } - - return await($promise, $loop, $timeout); - } - - /** - * @param array $promises - * @param LoopInterface|null $loop - * @return array - */ - protected function awaitAll(array $promises, LoopInterface $loop = null, float $timeout = self::DEFAULT_AWAIT_TIMEOUT) - { - if (!($loop instanceof LoopInterface)) { - $loop = Factory::create(); - } - - return awaitAll($promises, $loop, $timeout); - } - - /** - * @param array $promises - * @param LoopInterface|null $loop - * @return mixed - */ - protected function awaitAny(array $promises, LoopInterface $loop = null, float $timeout = self::DEFAULT_AWAIT_TIMEOUT) - { - if (!($loop instanceof LoopInterface)) { - $loop = Factory::create(); - } - - return awaitAny($promises, $loop, $timeout); - } }