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();
|
2020-11-21 20:54:04 +01:00
|
|
|
$model4 = null;
|
2020-10-21 00:11:33 +02:00
|
|
|
|
|
|
|
$cleanup->cleanup($model);
|
|
|
|
$cleanup->cleanup([$model2]);
|
|
|
|
$cleanup->cleanup($model3, ['text']);
|
2020-11-21 20:54:04 +01:00
|
|
|
$cleanup->cleanup($model4);
|
2020-10-21 00:11:33 +02:00
|
|
|
|
|
|
|
$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);
|
2020-11-21 20:54:04 +01:00
|
|
|
|
|
|
|
$this->assertNull($model4);
|
2020-10-21 00:11:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the DB
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->initDatabase();
|
|
|
|
}
|
|
|
|
}
|