Skip to content

Commit a04c981

Browse files
committed
Update tests and stat analyze
1 parent b9ab40b commit a04c981

File tree

9 files changed

+96
-42
lines changed

9 files changed

+96
-42
lines changed

.php-cs-fixer.dist.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+
require_once 'vendor/autoload.php';
6+
7+
return \Spiral\CodeStyle\Builder::create()
8+
->include(__DIR__ . '/src')
9+
->include(__DIR__ . '/tests')
10+
->include(__FILE__)
11+
->allowRisky(true)
12+
->build();

composer.json

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
{
99
"name": "Aleksei Gagarin (roxblnfk)",
1010
"homepage": "https://github.com/roxblnfk"
11-
},
12-
{
13-
"name": "Pavel Buchnev (butschster)",
14-
"homepage": "https://github.com/butschster"
1511
}
1612
],
1713
"autoload": {
@@ -28,10 +24,6 @@
2824
{
2925
"type": "patreon",
3026
"url": "https://patreon.com/roxblnfk"
31-
},
32-
{
33-
"type": "patreon",
34-
"url": "https://patreon.com/butschster"
3527
}
3628
],
3729
"minimum-stability": "dev",
@@ -47,13 +39,31 @@
4739
"buggregator/trap": "^1.4",
4840
"dereuromark/composer-prefer-lowest": "^0.1.10",
4941
"phpunit/phpunit": "^10.5",
50-
"vimeo/psalm": "^5.23",
51-
"pestphp/pest": "^2.34",
52-
"pestphp/pest-plugin-arch": "^2.7"
42+
"spiral/code-style": "^2.3.0",
43+
"ta-tikoma/phpunit-architecture-test": "^0.8.4",
44+
"vimeo/psalm": "^6.13"
5345
},
5446
"config": {
5547
"allow-plugins": {
5648
"pestphp/pest-plugin": false
5749
}
50+
},
51+
"scripts": {
52+
"cs:diff": "php-cs-fixer fix --dry-run -v --diff",
53+
"cs:fix": "php-cs-fixer fix -v",
54+
"psalm": "psalm",
55+
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
56+
"psalm:ci": "psalm --output-format=github --shepherd --show-info=false --stats --threads=4",
57+
"test": [
58+
"phpunit --color=always --no-coverage"
59+
],
60+
"test:unit": [
61+
"@putenv XDEBUG_MODE=coverage",
62+
"phpunit --color=always --testsuite=Unit"
63+
],
64+
"test:arch": [
65+
"@putenv XDEBUG_MODE=coverage",
66+
"phpunit --color=always --testsuite=Arch"
67+
]
5868
}
5969
}

phpunit.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
44
backupGlobals="false"
55
colors="true"
6+
cacheResultFile="runtime/phpunit/result.cache"
67
processIsolation="false"
78
executionOrder="random"
89
failOnRisky="true"
910
failOnWarning="true"
1011
stopOnFailure="false"
1112
stopOnError="false"
1213
stderr="true"
13-
cacheDirectory=".phpunit.cache"
1414
resolveDependencies="true"
15+
displayDetailsOnTestsThatTriggerDeprecations="true"
1516
>
1617
<testsuites>
1718
<testsuite name="Unit">

src/Factory/ActivityStub.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Temporal\Support\Factory;
66

7-
use DateInterval;
87
use Temporal\Activity\ActivityOptions;
98
use Temporal\Internal\Workflow\ActivityProxy;
109
use Temporal\Support\Attribute\RetryPolicy;
@@ -15,7 +14,6 @@
1514
use Temporal\Support\Internal\RetryOptions;
1615
use Temporal\Workflow;
1716
use Temporal\Workflow\ActivityStubInterface;
18-
use Throwable;
1917

2018
final class ActivityStub
2119
{
@@ -29,29 +27,28 @@ final class ActivityStub
2927
* @param int<0, max>|null $retryAttempts Maximum number of attempts. When exceeded the retries stop even
3028
* if not expired yet. If not set or set to 0, it means unlimited, and rely on activity
3129
* {@see ActivityOptions::$scheduleToCloseTimeout} to stop.
32-
* @param DateInterval|string|int|null $retryInitInterval Backoff interval for the first retry.
30+
* @param \DateInterval|string|int|null $retryInitInterval Backoff interval for the first retry.
3331
* If $retryBackoff is 1.0 then it is used for all retries.
3432
* Int value in seconds.
35-
* @param DateInterval|string|int|null $retryMaxInterval Maximum backoff interval between retries.
33+
* @param \DateInterval|string|int|null $retryMaxInterval Maximum backoff interval between retries.
3634
* Exponential backoff leads to interval increase. This value is the cap of the interval.
3735
* Int value in seconds.
3836
* Default is 100x of $retryInitInterval.
3937
* @param float|null $retryBackoff Coefficient used to calculate the next retry backoff interval.
4038
* The next retry interval is previous interval multiplied by this coefficient.
4139
* Note: Must be greater than 1.0
42-
* @param list<class-string<Throwable>> $nonRetryables Non-retriable errors. Temporal server will stop retry
40+
* @param list<class-string<\Throwable>> $nonRetryables Non-retriable errors. Temporal server will stop retry
4341
* if error type matches this list.
44-
* @param DateInterval|string|int $scheduleToStartTimeout Time activity can stay in task queue before it
42+
* @param \DateInterval|string|int $scheduleToStartTimeout Time activity can stay in task queue before it
4543
* is picked up by a worker. If $scheduleToCloseTimeout is not provided then
4644
* both this and $startToCloseTimeout are required.
47-
* @param DateInterval|string|int $startToCloseTimeout Maximum activity execution time after it was sent
45+
* @param \DateInterval|string|int $startToCloseTimeout Maximum activity execution time after it was sent
4846
* to a worker. If $scheduleToCloseTimeout is not provided then both this
4947
* and $scheduleToStartTimeout are required.
50-
* @param DateInterval|string|int $scheduleToCloseTimeout Overall timeout workflow is willing to wait for
48+
* @param \DateInterval|string|int $scheduleToCloseTimeout Overall timeout workflow is willing to wait for
5149
* activity to complete. It includes time in a task queue ($scheduleToStartTimeout) plus activity
5250
* execution time ($startToCloseTimeout).
5351
* Either this option or both $scheduleToStartTimeout and $startToCloseTimeout are required.
54-
* @param DateInterval|string|int $heartbeatTimeout
5552
* @param \Stringable|non-empty-string|null $activityId Business level activity ID, this is not needed
5653
* for most of the cases. If you have to specify this, then talk to the temporal team.
5754
* This is something will be done in the future.
@@ -99,7 +96,7 @@ public static function activity(
9996
$scheduleToCloseTimeout === 0 or $options = $options->withScheduleToCloseTimeout($scheduleToCloseTimeout);
10097
$heartbeatTimeout === 0 or $options = $options->withHeartbeatTimeout($heartbeatTimeout);
10198
// Activity ID
102-
$activityId === null or $options = $options->withActivityId((string)$activityId);
99+
$activityId === null or $options = $options->withActivityId((string) $activityId);
103100
$cancellationType === 0 or $options = $options->withCancellationType($cancellationType);
104101

105102
return $class === null

tests/Arch/ArchTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Temporal\Support\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+
'resources',
16+
'tests',
17+
'vendor',
18+
];
19+
20+
public function testForgottenDebugFunctions(): void
21+
{
22+
$functions = ['dd', 'exit', 'die', 'var_dump', 'echo', 'print', 'trap', 'dump', 'tr', 'td', 'error_log'];
23+
24+
$layer = $this->layer();
25+
26+
foreach ($layer as $object) {
27+
foreach ($object->uses as $use) {
28+
foreach ($functions as $function) {
29+
$function === $use and throw new \Exception(
30+
\sprintf(
31+
'Function `%s()` is used in %s.',
32+
$function,
33+
$object->name,
34+
),
35+
);
36+
}
37+
}
38+
}
39+
40+
$this->assertTrue(true);
41+
}
42+
}

tests/Arch/DebugTest.php

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

tests/Unit/Factory/ActivityStubTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class: AttributedWithoutInterface::class,
3939
$this->assertSame(3, $options->retryOptions->maximumAttempts);
4040
$this->assertSame(10.0, $options->retryOptions->backoffCoefficient);
4141
$this->assertSame([RuntimeException::class], $options->retryOptions->nonRetryableExceptions);
42-
$this->assertSame('5.0', $options->retryOptions->initialInterval->format('%s.%f'));
43-
$this->assertSame('500.0', $options->retryOptions->maximumInterval->format('%s.%f'));
42+
$this->assertSame('0.5.0', $options->retryOptions->initialInterval->format('%i.%s.%f'));
43+
$this->assertSame('8.20.0', $options->retryOptions->maximumInterval->format('%i.%s.%f'));
4444
}
4545

4646
public function testAttributeOverrides(): void
@@ -63,8 +63,8 @@ class: AttributedWithoutInterface::class,
6363
[LogicException::class, RuntimeException::class],
6464
$options->retryOptions->nonRetryableExceptions,
6565
);
66-
$this->assertSame('10.0', $options->retryOptions->initialInterval->format('%s.%f'));
67-
$this->assertSame('200.0', $options->retryOptions->maximumInterval->format('%s.%f'));
66+
$this->assertSame('0.10.0', $options->retryOptions->initialInterval->format('%i.%s.%f'));
67+
$this->assertSame('3.20.0', $options->retryOptions->maximumInterval->format('%i.%s.%f'));
6868
}
6969

7070
public function testUntypedActivity(): void

tests/Unit/Factory/ChildWorkflowStubTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function testDefaultsFromAttributes(): void
4040
$this->assertSame(3, $options->retryOptions->maximumAttempts);
4141
$this->assertSame(10.0, $options->retryOptions->backoffCoefficient);
4242
$this->assertSame([RuntimeException::class], $options->retryOptions->nonRetryableExceptions);
43-
$this->assertSame('5.0', $options->retryOptions->initialInterval->format('%s.%f'));
44-
$this->assertSame('500.0', $options->retryOptions->maximumInterval->format('%s.%f'));
43+
$this->assertSame('0.5.0', $options->retryOptions->initialInterval->format('%i.%s.%f'));
44+
$this->assertSame('8.20.0', $options->retryOptions->maximumInterval->format('%i.%s.%f'));
4545
}
4646

4747
public function testAttributeOverrides(): void
@@ -64,8 +64,8 @@ public function testAttributeOverrides(): void
6464
[LogicException::class, RuntimeException::class],
6565
$options->retryOptions->nonRetryableExceptions,
6666
);
67-
$this->assertSame('10.0', $options->retryOptions->initialInterval->format('%s.%f'));
68-
$this->assertSame('200.0', $options->retryOptions->maximumInterval->format('%s.%f'));
67+
$this->assertSame('0.10.0', $options->retryOptions->initialInterval->format('%i.%s.%f'));
68+
$this->assertSame('3.20.0', $options->retryOptions->maximumInterval->format('%i.%s.%f'));
6969
}
7070

7171
public function testUntypedChildCreated(): void

tests/Unit/Factory/WorkflowStubTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function testDefaultsFromAttributes(): void
4242
[RuntimeException::class],
4343
$input->options->retryOptions->nonRetryableExceptions,
4444
);
45-
self::assertSame('5.0', $input->options->retryOptions->initialInterval->format('%s.%f'));
46-
self::assertSame('500.0', $input->options->retryOptions->maximumInterval->format('%s.%f'));
45+
self::assertSame('0.5.0', $input->options->retryOptions->initialInterval->format('%i.%s.%f'));
46+
self::assertSame('8.20.0', $input->options->retryOptions->maximumInterval->format('%i.%s.%f'));
4747
}
4848

4949
public function testAttributeOverrides(): void
@@ -79,8 +79,8 @@ public function testAttributeOverrides(): void
7979
[LogicException::class, RuntimeException::class],
8080
$input->options->retryOptions->nonRetryableExceptions,
8181
);
82-
self::assertSame('10.0', $input->options->retryOptions->initialInterval->format('%s.%f'));
83-
self::assertSame('200.0', $input->options->retryOptions->maximumInterval->format('%s.%f'));
82+
self::assertSame('0.10.0', $input->options->retryOptions->initialInterval->format('%i.%s.%f'));
83+
self::assertSame('3.20.0', $input->options->retryOptions->maximumInterval->format('%i.%s.%f'));
8484
}
8585

8686
public function testUntypedWorkflowCreated(): void

0 commit comments

Comments
 (0)