connection = ConnectionManager::get('test'); static::setAppNamespace(); } /** * teardown * * @return void */ public function tearDown() { parent::tearDown(); $this->getTableLocator()->clear(); } /** * Test saving new records sets uuids * * @return void */ public function testSaveNew() { $now = new DateTime('now'); $entity = new Entity([ 'id' => $now, 'title' => 'shiny new', ]); $table = $this->getTableLocator()->get('DateKeys'); $this->assertSame($entity, $table->save($entity)); $this->assertEquals($now, $entity->id); $row = $table->find('all')->where(['id' => $entity->id])->first(); $this->assertEquals($row->id->format('Y-m-d'), $entity->id->format('Y-m-d')); } /** * Test saving existing records works * * @return void */ public function testSaveUpdate() { $id = new DateTime('now'); $entity = new Entity([ 'id' => $id, 'title' => 'shiny update', ]); $table = $this->getTableLocator()->get('DateKeys'); $this->assertSame($entity, $table->save($entity)); $this->assertEquals($id, $entity->id, 'Should match'); $row = $table->find('all')->where(['id' => $entity->id])->first(); $row->title = 'things'; $this->assertSame($row, $table->save($row)); } /** * Test delete with string pk. * * @return void */ public function testDelete() { $table = $this->getTableLocator()->get('DateKeys'); $entity = new Entity([ 'id' => new DateTime('now'), 'title' => 'shiny update', ]); $table->save($entity); $this->assertTrue($table->delete($entity)); $query = $table->find('all')->where(['id' => $entity->id]); $this->assertEmpty($query->first(), 'No row left'); } }