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 method database class truncate() as an alias of flush(true)…
…. Added REGEX on query operators. (and more testing)
- Loading branch information
1 parent
0523914
commit 7067fc7
Showing
8 changed files
with
138 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ class Predicate | |
'IN', | ||
'NOT', | ||
'LIKE', | ||
'NOT LIKE' | ||
'NOT LIKE', | ||
'REGEX' | ||
]; | ||
|
||
|
||
|
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 |
---|---|---|
|
@@ -187,7 +187,7 @@ public function testWhereCountAllGreaterLessCompare() | |
|
||
|
||
/** | ||
* testWhereLikeRegex() | ||
* testWhereLike() | ||
* | ||
* TEST CASE: | ||
* - Creates a bunch of items with the same information | ||
|
@@ -196,7 +196,7 @@ public function testWhereCountAllGreaterLessCompare() | |
* Comparisons used "LIKE", "NOT LIKE", "==" | ||
* | ||
*/ | ||
public function testWhereLikeRegex() | ||
public function testWhereLike() | ||
{ | ||
$db = new \Filebase\Database([ | ||
'dir' => __DIR__.'/databases/users_like', | ||
|
@@ -249,6 +249,58 @@ public function testWhereLikeRegex() | |
//-------------------------------------------------------------------- | ||
|
||
|
||
/** | ||
* testWhereRegex() | ||
* | ||
* TEST CASE: | ||
* - Testing the use of regex | ||
* | ||
* Comparisons used "REGEX" | ||
* | ||
*/ | ||
public function testWhereRegex() | ||
{ | ||
$db = new \Filebase\Database([ | ||
'dir' => __DIR__.'/databases/users_regex', | ||
'cache' => false | ||
]); | ||
|
||
$db->flush(true); | ||
|
||
for ($x = 1; $x <= 10; $x++) | ||
{ | ||
$user = $db->get(uniqid()); | ||
$user->name = 'John Ellot'; | ||
$user->email = '[email protected]'; | ||
$user->save(); | ||
} | ||
|
||
// the needle (with bad email) | ||
$user = $db->get(uniqid()); | ||
$user->name = 'Leo Ash'; | ||
$user->email = 'example@emailcom'; | ||
$user->save(); | ||
|
||
$count = $db->count(); | ||
|
||
// this should find match with regex loose expression | ||
$query1 = $db->query()->where('name','REGEX','/leo/i')->results(); | ||
$query2 = $db->query()->where('name','REGEX','/leo\sash/i')->results(); | ||
|
||
// finds all the emails in a field | ||
$query3 = $db->query()->where('email','REGEX','/[a-z\d._%+-]+@[a-z\d.-]+\.[a-z]{2,4}\b/i')->results(); | ||
|
||
$this->assertEquals(1, count($query1)); | ||
$this->assertEquals(1, count($query2)); | ||
$this->assertEquals(10, count($query3)); | ||
|
||
$db->flush(true); | ||
} | ||
|
||
|
||
//-------------------------------------------------------------------- | ||
|
||
|
||
/** | ||
* testLimitOffset() | ||
* | ||
|