1313 * @author JR Cologne <[email protected] > 1414 * @copyright 2018 JR Cologne
1515 * @license https://github.com/jr-cologne/db-class/blob/master/LICENSE MIT
16- * @version v2.3 .0
16+ * @version v2.4 .0
1717 * @link https://github.com/jr-cologne/db-class GitHub Repository
1818 * @link https://packagist.org/packages/jr-cologne/db-class Packagist site
1919 *
@@ -119,11 +119,34 @@ public function test_retrieve_method_returns_data_based_on_where_clause() {
119119 );
120120 }
121121
122- public function test_retrieve_method_returns_data_based_on_where_clause_with_custom_operator () {
122+ public function test_retrieve_method_returns_data_based_on_where_clause_with_custom_logical_operator () {
123123 $ this ->assertEquals ('John ' ,
124124 $ this ->getDBConnection ()
125125 ->table ('users ' )
126- ->select ('username ' , [ 'id ' => 1 , '|| ' , 'username ' => 'John ' , '&& ' , 'password ' => 'ilovecats123 ' ])
126+ ->select ('username ' , [
127+ 'id ' => 1 ,
128+ '|| ' ,
129+ 'username ' => 'John ' ,
130+ '&& ' ,
131+ 'password ' => 'ilovecats123 '
132+ ])
133+ ->retrieve ('first ' )['username ' ]
134+ );
135+ }
136+
137+ public function test_retrieve_method_returns_data_based_on_where_clause_with_custom_comparison_operator () {
138+ $ this ->assertEquals ('John ' ,
139+ $ this ->getDBConnection ()
140+ ->table ('users ' )
141+ ->select ('username ' , [
142+ [
143+ 'id ' ,
144+ '!= ' ,
145+ 2
146+ ],
147+ 'username ' => 'John ' ,
148+ 'password ' => 'ilovecats123 '
149+ ])
127150 ->retrieve ('first ' )['username ' ]
128151 );
129152 }
@@ -347,7 +370,7 @@ public function test_update_method_updates_data_in_database() {
347370 );
348371 }
349372
350- public function test_update_method_updates_data_in_database_based_on_custom_where_clause () {
373+ public function test_update_method_updates_data_in_database_based_on_where_clause_with_custom_logical_operator () {
351374 $ this ->getDBConnection ()
352375 ->table ('users ' )
353376 ->update ([
@@ -367,6 +390,30 @@ public function test_update_method_updates_data_in_database_based_on_custom_wher
367390 );
368391 }
369392
393+ public function test_update_method_updates_data_in_database_based_on_where_clause_with_custom_comparison_operator () {
394+ $ this ->getDBConnection ()
395+ ->table ('users ' )
396+ ->update ([
397+ 'username ' => 'Johnny '
398+ ], [
399+ 'username ' => 'John ' ,
400+ '|| ' ,
401+ [
402+ 'id ' ,
403+ '= ' ,
404+ 1
405+ ],
406+ 'password ' => 'ilovecats123 '
407+ ]);
408+
409+ $ this ->assertEquals ('Johnny ' ,
410+ $ this ->getDBConnection ()
411+ ->table ('users ' )
412+ ->select ('username ' , [ 'username ' => 'Johnny ' ])
413+ ->retrieve ('first ' )['username ' ] ?? null
414+ );
415+ }
416+
370417 public function test_update_method_without_where_clause_updates_all_data_in_database () {
371418 $ this ->getDBConnection ()
372419 ->table ('users ' )
@@ -417,7 +464,7 @@ public function test_delete_method_deletes_data_in_database() {
417464 );
418465 }
419466
420- public function test_delete_method_deletes_data_in_database_based_on_custom_where_clause () {
467+ public function test_delete_method_deletes_data_in_database_based_on_where_clause_with_custom_logical_operator () {
421468 $ this ->getDBConnection ()
422469 ->table ('users ' )
423470 ->delete ([
@@ -435,6 +482,32 @@ public function test_delete_method_deletes_data_in_database_based_on_custom_wher
435482 );
436483 }
437484
485+ public function test_delete_method_deletes_data_in_database_based_on_where_clause_with_custom_comparison_operator () {
486+ $ this ->getDBConnection ()
487+ ->table ('users ' )
488+ ->delete ([
489+ [
490+ 'id ' ,
491+ '>= ' ,
492+ 1
493+ ],
494+ 'username ' => 'John ' ,
495+ 'AND ' ,
496+ [
497+ 'password ' ,
498+ '!= ' ,
499+ 'test123 '
500+ ]
501+ ]);
502+
503+ $ this ->assertCount (1 ,
504+ $ this ->getDBConnection ()
505+ ->table ('users ' )
506+ ->select ('* ' )
507+ ->retrieve ()
508+ );
509+ }
510+
438511 public function test_delete_method_without_where_clause_deletes_all_data_in_database () {
439512 $ this ->getDBConnection ()
440513 ->table ('users ' )
0 commit comments