Skip to content

Commit d23d501

Browse files
committed
Fix test logic, add test
1 parent c10f385 commit d23d501

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

tests/_support/DatabaseTestCase.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,22 @@ public function seeAudit(array $values)
7070
// Check each audit in the queue for a match
7171
foreach ($queue as $audit)
7272
{
73+
$found = true;
74+
7375
// Check each value against the audit
7476
foreach ($values as $key => $value)
7577
{
7678
if ($audit[$key] != $value)
7779
{
78-
break 2;
80+
$found = false;
81+
break;
7982
}
8083
}
8184

82-
$found = true;
83-
break;
85+
if ($found)
86+
{
87+
break;
88+
}
8489
}
8590

8691
$this->assertTrue($found, 'Audit not found in queue: ' . print_r($values, true));

tests/unit/TraitTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Tests\Support\DatabaseTestCase;
4+
use Tests\Support\Models\WidgetModel;
45

56
class TraitTest extends DatabaseTestCase
67
{
@@ -16,12 +17,35 @@ public function testInsertAddsAudit()
1617
'source_id' => $result,
1718
'event' => 'insert',
1819
'summary' => '5 fields',
19-
'user_id' => -1,
20+
'user_id' => 0,
2021
];
2122

2223
$queue = service('audits')->getQueue();
2324

2425
$this->assertCount(1, $queue);
2526
$this->seeAudit($expected);
2627
}
28+
29+
public function testUpdateAddsAudit()
30+
{
31+
$widget = fake(WidgetModel::class);
32+
$widgetId = $widget->id; // @phpstan-ignore-line
33+
34+
$this->model->update($widgetId, [
35+
'name' => 'Banana Widget',
36+
]);
37+
38+
$expected = [
39+
'source' => 'widgets',
40+
'source_id' => [$widgetId],
41+
'event' => 'update',
42+
'summary' => '2 fields',
43+
'user_id' => 0,
44+
];
45+
46+
$queue = service('audits')->getQueue();
47+
48+
$this->assertCount(2, $queue);
49+
$this->seeAudit($expected);
50+
}
2751
}

0 commit comments

Comments
 (0)