You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 line
1.1KB

  1. <?php
  2. use CodeIgniter\Test\CIUnitTestCase;
  3. use CodeIgniter\Test\DatabaseTestTrait;
  4. use Tests\Support\Database\Seeds\ExampleSeeder;
  5. use Tests\Support\Models\ExampleModel;
  6. /**
  7. * @internal
  8. */
  9. final class ExampleDatabaseTest extends CIUnitTestCase
  10. {
  11. use DatabaseTestTrait;
  12. protected $seed = ExampleSeeder::class;
  13. public function testModelFindAll()
  14. {
  15. $model = new ExampleModel();
  16. // Get every row created by ExampleSeeder
  17. $objects = $model->findAll();
  18. // Make sure the count is as expected
  19. $this->assertCount(3, $objects);
  20. }
  21. public function testSoftDeleteLeavesRow()
  22. {
  23. $model = new ExampleModel();
  24. $this->setPrivateProperty($model, 'useSoftDeletes', true);
  25. $this->setPrivateProperty($model, 'tempUseSoftDeletes', true);
  26. $object = $model->first();
  27. $model->delete($object->id);
  28. // The model should no longer find it
  29. $this->assertNull($model->find($object->id));
  30. // ... but it should still be in the database
  31. $result = $model->builder()->where('id', $object->id)->get()->getResult();
  32. $this->assertCount(1, $result);
  33. }
  34. }