From 4144d3424636d5db8b428a91590c462b14fb4e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=C4=9Bzslav=20Dvo=C5=99=C3=A1k?= Date: Thu, 30 Jul 2020 10:52:52 +0200 Subject: [PATCH] Engine Unit Tests --- debian/control | 2 +- tests/src/Ease/SQL/EngineTest.php | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/debian/control b/debian/control index 58b4375..7986f70 100644 --- a/debian/control +++ b/debian/control @@ -1,4 +1,4 @@ -Source: php-vitexsoftware-ease-fluentpdo +` Source: php-vitexsoftware-ease-fluentpdo Build-Depends: debhelper (>= 7.0.50~) Section: web Standards-Version: 3.9.8 diff --git a/tests/src/Ease/SQL/EngineTest.php b/tests/src/Ease/SQL/EngineTest.php index 31b76ab..17b2dbe 100644 --- a/tests/src/Ease/SQL/EngineTest.php +++ b/tests/src/Ease/SQL/EngineTest.php @@ -13,13 +13,15 @@ class EngineTest extends \PHPUnit\Framework\TestCase { * @var Engine */ protected $object; + protected $lastId = null; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { - $this->object = new Engine(null, ['myTable' => 'test', 'createColumn' => 'created']); + $this->object = new Engine(null, ['myTable' => 'test', 'createColumn' => 'created', 'lastModifiedColumn' => 'updated']); + $this->lastId = $this->object->listingQuery()->orderBy('id DESC')->limit(1)->fetchColumn(0); } /** @@ -160,7 +162,7 @@ public function testDbreload() { * @covers Ease\SQL\Engine::dbsync */ public function testDbsync() { - $this->object->setData(['id'=>3,'key'=>'thrid','value'=>'newone']); + $this->object->setData(['id' => 3, 'key' => 'thrid', 'value' => 'newone']); $this->assertEquals('', $this->object->dbsync()); } @@ -168,14 +170,21 @@ public function testDbsync() { * @covers Ease\SQL\Engine::updateToSQL */ public function testUpdateToSQL() { - $this->assertEquals(1, $this->object->updateToSQL(['id'=>1,'key'=>'foo','value'=>'updated'])); + $this->assertEquals(1, $this->object->updateToSQL(['id' => 1, 'key' => 'foo', 'value' => 'updated'])); + $this->object->setData(['id' => 1, 'key' => 'foo', 'value' => 'a']); + $this->assertEquals(1, $this->object->updateToSQL()); //Reset to Inital value for further testing + $this->expectException('\Ease\Exception'); + $this->object->updateToSQL(['foo' => 'bar']); } /** * @covers Ease\SQL\Engine::saveToSQL */ public function testSaveToSQL() { - $this->assertEquals('', $this->object->saveToSQL()); + $this->object->setData(['key' => 'saved', 'value' => 'sure']); + $this->assertEquals($this->lastId + 1, $this->object->saveToSQL()); + $this->object->setData(['id' => 3, 'key' => 'saved', 'value' => 'sure']); + $this->assertEquals(3, $this->object->saveToSQL()); } /** @@ -194,7 +203,8 @@ public function testInsertToSQL() { * @covers Ease\SQL\Engine::deleteFromSQL */ public function testDeleteFromSQL() { - $this->assertEquals('', $this->object->deleteFromSQL()); + $this->object->setData(['id' => $this->lastId]); + $this->assertEquals(1, $this->object->deleteFromSQL()); } /**