This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new comparison operator "NOT" equals to "!=", added new method …
…for returning only objects resultDocuments(), results() is now just an array. Added some more extensive testing on query comparisons.
- Loading branch information
1 parent
a4c78b7
commit 3f099cb
Showing
7 changed files
with
136 additions
and
29 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
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
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
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
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
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
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 |
---|---|---|
|
@@ -4,7 +4,22 @@ | |
class QueryTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
public function testWhereQueryCount() | ||
/** | ||
* testWhereCountAllEqualCompare() | ||
* | ||
* TEST: | ||
* | ||
* 1. Creates 10 items in database with ["name" = "John"] | ||
* 2. Runs query to find items that have ["name" = "John"] | ||
* 3. Counts the total items in the database | ||
* 4. Compares the number of items in db to the number items the query found | ||
* | ||
* Results: Should be the EXACT SAME (query should find "all" items in db) | ||
* | ||
* Comparisons used "=", "==", "===" | ||
* | ||
*/ | ||
public function testWhereCountAllEqualCompare() | ||
{ | ||
$db = new \Filebase\Database([ | ||
'dir' => __DIR__.'/databases/users_1', | ||
|
@@ -17,21 +32,87 @@ public function testWhereQueryCount() | |
{ | ||
$user = $db->get(uniqid()); | ||
$user->name = 'John'; | ||
$user->save(); | ||
} | ||
|
||
$count = $db->count(); | ||
|
||
$query1 = $db->query()->where('name','=','John')->results(); | ||
$query2 = $db->query()->where('name','==','John')->results(); | ||
$query3 = $db->query()->where('name','===','John')->results(); | ||
$query4 = $db->query()->where(['name' => 'John'])->results(); | ||
|
||
$this->assertEquals($count, count($query1)); | ||
$this->assertEquals($count, count($query2)); | ||
$this->assertEquals($count, count($query3)); | ||
$this->assertEquals($count, count($query4)); | ||
|
||
$db->flush(true); | ||
} | ||
|
||
|
||
//-------------------------------------------------------------------- | ||
|
||
|
||
/** | ||
* testWhereCountAllNotEqualCompare() | ||
* | ||
* TEST CASE: | ||
* - Creates 10 items in database with ["name" = "John"] | ||
* - Counts the total items in the database | ||
* | ||
* FIRST TEST: | ||
* - Compares the number of items in db to the number items the query found | ||
* - Should match "10" | ||
* | ||
* SECOND TEST: | ||
* - Secondary Tests to find items that DO NOT match "John" | ||
* - Should match "0" | ||
* | ||
* Comparisons used "!=", "!==", "NOT" | ||
* | ||
*/ | ||
public function testWhereCountAllNotEqualCompare() | ||
{ | ||
$db = new \Filebase\Database([ | ||
'dir' => __DIR__.'/databases/users_1', | ||
'cache' => false | ||
]); | ||
|
||
$db->flush(true); | ||
|
||
for ($x = 1; $x <= 10; $x++) | ||
{ | ||
$user = $db->get(uniqid()); | ||
$user->name = 'John'; | ||
$user->save(); | ||
} | ||
|
||
$results = $db->query() | ||
->where('name','=','John') | ||
->results(); | ||
$count = $db->count(); | ||
|
||
$this->assertEquals($db->count(), count($results)); | ||
$query1 = $db->query()->where('name','!=','Max')->results(); | ||
$query2 = $db->query()->where('name','!==','Smith')->results(); | ||
$query3 = $db->query()->where('name','NOT','Jason')->results(); | ||
|
||
$query4 = $db->query()->where('name','!=','John')->results(); | ||
$query5 = $db->query()->where('name','!==','John')->results(); | ||
$query6 = $db->query()->where('name','NOT','John')->results(); | ||
|
||
$this->assertEquals($count, count($query1)); | ||
$this->assertEquals($count, count($query2)); | ||
$this->assertEquals($count, count($query3)); | ||
|
||
$this->assertEquals(0, count($query4)); | ||
$this->assertEquals(0, count($query5)); | ||
$this->assertEquals(0, count($query6)); | ||
|
||
$db->flush(true); | ||
$db->flushCache(); | ||
} | ||
|
||
|
||
//-------------------------------------------------------------------- | ||
|
||
|
||
public function testWhereQueryWhereCount() | ||
{ | ||
$db = new \Filebase\Database([ | ||
|
@@ -152,19 +233,18 @@ public function testWhereQueryFromCache() | |
$user = $db->get(uniqid()); | ||
$user->name = 'John'; | ||
$user->email = '[email protected]'; | ||
|
||
$user->save(); | ||
} | ||
|
||
$results = $db->query() | ||
->where('name','=','John') | ||
->andWhere('email','==','[email protected]') | ||
->results(); | ||
->resultDocuments(); | ||
|
||
$result_from_cache = $db->query() | ||
->where('name','=','John') | ||
->andWhere('email','==','[email protected]') | ||
->results(); | ||
->resultDocuments(); | ||
|
||
$this->assertEquals(10, count($results)); | ||
$this->assertEquals(true, ($result_from_cache[0]->isCache())); | ||
|