Skip to content

Commit

Permalink
Modify insertTests
Browse files Browse the repository at this point in the history
  • Loading branch information
donjajo committed Sep 1, 2021
1 parent a047e4b commit 4117da5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 98 deletions.
36 changes: 13 additions & 23 deletions tests/JSONDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
class InsertTest extends TestCase {
private $db;

public function load_db() {
$this->db = new JSONDB( __DIR__ );
protected function setUp(): void {
$this->db = new JSONDB(__DIR__);
}

public function tearDown() {
@unlink( __DIR__ . '/users.sql' );
}

public function testInsert() : void {
$this->load_db();
$names = [ 'James£', 'John£', 'Oji£', 'Okeke', 'Bola', 'Thomas', 'Ibrahim', 'Smile' ];
$states = [ 'Abia', 'Lagos', 'Benue', 'Kano', 'Kastina', 'Abuja', 'Imo', 'Ogun' ];
shuffle( $names );
Expand All @@ -29,17 +32,21 @@ public function testInsert() : void {
'age' => $age
]);

$this->assertArrayHasKey( 0, $indexes );
$user = $this->db->select( '*' )
->from( 'users' )
->where( [ 'name' => $name, 'state' => $state, 'age' => $age ], 'AND' )
->get();

$this->db->insert( "users", array(
"name" => "Dummy",
"state" => "Lagos",
"age" => 12
));

$this->assertEquals( $name, $user[0]['name'] );
}

public function testGet() : void {
$this->load_db();
printf( "\nCheck exist\n" );
$users = ( $this->db->select( '*' )
->from( 'users' )
Expand All @@ -48,7 +55,6 @@ public function testGet() : void {
}

public function testWhere() : void {
$this->load_db();
$result = ( $this->db->select( '*' )
->from( 'users' )
->where([ 'name' => 'Okeke' ])
Expand All @@ -74,8 +80,6 @@ public function testWhere() : void {
}

public function testMultiWhere() : void {
$this->load_db();

$this->db->insert( "users", array(
"name" => "Jajo",
"age" => null,
Expand All @@ -93,8 +97,6 @@ public function testMultiWhere() : void {
}

public function testAND() : void {
$this->load_db();

$this->db->insert( "users", array(
"name" => "Jajo",
"age" => 50,
Expand All @@ -114,8 +116,6 @@ public function testAND() : void {
}

public function testRegexAND() : void {
$this->load_db();

$this->db->insert( "users", array(
"name" => "Paulo",
"age" => 50,
Expand Down Expand Up @@ -149,8 +149,6 @@ public function testRegexAND() : void {
}

public function testRegex() : void {
$this->load_db();

$this->db->insert( "users", array(
"name" => "Jajo",
"age" => 89,
Expand All @@ -172,8 +170,6 @@ public function testRegex() : void {
}

public function testUpdate() : void {
$this->load_db();

$this->db->update([ 'name' => 'Jammy', 'state' => 'Sokoto' ])
->from( 'users' )
->where([ 'name' => 'Okeke' ])
Expand All @@ -194,16 +190,12 @@ public function testUpdate() : void {
}

public function testSQLExport() : void {
$this->load_db();

$this->db->to_mysql( "users", "tests/users.sql" );

$this->assertTrue(file_exists( "tests/users.sql" ) );
}

public function testDelete() : void {
$this->load_db();

$this->db->delete()
->from( 'users' )
->where([ 'name' => 'Jammy' ])
Expand All @@ -217,9 +209,7 @@ public function testDelete() : void {
$this->assertEmpty( $result );
}

public function testDeleteAll() : void {
$this->load_db();

public function testDeleteAll() : void {
/* I add a select action with where statement */
$result_before = $this->db->select( '*' )
->from( 'users' )
Expand Down
53 changes: 1 addition & 52 deletions tests/users.json
Original file line number Diff line number Diff line change
@@ -1,52 +1 @@
[
{
"name": "John£",
"state": "Benue",
"age": 22
},
{
"name": "Jajo",
"age": null,
"state": "Lagos"
},
{
"name": "Johnny",
"age": 30,
"state": "Ogun"
},
{
"name": "Jajo",
"age": 50,
"state": "Lagos"
},
{
"name": "Johnny",
"age": 50,
"state": "Ogun"
},
{
"name": "Paulo",
"age": 50,
"state": "Algeria"
},
{
"name": "Nina",
"age": 50,
"state": "Nigeria"
},
{
"name": "Ogwo",
"age": 49,
"state": "Nigeria"
},
{
"name": "Jajo",
"age": 89,
"state": "Abia"
},
{
"name": "Mitchell",
"age": 45,
"state": "Zamfara"
}
]
[]
23 changes: 0 additions & 23 deletions tests/users.sql

This file was deleted.

0 comments on commit 4117da5

Please sign in to comment.