Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class Model implements \ArrayAccess, \IteratorAggregate

final public function __construct(?array $properties = null)
{
if ($this->hasProperties()) {
if (! empty($properties)) {
$this->setProperties($properties);
}

Expand Down
46 changes: 46 additions & 0 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace ipl\Tests\Orm;

use ipl\Orm\Model;

class ModelTest extends \PHPUnit\Framework\TestCase
{
public function testInitIsCalledAfterConstruction()
Expand All @@ -21,4 +23,48 @@ public function testOnReturnsQueryWithModelAndDatabaseConnectionAssociated()
/** @noinspection PhpParamsInspection */
$this->assertInstanceOf(TestModel::class, $query->getModel());
}

public function testModelsCanBeInitializedWithProperties(): void
{
$model = new class (['foo' => 'bar']) extends Model {
public function getTableName()
{
return 'test';
}

public function getKeyName()
{
return 'id';
}

public function getColumns()
{
return ['foo'];
}
};

$this->assertSame('bar', $model->foo);
}

public function testModelsCanBeInitializedWithoutProperties(): void
{
$model = new class extends Model {
public function getTableName()
{
return 'test';
}

public function getKeyName()
{
return 'id';
}

public function getColumns()
{
return ['foo'];
}
};

$this->assertFalse(isset($model->foo));
}
}
Loading