Skip to content

Commit 5793372

Browse files
committed
Build up on wyrihaximus/async-test-utilities
1 parent 7d18040 commit 5793372

File tree

4 files changed

+96
-191
lines changed

4 files changed

+96
-191
lines changed

.php_cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
use ApiClients\Tools\TestUtilities\PhpCsFixerConfig;
3+
use ApiClients\Tools\CsFixerConfig\PhpCsFixerConfig;
44

55
return (function ()
66
{

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"localheinz/composer-normalize": "^1.0.0",
2121
"nunomaduro/collision": "^2.1",
2222
"phpstan/phpstan": "^0.10.7",
23-
"phpunit/phpunit": "^7.5"
23+
"phpunit/phpunit": "^7.5",
24+
"wyrihaximus/async-test-utilities": "dev-master",
25+
"wyrihaximus/test-utilities": "dev-master"
2426
},
2527
"require-dev": {},
2628
"config": {

composer.lock

Lines changed: 90 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TestCase.php

Lines changed: 2 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -2,193 +2,8 @@
22

33
namespace ApiClients\Tools\TestUtilities;
44

5-
use function Clue\React\Block\await;
6-
use function Clue\React\Block\awaitAll;
7-
use function Clue\React\Block\awaitAny;
8-
use FilesystemIterator;
9-
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
10-
use React\EventLoop\Factory;
11-
use React\EventLoop\LoopInterface;
12-
use React\Promise\PromiseInterface;
13-
use RecursiveDirectoryIterator;
14-
use RecursiveIteratorIterator;
5+
use WyriHaximus\AsyncTestUtilities\AsyncTestCase;
156

16-
abstract class TestCase extends PHPUnitTestCase
7+
abstract class TestCase extends AsyncTestCase
178
{
18-
const DEFAULT_AWAIT_TIMEOUT = 60;
19-
20-
/**
21-
* @var string
22-
*/
23-
private $baseTmpDir;
24-
25-
/**
26-
* @var string
27-
*/
28-
private $tmpDir;
29-
30-
/**
31-
* @var string
32-
*/
33-
private $tmpNamespace;
34-
35-
protected function setUp(): void
36-
{
37-
parent::setUp();
38-
39-
$this->baseTmpDir = $this->getSysTempDir() .
40-
\DIRECTORY_SEPARATOR .
41-
'p-a-c-t-' .
42-
\uniqid() .
43-
\DIRECTORY_SEPARATOR;
44-
$this->tmpDir = $this->baseTmpDir .
45-
\uniqid() .
46-
\DIRECTORY_SEPARATOR;
47-
;
48-
49-
$this->tmpNamespace = \uniqid('PACTN');
50-
}
51-
52-
protected function tearDown(): void
53-
{
54-
parent::tearDown();
55-
56-
if (\file_exists($this->baseTmpDir)) {
57-
$this->rmdir($this->baseTmpDir);
58-
}
59-
}
60-
61-
/**
62-
* @return array
63-
*/
64-
public function provideTrueFalse(): array
65-
{
66-
return [
67-
[
68-
true,
69-
],
70-
[
71-
false,
72-
],
73-
];
74-
}
75-
76-
/**
77-
* @return string
78-
*/
79-
protected function getSysTempDir(): string
80-
{
81-
if (\strtoupper(\substr(\PHP_OS, 0, 3)) === 'WIN') {
82-
return 'C:\\t\\';
83-
}
84-
85-
return \sys_get_temp_dir();
86-
}
87-
88-
/**
89-
* @param string $dir
90-
*/
91-
protected function rmdir(string $dir): void
92-
{
93-
$directory = new FilesystemIterator($dir);
94-
95-
/** @var \SplFileInfo $node */
96-
foreach ($directory as $node) {
97-
if (\is_dir($node->getPathname())) {
98-
$this->rmdir($node->getPathname());
99-
continue;
100-
}
101-
102-
if (\is_file($node->getPathname())) {
103-
\unlink($node->getPathname());
104-
continue;
105-
}
106-
}
107-
108-
\rmdir($dir);
109-
}
110-
111-
/**
112-
* @return string
113-
*/
114-
protected function getTmpDir(): string
115-
{
116-
if (!\file_exists($this->tmpDir)) {
117-
\mkdir($this->tmpDir, 0777, true);
118-
}
119-
120-
return $this->tmpDir;
121-
}
122-
123-
/**
124-
* @return string
125-
*/
126-
protected function getRandomNameSpace(): string
127-
{
128-
return $this->tmpNamespace;
129-
}
130-
131-
/**
132-
* @param string $path
133-
* @return array
134-
*/
135-
protected function getFilesInDirectory(string $path): array
136-
{
137-
$files = [];
138-
139-
$directory = new RecursiveDirectoryIterator($path);
140-
$directory = new RecursiveIteratorIterator($directory);
141-
142-
foreach ($directory as $node) {
143-
if (!\is_file($node->getPathname())) {
144-
continue;
145-
}
146-
147-
$files[] = $node->getPathname();
148-
}
149-
150-
return $files;
151-
}
152-
153-
/**
154-
* @param PromiseInterface $promise
155-
* @param LoopInterface|null $loop
156-
* @return mixed
157-
*/
158-
protected function await(PromiseInterface $promise, LoopInterface $loop = null, float $timeout = self::DEFAULT_AWAIT_TIMEOUT)
159-
{
160-
if (!($loop instanceof LoopInterface)) {
161-
$loop = Factory::create();
162-
}
163-
164-
return await($promise, $loop, $timeout);
165-
}
166-
167-
/**
168-
* @param array $promises
169-
* @param LoopInterface|null $loop
170-
* @return array
171-
*/
172-
protected function awaitAll(array $promises, LoopInterface $loop = null, float $timeout = self::DEFAULT_AWAIT_TIMEOUT)
173-
{
174-
if (!($loop instanceof LoopInterface)) {
175-
$loop = Factory::create();
176-
}
177-
178-
return awaitAll($promises, $loop, $timeout);
179-
}
180-
181-
/**
182-
* @param array $promises
183-
* @param LoopInterface|null $loop
184-
* @return mixed
185-
*/
186-
protected function awaitAny(array $promises, LoopInterface $loop = null, float $timeout = self::DEFAULT_AWAIT_TIMEOUT)
187-
{
188-
if (!($loop instanceof LoopInterface)) {
189-
$loop = Factory::create();
190-
}
191-
192-
return awaitAny($promises, $loop, $timeout);
193-
}
1949
}

0 commit comments

Comments
 (0)