-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some model functionality unit tests.
- Loading branch information
1 parent
2e81650
commit 8175c1d
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php namespace Tempest\Tests\Material; | ||
|
||
use Tempest\Database\Field; | ||
use Tempest\Database\Model; | ||
|
||
class ExampleModel extends Model { | ||
|
||
protected static function fields() { | ||
return [ | ||
'id' => Field::int()->setAutoIncrements(), | ||
'first' => Field::string(), | ||
'last' => Field::string(), | ||
'age' => Field::int()->setDefault(18), | ||
'email' => Field::string()->addUniqueKey('identity'), | ||
'mobile' => Field::string()->addUniqueKey('identity') | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php namespace Tempest\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Tempest\Tests\Material\ExampleModel; | ||
|
||
class ModelTest extends TestCase { | ||
|
||
public function testCreation() { | ||
$this->assertInstanceOf(ExampleModel::class, ExampleModel::create()); | ||
} | ||
|
||
public function testCreationWithValues() { | ||
$this->assertEquals('Marty', ExampleModel::create(['first' => 'Marty'])->getRaw('first')); | ||
} | ||
|
||
public function testDefaultValues() { | ||
$this->assertEquals(18, ExampleModel::create()->age); | ||
} | ||
|
||
public function testGetterAccess() { | ||
$model = ExampleModel::create([ | ||
'first' => 'Marty', | ||
'last' => 'Wallace' | ||
]); | ||
|
||
$this->assertEquals('Marty', $model->first); | ||
$this->assertEquals('Wallace', $model->last); | ||
} | ||
|
||
public function testSetValues() { | ||
$model = ExampleModel::create(); | ||
|
||
$model->setFieldValue('first', 'Marty'); | ||
$model->last = 'Wallace'; | ||
|
||
$this->assertEquals('Marty', $model->first); | ||
$this->assertEquals('Wallace', $model->last); | ||
} | ||
|
||
public function testFill() { | ||
$model = ExampleModel::create()->fill([ | ||
'email' => '[email protected]', | ||
'first' => 'Marty' | ||
]); | ||
|
||
$this->assertEquals('[email protected]', $model->email); | ||
$this->assertEquals('Marty', $model->first); | ||
$this->assertEquals(18, $model->age); | ||
$this->assertNull($model->last); | ||
} | ||
|
||
public function testGetPrimaryKey() { | ||
$this->assertEquals('id', ExampleModel::getPrimaryFields()[0]->getName()); | ||
} | ||
|
||
public function testGetUniqueIndexWithMultipleFields() { | ||
$this->assertCount(2, ExampleModel::getIndexByName('identity')->getFields()); | ||
} | ||
|
||
public function testGetNonIndexedFields() { | ||
$this->assertCount(3, ExampleModel::getNonIndexedFields()); | ||
} | ||
|
||
} |