Skip to content

Commit e718685

Browse files
authored
Better exceptions (#222)
1 parent 4fbccd9 commit e718685

14 files changed

Lines changed: 138 additions & 19 deletions

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
run: vendor/bin/ecs check
5858

5959
- name: Run static analysis via PHPStan
60-
run: vendor/bin/phpstan --xdebug analyse src tests
60+
run: vendor/bin/phpstan analyse src tests
6161

6262
- name: Create databases
6363
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ composer.lock
33
vendor
44
coverage
55
.env
6+
.phpunit.cache
67
.phpunit.result.cache
78
.php_cs.cache
89
.php-cs-fixer.cache

src/Traits/Timers.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Workflow\Traits;
66

77
use Carbon\CarbonInterval;
8-
use Illuminate\Database\QueryException;
98
use React\Promise\Deferred;
109
use React\Promise\PromiseInterface;
1110
use function React\Promise\resolve;
@@ -64,7 +63,7 @@ public static function timer($seconds): PromiseInterface
6463
'class' => Signal::class,
6564
'result' => Serializer::serialize(true),
6665
]);
67-
} catch (QueryException $exception) {
66+
} catch (\Illuminate\Database\UniqueConstraintViolationException $exception) {
6867
// already logged
6968
}
7069
}

src/WorkflowStub.php

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

55
namespace Workflow;
66

7-
use Illuminate\Database\QueryException;
87
use Illuminate\Support\Arr;
98
use Illuminate\Support\Carbon;
109
use Illuminate\Support\Traits\Macroable;
@@ -220,15 +219,11 @@ public function startAsChild(StoredWorkflow $parentWorkflow, int $index, $now, .
220219

221220
public function fail($exception): void
222221
{
223-
try {
224-
$this->storedWorkflow->exceptions()
225-
->create([
226-
'class' => $this->storedWorkflow->class,
227-
'exception' => Serializer::serialize($exception),
228-
]);
229-
} catch (QueryException) {
230-
// already logged
231-
}
222+
$this->storedWorkflow->exceptions()
223+
->create([
224+
'class' => $this->storedWorkflow->class,
225+
'exception' => Serializer::serialize($exception),
226+
]);
232227

233228
$this->storedWorkflow->status->transitionTo(WorkflowFailedStatus::class);
234229

@@ -267,7 +262,7 @@ public function next($index, $now, $class, $result): void
267262
'class' => $class,
268263
'result' => Serializer::serialize($result),
269264
]);
270-
} catch (QueryException) {
265+
} catch (\Illuminate\Database\UniqueConstraintViolationException $exception) {
271266
// already logged
272267
}
273268

tests/TestCase.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ public static function setUpBeforeClass(): void
2525
}
2626

2727
for ($i = 0; $i < self::NUMBER_OF_WORKERS; $i++) {
28-
self::$workers[$i] = new Process([
29-
'php',
30-
__DIR__ . '/../vendor/orchestra/testbench-core/laravel/artisan',
31-
'queue:work',
32-
]);
28+
self::$workers[$i] = new Process(['php', __DIR__ . '/../vendor/bin/testbench', 'queue:work']);
3329
self::$workers[$i]->start();
3430
}
3531
}

tests/Unit/Listeners/MonitorActivityCompletedTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ final class MonitorActivityCompletedTest extends TestCase
1515
{
1616
public function testHandle(): void
1717
{
18+
$this->app->make('cache')
19+
->store()
20+
->clear();
21+
1822
config([
1923
'workflows.monitor_url' => 'http://test',
2024
]);

tests/Unit/Listeners/MonitorActivityFailedTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ final class MonitorActivityFailedTest extends TestCase
1515
{
1616
public function testHandle(): void
1717
{
18+
$this->app->make('cache')
19+
->store()
20+
->clear();
21+
1822
config([
1923
'workflows.monitor_url' => 'http://test',
2024
]);

tests/Unit/Listeners/MonitorActivityStartedTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ final class MonitorActivityStartedTest extends TestCase
1515
{
1616
public function testHandle(): void
1717
{
18+
$this->app->make('cache')
19+
->store()
20+
->clear();
21+
1822
config([
1923
'workflows.monitor_url' => 'http://test',
2024
]);

tests/Unit/Listeners/MonitorWorkflowCompletedTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ final class MonitorWorkflowCompletedTest extends TestCase
1414
{
1515
public function testHandle(): void
1616
{
17+
$this->app->make('cache')
18+
->store()
19+
->clear();
20+
1721
config([
1822
'workflows.monitor_url' => 'http://test',
1923
]);

tests/Unit/Listeners/MonitorWorkflowFailedTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ final class MonitorWorkflowFailedTest extends TestCase
1414
{
1515
public function testHandle(): void
1616
{
17+
$this->app->make('cache')
18+
->store()
19+
->clear();
20+
1721
config([
1822
'workflows.monitor_url' => 'http://test',
1923
]);

0 commit comments

Comments
 (0)