Skip to content

Commit

Permalink
Engine Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Jul 30, 2020
1 parent ad3d3fa commit 4144d34
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 15 additions & 5 deletions tests/src/Ease/SQL/EngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -160,22 +162,29 @@ 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());
}

/**
* @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());
}

/**
Expand All @@ -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());
}

/**
Expand Down

0 comments on commit 4144d34

Please sign in to comment.