95% coverage, getting close.
This commit is contained in:
parent
f3d5d12b9f
commit
db6e169f7b
6 changed files with 222 additions and 54 deletions
|
@ -61,6 +61,7 @@ function setUpConfig($config)
|
|||
}
|
||||
|
||||
`mysql -e 'TRUNCATE TABLE test.pickles;'`;
|
||||
`mysql -e 'TRUNCATE TABLE test.mypickles;'`;
|
||||
`mysql -e 'TRUNCATE TABLE test.users;'`;
|
||||
`echo 'flush_all' | nc localhost 11211`;
|
||||
|
||||
|
|
|
@ -6,16 +6,25 @@ class MockModelWithoutColumns extends Model
|
|||
public $columns = false;
|
||||
}
|
||||
|
||||
// InnoDB
|
||||
class MockModel extends Model
|
||||
{
|
||||
public $table = 'pickles';
|
||||
public $columns = ['created_at' => 'created_at'];
|
||||
}
|
||||
|
||||
// MyISAM
|
||||
class MyMockModel extends Model
|
||||
{
|
||||
public $table = 'mypickles';
|
||||
}
|
||||
|
||||
class ModelTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
// Clears out the Config for ease of testing
|
||||
Object::$instances = [];
|
||||
$config = Config::getInstance();
|
||||
|
||||
$config->data = [
|
||||
|
@ -353,6 +362,126 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
$model = new MockModel();
|
||||
$conditions = $model->generateConditions(['id BETWEEN' => '1']);
|
||||
}
|
||||
|
||||
public function testCommitSingleRecord()
|
||||
{
|
||||
$value = String::random();
|
||||
$model = new MockModel(1);
|
||||
$model->record['field1'] = $value;
|
||||
$model->commit();
|
||||
|
||||
$model = new MockModel(1);
|
||||
$this->assertEquals($value, $model->record['field1']);
|
||||
}
|
||||
|
||||
public function testCommitSingleRecordReplace()
|
||||
{
|
||||
# $value = String::random();
|
||||
# $model = new MockModel(1);
|
||||
# $model->replace = true;
|
||||
# $model->record['field1'] = $value;
|
||||
# $model->commit();
|
||||
# $model = new MockModel(1);
|
||||
# $this->assertEquals($value, $model->record['field1']);
|
||||
}
|
||||
|
||||
public function testCommitInsertPriority()
|
||||
{
|
||||
$value = String::random();
|
||||
$model = new MockModel();
|
||||
$model->priority = 'low';
|
||||
$model->record['field1'] = $value;
|
||||
$id = $model->commit();
|
||||
$model = new MockModel($id);
|
||||
$this->assertEquals($value, $model->record['field1']);
|
||||
}
|
||||
|
||||
public function testCommitInsertDelayed()
|
||||
{
|
||||
$value = String::random();
|
||||
$model = new MyMockModel();
|
||||
$model->delayed = true;
|
||||
$model->record['field1'] = $value;
|
||||
$model->commit();
|
||||
$model = new MyMockModel(1);
|
||||
$this->assertEquals($value, $model->record['field1']);
|
||||
}
|
||||
|
||||
public function testCommitInsertIgnore()
|
||||
{
|
||||
$value = String::random();
|
||||
$model = new MockModel();
|
||||
$model->ignore = true;
|
||||
$model->record['field1'] = $value;
|
||||
$id = $model->commit();
|
||||
$model = new MockModel($id);
|
||||
$this->assertEquals($value, $model->record['field1']);
|
||||
}
|
||||
|
||||
public function testCommitReplacePriority()
|
||||
{
|
||||
$value = String::random();
|
||||
$model = new MockModel();
|
||||
$model->replace = true;
|
||||
$model->priority = 'low';
|
||||
$model->record['field1'] = $value;
|
||||
$id = $model->commit();
|
||||
$model = new MockModel($id);
|
||||
$this->assertEquals($value, $model->record['field1']);
|
||||
}
|
||||
|
||||
public function testCommitReplaceDelayed()
|
||||
{
|
||||
$value = String::random();
|
||||
$model = new MyMockModel();
|
||||
$model->replace = true;
|
||||
$model->delayed = true;
|
||||
$model->record['field1'] = $value;
|
||||
$model->commit();
|
||||
$model = new MyMockModel(2);
|
||||
$this->assertEquals($value, $model->record['field1']);
|
||||
}
|
||||
|
||||
public function testCommitReplaceIgnore()
|
||||
{
|
||||
$value = String::random();
|
||||
$model = new MockModel();
|
||||
$model->replace = true;
|
||||
$model->ignore = true;
|
||||
$model->record['field1'] = $value;
|
||||
$id = $model->commit();
|
||||
$model = new MockModel($id);
|
||||
$this->assertEquals($value, $model->record['field1']);
|
||||
}
|
||||
|
||||
public function testDeleteLogical()
|
||||
{
|
||||
$_SESSION['__pickles']['security']['user_id'] = 1;
|
||||
$model = new MockModel(1);
|
||||
$model->delete();
|
||||
$model = new MockModelWithoutColumns(1);
|
||||
$this->assertEquals(1, $model->record['is_deleted']);
|
||||
}
|
||||
|
||||
public function testDeleteActual()
|
||||
{
|
||||
$model = new MockModelWithoutColumns(1);
|
||||
$model->delete();
|
||||
$model = new MockModelWithoutColumns(1);
|
||||
$this->assertEquals(0, $model->count());
|
||||
}
|
||||
|
||||
public function testDeleteNothing()
|
||||
{
|
||||
$model = new MockModelWithoutColumns(100);
|
||||
$this->assertFalse($model->delete());
|
||||
}
|
||||
|
||||
public function testLoadParametersWithString()
|
||||
{
|
||||
$model = new MockModel();
|
||||
$this->assertFalse($model->loadParameters(''));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -3,12 +3,12 @@ DROP TABLE IF EXISTS pickles;
|
|||
CREATE TABLE `pickles` (
|
||||
`id` int(1) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`field1` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`field2` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`field3` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`field4` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`field5` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`field2` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`field3` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`field4` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`field5` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`created_id` int(1) unsigned DEFAULT NULL,
|
||||
`created_at` datetime NOT NULL,
|
||||
`created_at` datetime DEFAULT NULL,
|
||||
`updated_id` int(1) unsigned DEFAULT NULL,
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
`deleted_id` int(1) unsigned DEFAULT NULL,
|
||||
|
@ -16,7 +16,27 @@ CREATE TABLE `pickles` (
|
|||
`is_deleted` tinyint(1) unsigned DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY is_deleted (is_deleted)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS mypickles;
|
||||
|
||||
CREATE TABLE `mypickles` (
|
||||
`id` int(1) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`field1` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`field2` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`field3` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`field4` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`field5` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`created_id` int(1) unsigned DEFAULT NULL,
|
||||
`created_at` datetime DEFAULT NULL,
|
||||
`updated_id` int(1) unsigned DEFAULT NULL,
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
`deleted_id` int(1) unsigned DEFAULT NULL,
|
||||
`deleted_at` datetime DEFAULT NULL,
|
||||
`is_deleted` tinyint(1) unsigned DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY is_deleted (is_deleted)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS users;
|
||||
|
||||
|
@ -32,4 +52,4 @@ CREATE TABLE `users` (
|
|||
`deleted_at` datetime DEFAULT NULL,
|
||||
`is_deleted` tinyint(1) unsigned DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue