engelsystem/tests/Unit/Controllers/CleanupModelTest.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2020-10-21 00:11:33 +02:00
<?php
namespace Engelsystem\Test\Unit\Controllers;
use Engelsystem\Test\Unit\Controllers\Stub\CleanupModelImplementation;
use Engelsystem\Test\Unit\Controllers\Stub\TestModel;
use Engelsystem\Test\Unit\HasDatabase;
use Engelsystem\Test\Unit\TestCase;
class CleanupModelTest extends TestCase
{
use HasDatabase;
/**
* @covers \Engelsystem\Controllers\CleanupModel::cleanupModelNullValues
*/
public function testCleanupModelNullValues()
{
$cleanup = new CleanupModelImplementation();
$model = new TestModel();
$model->foo = null;
$model2 = new TestModel();
$model3 = new TestModel();
$cleanup->cleanup($model);
$cleanup->cleanup([$model2]);
$cleanup->cleanup($model3, ['text']);
$this->assertTrue(isset($model->text));
$this->assertTrue(isset($model->created_at));
$this->assertTrue(isset($model->foo));
$this->assertEquals('', $model->text);
$this->assertTrue(isset($model2->text));
$this->assertTrue(isset($model3->text));
$this->assertNull($model3->another_text);
$this->assertNull($model3->foo);
}
/**
* Setup the DB
*/
public function setUp(): void
{
parent::setUp();
$this->initDatabase();
}
}