Newer
Older

Yassine Doghri
committed
namespace Tests\Database;
use Tests\Support\DatabaseTestCase;
use Tests\Support\Models\ExampleModel;

Yassine Doghri
committed
class ExampleDatabaseTest extends DatabaseTestCase
protected function setUp(): void

Yassine Doghri
committed
{
parent::setUp();

Yassine Doghri
committed
// Extra code to run before each test
}

Yassine Doghri
committed
public function testModelFindAll(): void

Yassine Doghri
committed
{
$model = new ExampleModel();

Yassine Doghri
committed
// Get every row created by ExampleSeeder
$objects = $model->findAll();

Yassine Doghri
committed
// Make sure the count is as expected
$this->assertCount(3, $objects);
}

Yassine Doghri
committed
public function testSoftDeleteLeavesRow(): void

Yassine Doghri
committed
{
$model = new ExampleModel();
$this->setPrivateProperty($model, 'useSoftDeletes', true);
$this->setPrivateProperty($model, 'tempUseSoftDeletes', true);

Yassine Doghri
committed
$object = $model->first();
$model->delete($object->id);

Yassine Doghri
committed
// The model should no longer find it
$this->assertNull($model->find($object->id));

Yassine Doghri
committed
// ... but it should still be in the database
$result = $model
->builder()
->where('id', $object->id)
->get()
->getResult();

Yassine Doghri
committed
$this->assertCount(1, $result);
}