castopod/tests/database/ExampleDatabaseTest.php
Yassine Doghri 5c5c6da4be
refactor: add rector to enforce type declarations, code quality + style and remove dead code
- update CI process to include quality stage (tests + code review)
- add captainhook to install git pre-commit & pre-push hooks
- remove .devcontainer Dockerfile to use project's docker-compose services: all
services can now be started automatically using vscode
- update docs/setup-development.md
2021-05-12 10:48:30 +00:00

50 lines
1.2 KiB
PHP

<?php
namespace Tests\Database;
use Tests\Support\DatabaseTestCase;
use Tests\Support\Models\ExampleModel;
class ExampleDatabaseTest extends DatabaseTestCase
{
public function setUp(): void
{
parent::setUp();
// Extra code to run before each test
}
public function testModelFindAll(): void
{
$model = new ExampleModel();
// Get every row created by ExampleSeeder
$objects = $model->findAll();
// Make sure the count is as expected
$this->assertCount(3, $objects);
}
public function testSoftDeleteLeavesRow(): void
{
$model = new ExampleModel();
$this->setPrivateProperty($model, 'useSoftDeletes', true);
$this->setPrivateProperty($model, 'tempUseSoftDeletes', true);
$object = $model->first();
$model->delete($object->id);
// The model should no longer find it
$this->assertNull($model->find($object->id));
// ... but it should still be in the database
$result = $model
->builder()
->where('id', $object->id)
->get()
->getResult();
$this->assertCount(1, $result);
}
}