castopod/tests/database/ExampleDatabaseTest.php
Yassine Doghri aa1612342e
style(ecs): add easy-coding-standard to enforce coding style rules for php
- update .devcontainer settings: remove auto-formatting
for php + set intelephense as default formatter
- remove prettier php plugin as it lacks php 8 support
- add captain hook action for checking style pre-commit
- fix style with ecs on all files except views
2021-06-11 09:34:48 +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
{
protected 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);
}
}