Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
michielkempen committed Aug 21, 2020
1 parent bb3195d commit 49394c8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Output/SerializableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Async\Output;

use ArgumentCountError;
use Throwable;

class SerializableException
Expand All @@ -27,7 +28,7 @@ public function asThrowable(): Throwable
try {
/** @var Throwable $throwable */
$throwable = new $this->class($this->message."\n\n".$this->trace);
} catch (Throwable $exception) {
} catch (ArgumentCountError $exception) {
$throwable = new \Exception($this->message."\n\n".$this->trace);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/ErrorHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ public function it_can_handle_exceptions_via_catch_callback()
$this->assertCount(5, $pool->getFailed(), (string) $pool->status());
}

/** @test */
public function it_can_handle_complex_exceptions_via_catch_callback()
{
$pool = Pool::create();

foreach (range(1, 5) as $i) {
$pool->add(function () {
throw new MyComplexException('test', (object) ['error' => 'wrong query']);
})->catch(function (MyComplexException $e) {
$this->assertRegExp('/test/', $e->getMessage());
});
}

$pool->wait();

$this->assertCount(5, $pool->getFailed(), (string) $pool->status());
}

/** @test */
public function it_can_handle_typed_exceptions_via_catch_callback()
{
Expand Down
17 changes: 17 additions & 0 deletions tests/MyComplexException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Spatie\Async\Tests;

use Exception;
use stdClass;

class MyComplexException extends Exception
{
public $payload;

public function __construct(string $message, stdClass $payload)
{
parent::__construct($message);
$this->payload = $payload;
}
}

0 comments on commit 49394c8

Please sign in to comment.