Skip to content

Commit 6612ff3

Browse files
authored
The destroy test should assert for SoftDeleted (#381)
1 parent 5afc0d7 commit 6612ff3

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/Generators/TestGenerator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,13 @@ protected function buildTestCases(Controller $controller)
446446
} else {
447447
$setup['data'][] = sprintf('$%s = factory(%s::class)->create();', $variable, $model);
448448
}
449-
$assertions['generic'][] = sprintf('$this->assertDeleted($%s);', $variable);
449+
/** @var \Blueprint\Models\Model $local_model */
450+
$local_model = $this->tree->modelForContext($model);
451+
if (! is_null($local_model) && $local_model->usesSoftDeletes()) {
452+
$assertions['generic'][] = sprintf('$this->assertSoftDeleted($%s);', $variable);
453+
} else {
454+
$assertions['generic'][] = sprintf('$this->assertDeleted($%s);', $variable);
455+
}
450456
} elseif ($statement->operation() === 'update') {
451457
$assertions['sanity'][] = sprintf('$%s->refresh();', $variable);
452458

tests/fixtures/tests/models-with-custom-namespace-laravel8.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ public function destroy_deletes_and_responds_with()
133133

134134
$response->assertNoContent();
135135

136-
$this->assertDeleted($category);
136+
$this->assertSoftDeleted($category);
137137
}
138138
}

tests/fixtures/tests/models-with-custom-namespace.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ public function destroy_deletes_and_responds_with()
133133

134134
$response->assertNoContent();
135135

136-
$this->assertDeleted($category);
136+
$this->assertSoftDeleted($category);
137137
}
138138
}

0 commit comments

Comments
 (0)