More model testing

Getting close!
This commit is contained in:
Joshua Sherman 2014-01-19 14:25:15 -05:00
parent 4bffc1d80c
commit 07d2348dd1
2 changed files with 357 additions and 356 deletions

File diff suppressed because it is too large Load diff

View file

@ -2,14 +2,14 @@
class MockModelWithoutColumns extends Model class MockModelWithoutColumns extends Model
{ {
protected $table = 'pickles'; public $table = 'pickles';
protected $columns = false; public $columns = false;
} }
class MockModel extends Model class MockModel extends Model
{ {
protected $table = 'pickles'; public $table = 'pickles';
protected $columns = ['created_at' => 'created_at']; public $columns = ['created_at' => 'created_at'];
} }
class ModelTest extends PHPUnit_Framework_TestCase class ModelTest extends PHPUnit_Framework_TestCase
@ -245,6 +245,67 @@ class ModelTest extends PHPUnit_Framework_TestCase
$model->commit(); $model->commit();
} }
public function testGetFromCache()
{
$model = new MockModel(1);
$this->assertEquals('1', $model->record['id']);
}
public function testGetFromCacheConditionals()
{
$model = new MockModel(['conditions' => ['id' => 1]]);
$this->assertEquals('1', $model->record['id']);
}
public function testCacheKey()
{
$model = new MockModel('indexed', 1, 'cache-key');
$this->assertEquals([1], array_keys($model->records));
}
public function testGenerateQuery()
{
$model = new MockModelWithoutColumns([
'conditions' => [1, 2, 3],
'group' => 'id',
'having' => '1 = 1',
'order' => 'id DESC',
'limit' => 5,
'offset' => 1,
]);
$this->assertEquals('2', $model->record['id']);
}
public function testGenerateConditions()
{
$model = new MockModel();
$conditions = $model->generateConditions([
'id' => [1, 2, 3],
'NOT' => 5,
'OR id !=' => 10,
'OR NOT' => [15, 20, 25],
'id != 30',
'IS NOT' => null,
]);
var_dump($conditions);
}
public function testGenerateConditionsInjectValues()
{
$model = new MockModel();
$conditions = $model->generateConditions([
'id' => [1, 2, 3],
'NOT' => 5,
'OR id !=' => 10,
'OR NOT' => [15, 20, 25],
'id != 30',
'IS NOT' => null,
], true);
var_dump($conditions);
}
} }
?> ?>