Skip to content

Commit 17bc1ab

Browse files
authored
Prevent error when listing exceptions (#26)
1 parent 3eb81db commit 17bc1ab

File tree

4 files changed

+89
-13
lines changed

4 files changed

+89
-13
lines changed

app/Http/Resources/StoredWorkflowExceptionResource.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33

44
namespace Waterline\Http\Resources;
55

6-
use Illuminate\Http\Request;
76
use Illuminate\Http\Resources\Json\JsonResource;
87
use SplFileObject;
9-
use Waterline\Transformer\WorkflowToChartDataTransformer;
10-
use Workflow\Models\StoredWorkflow;
118
use Workflow\Models\StoredWorkflowException;
129
use Workflow\Serializers\Y;
1310

@@ -18,9 +15,9 @@ class StoredWorkflowExceptionResource extends JsonResource
1815
{
1916
public static $wrap = null;
2017

21-
public function toArray(Request $request)
18+
public function toArray($request)
2219
{
23-
$code = null;
20+
$code = '';
2421
$exception = $this->exception;
2522

2623
$unserialized = Y::unserialize($exception);
@@ -32,11 +29,11 @@ public function toArray(Request $request)
3229
$file = new SplFileObject($unserialized['file']);
3330
$file->seek($unserialized['line'] - 4);
3431
for ($line = 0; $line < 7; ++$line) {
35-
$exception->code .= $file->current();
32+
$code .= $file->current();
3633
$file->next();
3734
if ($file->eof()) break;
3835
}
39-
$code = rtrim($exception->code);
36+
$code = rtrim($code);
4037
$exception = serialize($unserialized);
4138
}
4239

app/Http/Resources/StoredWorkflowLogResource.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
namespace Waterline\Http\Resources;
55

6-
use Illuminate\Http\Request;
76
use Illuminate\Http\Resources\Json\JsonResource;
8-
use Waterline\Transformer\WorkflowToChartDataTransformer;
9-
use Workflow\Models\StoredWorkflow;
107
use Workflow\Models\StoredWorkflowLog;
118
use Workflow\Serializers\Y;
129

@@ -17,7 +14,7 @@ class StoredWorkflowLogResource extends JsonResource
1714
{
1815
public static $wrap = null;
1916

20-
public function toArray(Request $request)
17+
public function toArray($request)
2118
{
2219
return [
2320
"id" => $this->id,

app/Http/Resources/StoredWorkflowResource.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace Waterline\Http\Resources;
55

6-
use Illuminate\Http\Request;
76
use Illuminate\Http\Resources\Json\JsonResource;
87
use Waterline\Transformer\WorkflowToChartDataTransformer;
98
use Workflow\Models\StoredWorkflow;
@@ -16,7 +15,7 @@ class StoredWorkflowResource extends JsonResource
1615
{
1716
public static $wrap = null;
1817

19-
public function toArray(Request $request)
18+
public function toArray($request)
2019
{
2120
return [
2221
"id" => $this->id,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace Waterline\Tests\Feature;
4+
5+
use Exception;
6+
use Illuminate\Testing\Fluent\AssertableJson;
7+
use Waterline\Tests\TestCase;
8+
use Workflow\Models\StoredWorkflow;
9+
use Workflow\Serializers\Y;
10+
11+
class DashboardWorkflowTest extends TestCase
12+
{
13+
public function testIndexNone()
14+
{
15+
$storedWorkflow = StoredWorkflow::create([
16+
'class' => 'WorkflowClass',
17+
'arguments' => 'N;',
18+
'output' => 'N;',
19+
'status' => 'created',
20+
]);
21+
22+
$storedLog = $storedWorkflow->logs()->create([
23+
'index' => 0,
24+
'now' => now()->toDateTimeString(),
25+
'class' => 'Activity1Class',
26+
'result' => 'N;',
27+
]);
28+
29+
$storedWorkflow->exceptions()->create([
30+
'class' => 'Activity2Class',
31+
'exception' => Y::serialize(new Exception('ExceptionMessage')),
32+
]);
33+
34+
35+
$response = $this
36+
->get('/waterline/api/flows/'.$storedWorkflow->id);
37+
38+
$response
39+
->assertStatus(200)
40+
->assertJson(
41+
fn (AssertableJson $json) => $json
42+
->where('id', $storedWorkflow->id)
43+
->where('class', 'WorkflowClass')
44+
->where('arguments', 'N;')
45+
->where('output', 'N;')
46+
->where('status', 'created')
47+
->whereType('created_at', 'string')
48+
->whereType('updated_at', 'string')
49+
->has(
50+
'logs',
51+
1,
52+
fn (AssertableJson $log) => $log
53+
->where('id', $storedLog->id)
54+
->where('index', 0)
55+
->whereType('now', 'string')
56+
->where('class', 'Activity1Class')
57+
->where('result', 'N;')
58+
->whereType('created_at', 'string')
59+
)
60+
->has(
61+
'exceptions',
62+
1,
63+
fn (AssertableJson $exception) => $exception
64+
->whereType('code', 'string')
65+
->whereType('exception', 'string')
66+
->where('class', 'Activity2Class')
67+
->whereType('created_at', 'string')
68+
)
69+
->has('chartData', 2)
70+
->where('chartData.0.x', 'WorkflowClass')
71+
->where('chartData.0.type', 'Workflow')
72+
->where('chartData.1.x', 'Activity1Class')
73+
->where('chartData.1.type', 'Activity')
74+
->whereAllType([
75+
'chartData.0.y.0' => 'integer',
76+
'chartData.0.y.1' => 'integer',
77+
'chartData.1.y.0' => 'integer',
78+
'chartData.1.y.1' => 'integer',
79+
])
80+
81+
);
82+
}
83+
}

0 commit comments

Comments
 (0)