Skip to content

Commit f943b81

Browse files
committed
test: Fix namespaces;
add Arch tests; update PHPUnit to v10
1 parent 9420847 commit f943b81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+626
-600
lines changed

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
},
3737
"require-dev": {
3838
"phpstan/phpstan": "1.12.28",
39-
"phpunit/phpunit": "^9.6",
39+
"phpunit/phpunit": "^10.5",
4040
"rector/rector": "^1.2",
41-
"spiral/code-style": "^2.2"
41+
"spiral/code-style": "^2.2",
42+
"ta-tikoma/phpunit-architecture-test": "^0.8.5"
4243
},
4344
"autoload": {
4445
"psr-4": {
@@ -50,8 +51,7 @@
5051
},
5152
"autoload-dev": {
5253
"psr-4": {
53-
"React\\Promise\\": [
54-
"tests/fixtures/",
54+
"React\\Promise\\Tests\\": [
5555
"tests/"
5656
]
5757
}
@@ -66,6 +66,8 @@
6666
"cs:fix": "php-cs-fixer fix -v",
6767
"stan": "phpstan",
6868
"test": "phpunit --color=always --testdox",
69+
"test:arch": "phpunit --color=always --testdox --testsuite=Arch",
70+
"test:feat": "phpunit --color=always --testdox --testsuite=Feature",
6971
"test:unit": "phpunit --color=always --testdox --testsuite=Unit",
7072
"refactor": "rector process --config=rector.php",
7173
"test:cc": [

phpunit.xml.dist

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
bootstrap="vendor/autoload.php"
77
cacheResultFile="runtime/phpunit/result.cache"
88
colors="true"
9-
convertDeprecationsToExceptions="true">
9+
>
1010
<testsuites>
11+
<testsuite name="Arch">
12+
<directory>./tests/Arch</directory>
13+
</testsuite>
1114
<testsuite name="Feature">
1215
<directory suffix=".phpt">./tests/Feature</directory>
1316
</testsuite>
@@ -16,13 +19,23 @@
1619
</testsuite>
1720
</testsuites>
1821
<coverage>
22+
<report>
23+
<html outputDirectory="runtime/coverage"/>
24+
<text outputFile="runtime/coverage.txt"/>
25+
<clover outputFile="runtime/logs/clover.xml"/>
26+
</report>
27+
</coverage>
28+
<logging>
29+
<junit outputFile="runtime/report.junit.xml"/>
30+
</logging>
31+
<source>
1932
<include>
20-
<directory>./src/</directory>
33+
<directory>src</directory>
2134
</include>
2235
<exclude>
23-
<file>./src/functions_include.php</file>
36+
<directory>tests</directory>
2437
</exclude>
25-
</coverage>
38+
</source>
2639
<php>
2740
<ini name="error_reporting" value="-1" />
2841
<!-- Evaluate assertions, requires running with "php -d zend.assertions=1 vendor/bin/phpunit" -->

rector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
])
1212
// uncomment to reach your current PHP version
1313
// ->withPhpSets(php81: true)
14+
// ->withSets([
15+
// \Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
16+
// ])
1417
->withTypeCoverageLevel(0)
1518
->withDeadCodeLevel(0)
1619
->withCodeQualityLevel(0);

tests/Arch/ArchTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace React\Promise\Tests\Arch;
6+
7+
use PHPUnit\Architecture\ArchitectureAsserts;
8+
use PHPUnit\Framework\TestCase;
9+
10+
final class ArchTest extends TestCase
11+
{
12+
use ArchitectureAsserts;
13+
14+
protected array $excludedPaths = [
15+
'tests',
16+
'vendor',
17+
];
18+
19+
public function testForgottenDebugFunctions(): void
20+
{
21+
$functions = ['dd', 'exit', 'die', 'var_dump', 'echo', 'print', 'dump', 'tr', 'td', 'trap'];
22+
$layer = $this->layer();
23+
24+
foreach ($layer as $object) {
25+
foreach ($object->uses as $use) {
26+
foreach ($functions as $function) {
27+
$function === $use and throw new \Exception(
28+
\sprintf(
29+
'Function `%s()` is used in %s.',
30+
$function,
31+
$object->name,
32+
),
33+
);
34+
}
35+
}
36+
}
37+
38+
$this->assertTrue(true);
39+
}
40+
}

tests/Feature/FunctionRejectTestThenMismatchThrowsTypeErrorAndShouldReportUnhandledForTypeErrorOnlyOnPhp7.phpt

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/Feature/FunctionRejectTestThenMismatchThrowsTypeErrorAndShouldReportUnhandledForTypeErrorOnlyOnPhp8.phpt

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/Types/all.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use function PHPStan\Testing\assertType;
6+
use function React\Promise\all;
7+
use function React\Promise\resolve;
8+
9+
assertType('React\Promise\PromiseInterface<array<bool>>', all([resolve(true), resolve(false)]));
10+
assertType('React\Promise\PromiseInterface<array<bool>>', all([resolve(true), false]));
11+
assertType('React\Promise\PromiseInterface<array<bool|int>>', all([true, \time()]));
12+
assertType('React\Promise\PromiseInterface<array<bool|int>>', all([resolve(true), resolve(\time())]));

tests/Types/any.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use function PHPStan\Testing\assertType;
6+
use function React\Promise\any;
7+
use function React\Promise\resolve;
8+
9+
assertType('React\Promise\PromiseInterface<bool>', any([resolve(true), resolve(false)]));
10+
assertType('React\Promise\PromiseInterface<bool>', any([resolve(true), false]));
11+
assertType('React\Promise\PromiseInterface<bool|int>', any([true, \time()]));
12+
assertType('React\Promise\PromiseInterface<bool|int>', any([resolve(true), resolve(\time())]));

tests/Types/deferred.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use React\Promise\Deferred;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
$deferredA = new Deferred();
10+
assertType('React\Promise\PromiseInterface<mixed>', $deferredA->promise());
11+
12+
/** @var Deferred<int> $deferredB */
13+
$deferredB = new Deferred();
14+
$deferredB->resolve(42);
15+
assertType('React\Promise\PromiseInterface<int>', $deferredB->promise());
16+
17+
// $deferred = new Deferred();
18+
// $deferred->resolve(42);
19+
// assertType('React\Promise\Deferred<int>', $deferred);
20+
21+
// $deferred = new Deferred();
22+
// $deferred->resolve(true);
23+
// $deferred->resolve('ignored');
24+
// assertType('React\Promise\Deferred<bool>', $deferred);
25+
26+
// $deferred = new Deferred();
27+
// $deferred->reject(new \RuntimeException());
28+
// assertType('React\Promise\Deferred<never>', $deferred);
29+
30+
// invalid number of arguments passed to $canceller
31+
/** @phpstan-ignore-next-line */
32+
$deferred = new Deferred(static function ($a, $b, $c): void {});
33+
assertType('React\Promise\Deferred<mixed>', $deferred);
34+
35+
// invalid types for arguments of $canceller
36+
/** @phpstan-ignore-next-line */
37+
$deferred = new Deferred(static function (int $a, string $b): void {});
38+
assertType('React\Promise\Deferred<mixed>', $deferred);
39+
40+
// invalid number of arguments passed to $resolve
41+
$deferred = new Deferred(static function (callable $resolve): void {
42+
/** @phpstan-ignore-next-line */
43+
$resolve();
44+
});
45+
assertType('React\Promise\Deferred<mixed>', $deferred);
46+
47+
// invalid type passed to $reject
48+
$deferred = new Deferred(static function (callable $resolve, callable $reject): void {
49+
/** @phpstan-ignore-next-line */
50+
$reject(2);
51+
});
52+
assertType('React\Promise\Deferred<mixed>', $deferred);

tests/Types/promise.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use React\Promise\Promise;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
// $promise = new Promise(function (): void { });
10+
// assertType('React\Promise\PromiseInterface<never>', $promise);
11+
12+
// $promise = new Promise(function (callable $resolve): void {
13+
// $resolve(42);
14+
// });
15+
// assertType('React\Promise\PromiseInterface<int>', $promise);
16+
17+
// $promise = new Promise(function (callable $resolve): void {
18+
// $resolve(true);
19+
// $resolve('ignored');
20+
// });
21+
// assertType('React\Promise\PromiseInterface<bool>', $promise);
22+
23+
// $promise = new Promise(function (callable $resolve, callable $reject): void {
24+
// $reject(new \RuntimeException());
25+
// });
26+
// assertType('React\Promise\PromiseInterface<never>', $promise);
27+
28+
// $promise = new Promise(function (): never {
29+
// throw new \RuntimeException();
30+
// });
31+
// assertType('React\Promise\PromiseInterface<never>', $promise);
32+
33+
// invalid number of arguments for $resolver
34+
/** @phpstan-ignore-next-line */
35+
$promise = new Promise(static function ($a, $b, $c): void {});
36+
\assert($promise instanceof Promise);
37+
// assertType('React\Promise\PromiseInterface<never>', $promise);
38+
39+
// invalid types for arguments of $resolver
40+
/** @phpstan-ignore-next-line */
41+
$promise = new Promise(static function (int $a, string $b): void {});
42+
// assertType('React\Promise\PromiseInterface<never>', $promise);
43+
44+
// invalid number of arguments passed to $resolve
45+
$promise = new Promise(static function (callable $resolve): void {
46+
/** @phpstan-ignore-next-line */
47+
$resolve();
48+
});
49+
// assertType('React\Promise\PromiseInterface<never>', $promise);
50+
51+
// invalid number of arguments passed to $reject
52+
$promise = new Promise(static function (callable $resolve, callable $reject): void {
53+
/** @phpstan-ignore-next-line */
54+
$reject();
55+
});
56+
// assertType('React\Promise\PromiseInterface<never>', $promise);
57+
58+
// invalid type passed to $reject
59+
$promise = new Promise(static function (callable $resolve, callable $reject): void {
60+
/** @phpstan-ignore-next-line */
61+
$reject(2);
62+
});
63+
// assertType('React\Promise\PromiseInterface<never>', $promise);
64+
65+
// invalid number of arguments for $canceller
66+
/** @phpstan-ignore-next-line */
67+
$promise = new Promise(static function (): void {}, static function ($a, $b, $c): void {});
68+
// assertType('React\Promise\PromiseInterface<never>', $promise);
69+
70+
// invalid types for arguments of $canceller
71+
/** @phpstan-ignore-next-line */
72+
$promise = new Promise(static function (): void {}, static function (int $a, string $b): void {});
73+
// assertType('React\Promise\PromiseInterface<never>', $promise);
74+
75+
// invalid number of arguments passed to $resolve
76+
$promise = new Promise(static function (): void {}, static function (callable $resolve): void {
77+
/** @phpstan-ignore-next-line */
78+
$resolve();
79+
});
80+
// assertType('React\Promise\PromiseInterface<never>', $promise);
81+
82+
// invalid number of arguments passed to $reject
83+
$promise = new Promise(static function (): void {}, static function (callable $resolve, callable $reject): void {
84+
/** @phpstan-ignore-next-line */
85+
$reject();
86+
});
87+
// assertType('React\Promise\PromiseInterface<never>', $promise);
88+
89+
// invalid type passed to $reject
90+
$promise = new Promise(static function (): void {}, static function (callable $resolve, callable $reject): void {
91+
/** @phpstan-ignore-next-line */
92+
$reject(2);
93+
});
94+
// assertType('React\Promise\PromiseInterface<never>', $promise);

0 commit comments

Comments
 (0)