Skip to content

Commit

Permalink
Added a test class for the Database functions
Browse files Browse the repository at this point in the history
  • Loading branch information
andela-aonyango committed Feb 24, 2016
1 parent ec16565 commit 1f9a4e8
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/DatabaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* @file DatabaseTest.php
* This class tests the functions in the Database class
* @package PotatoORM
* @author andrew <andrew.onyango@andela.com>
* @license MIT => https://opensource.org/licenses/MIT
*/

namespace PotatoORM\Test;

use PotatoORM\Database;
use PotatoORM\Models\Person;
use PHPUnit_Framework_TestCase;

/**
*Tests for the Database class
*
* @category Test
* @package PotatoORM
*/
class DatabaseTest extends PHPUnit_Framework_TestCase
{
public function testCRUDMethods()
{
$db = new Database();
$id = -1;

$person = $this->getPerson(["john", "doe"]);
$id = $db->insert("Person", $person);
$this->assertFalse($id == -1);

$db->select("Person", " id = $id");
$person = $db->singleObject(get_called_class());
$this->assertEquals("john", $person->{"first_name"});

$person = $this->getPerson(["jane", "dizoe"]);
$db->update("Person", $person, " id = $id");
$db->select("Person", " id = $id");
$person = $db->singleObject(get_called_class());
$this->assertEquals("jane", $person->{"first_name"});

$db->delete("Person");
}

private function getPerson($array)
{
return [
"first_name" => $array[0],
"last_name" => $array[1]
];
}
}

0 comments on commit 1f9a4e8

Please sign in to comment.