injitools /
cms-Inji
| 1 | <?php |
||
| 2 | |||
| 3 | class ModelTest extends \PHPUnit\Framework\TestCase { |
||
| 4 | |||
| 5 | |||
| 6 | public function testLocalInsertStorage() { |
||
| 7 | $time = time(); |
||
| 8 | $config = \Inji\Db\Options::create(['connect_name' => $time]); |
||
| 9 | $config->connectionName = 'injiStorage'; |
||
| 10 | $config->dbOptions['share'] = true; |
||
| 11 | $config->save(); |
||
| 12 | |||
| 13 | $builder = \Inji\Db\Options::sharedStorage(); |
||
| 14 | $builder->where('id', $config->pk()); |
||
| 15 | $config = $builder->get(); |
||
| 16 | |||
| 17 | $this->assertEquals($time, $config->connect_name); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 18 | |||
| 19 | return $config; |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @depends testLocalInsertStorage |
||
| 24 | */ |
||
| 25 | public function testLocalStorageUpdate($config) { |
||
| 26 | |||
| 27 | $id = $config->id; |
||
| 28 | |||
| 29 | $time = $config->connect_name + 1; |
||
| 30 | $config->connect_name = $time; |
||
| 31 | $config->save(); |
||
| 32 | |||
| 33 | $builder = \Inji\Db\Options::sharedStorage(); |
||
| 34 | $builder->where('id', $config->pk()); |
||
| 35 | $config = $builder->get(); |
||
| 36 | |||
| 37 | $this->assertEquals($id, $config->id); |
||
|
0 ignored issues
–
show
|
|||
| 38 | $this->assertEquals($time, $config->connect_name); |
||
|
0 ignored issues
–
show
|
|||
| 39 | return $config; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @depends testLocalInsertStorage |
||
| 44 | */ |
||
| 45 | public function testLocalStorageGetList($config) { |
||
| 46 | $time = $config->connect_name + 1; |
||
| 47 | $config->connect_name = $time; |
||
| 48 | $config->save(); |
||
| 49 | |||
| 50 | $builder = \Inji\Db\Options::sharedStorage(); |
||
| 51 | $configs = $builder->getList(); |
||
| 52 | |||
| 53 | $this->assertTrue(isset($configs[$config->id])); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @depends testLocalStorageUpdate |
||
| 58 | */ |
||
| 59 | public function testLocalStorageDelete($config) { |
||
| 60 | $config->delete(); |
||
| 61 | |||
| 62 | $builder = \Inji\Db\Options::connection('injiStorage'); |
||
| 63 | $builder->setDbOption('share', true); |
||
| 64 | $builder->where('id', $config->pk()); |
||
| 65 | $config = $builder->get(); |
||
| 66 | |||
| 67 | $this->assertEmpty($config); |
||
| 68 | } |
||
| 69 | } |