-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test class for the Database functions
- Loading branch information
1 parent
ec16565
commit 1f9a4e8
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
]; | ||
} | ||
} |