|
13 | 13 | * @author JR Cologne <[email protected]> |
14 | 14 | * @copyright 2018 JR Cologne |
15 | 15 | * @license https://github.com/jr-cologne/db-class/blob/master/LICENSE MIT |
16 | | - * @version v2.2.0 |
| 16 | + * @version v2.3.0 |
17 | 17 | * @link https://github.com/jr-cologne/db-class GitHub Repository |
18 | 18 | * @link https://packagist.org/packages/jr-cologne/db-class Packagist site |
19 | 19 | * |
@@ -119,6 +119,15 @@ public function test_retrieve_method_returns_data_based_on_where_clause() { |
119 | 119 | ); |
120 | 120 | } |
121 | 121 |
|
| 122 | + public function test_retrieve_method_returns_data_based_on_where_clause_with_custom_operator() { |
| 123 | + $this->assertEquals('John', |
| 124 | + $this->getDBConnection() |
| 125 | + ->table('users') |
| 126 | + ->select('username', [ 'id' => 1, '||', 'username' => 'John', '&&', 'password' => 'ilovecats123' ]) |
| 127 | + ->retrieve('first')['username'] |
| 128 | + ); |
| 129 | + } |
| 130 | + |
122 | 131 | public function test_retrieve_method_returns_data_based_on_fetch_mode() { |
123 | 132 | $this->assertInternalType('object', |
124 | 133 | $this->getDBConnection() |
@@ -338,6 +347,26 @@ public function test_update_method_updates_data_in_database() { |
338 | 347 | ); |
339 | 348 | } |
340 | 349 |
|
| 350 | + public function test_update_method_updates_data_in_database_based_on_custom_where_clause() { |
| 351 | + $this->getDBConnection() |
| 352 | + ->table('users') |
| 353 | + ->update([ |
| 354 | + 'username' => 'Johnny' |
| 355 | + ], [ |
| 356 | + 'username' => 'John', |
| 357 | + '||', |
| 358 | + 'id' => 1, |
| 359 | + 'password' => 'ilovecats123' |
| 360 | + ]); |
| 361 | + |
| 362 | + $this->assertEquals('Johnny', |
| 363 | + $this->getDBConnection() |
| 364 | + ->table('users') |
| 365 | + ->select('username', [ 'username' => 'Johnny' ]) |
| 366 | + ->retrieve('first')['username'] ?? null |
| 367 | + ); |
| 368 | + } |
| 369 | + |
341 | 370 | public function test_update_method_without_where_clause_updates_all_data_in_database() { |
342 | 371 | $this->getDBConnection() |
343 | 372 | ->table('users') |
@@ -388,6 +417,24 @@ public function test_delete_method_deletes_data_in_database() { |
388 | 417 | ); |
389 | 418 | } |
390 | 419 |
|
| 420 | + public function test_delete_method_deletes_data_in_database_based_on_custom_where_clause() { |
| 421 | + $this->getDBConnection() |
| 422 | + ->table('users') |
| 423 | + ->delete([ |
| 424 | + 'id' => 1, |
| 425 | + 'username' => 'John', |
| 426 | + 'AND', |
| 427 | + 'password' => 'ilovecats123' |
| 428 | + ]); |
| 429 | + |
| 430 | + $this->assertCount(1, |
| 431 | + $this->getDBConnection() |
| 432 | + ->table('users') |
| 433 | + ->select('*') |
| 434 | + ->retrieve() |
| 435 | + ); |
| 436 | + } |
| 437 | + |
391 | 438 | public function test_delete_method_without_where_clause_deletes_all_data_in_database() { |
392 | 439 | $this->getDBConnection() |
393 | 440 | ->table('users') |
|
0 commit comments