13/06
2016
Wallogit.com
2017 © Pedro Peláez
Trait to check for soft deletes in Laravel 5
This is a trait for extending Laravel 5.1 testing functionality, to see if something has been soft-deleted in the database., (*1)
First, require the composer package: composer require kirkbater/soft-deletes, (*2)
Then, add the soft deletes functionality to your test:, (*3)
<?php
use Kirkbater\Testing\SoftDeletes;
class MyTestClass extends TestClass {
use SoftDeletes;
}
Then, write your unit tests, just like normal:, (*4)
```php <?php, (*5)
..., (*6)
public function tests_that_its_soft_deleted() { $user = [ "id" => 1, "first" => "Test", "last" => "Name", "username" => "txltwc" ];, (*7)
$response = $this->call('delete', '/users/'.$user->id, []);
$this->assertEquals(200, $response->status());
$this->seeInDatabase("users", $user);
$this->seeIsSoftDeletedInDatabase("users", $user);
}, (*8)