-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8979 from ducng99/feat/add_foundrows_mysqli_config
feat: add `foundRows` option for MySQLi config
- Loading branch information
Showing
6 changed files
with
190 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter\Database\Live\MySQLi; | ||
|
||
use CodeIgniter\Test\CIUnitTestCase; | ||
use CodeIgniter\Test\DatabaseTestTrait; | ||
use Config\Database; | ||
use PHPUnit\Framework\Attributes\Group; | ||
use Tests\Support\Database\Seeds\CITestSeeder; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Group('DatabaseLive')] | ||
final class FoundRowsTest extends CIUnitTestCase | ||
{ | ||
use DatabaseTestTrait; | ||
|
||
/** | ||
* Database config for tests | ||
* | ||
* @var array<string, mixed> | ||
*/ | ||
private $tests; | ||
|
||
protected $refresh = true; | ||
protected $seed = CITestSeeder::class; | ||
|
||
protected function setUp(): void | ||
{ | ||
$config = config('Database'); | ||
|
||
$this->tests = $config->tests; | ||
|
||
if ($this->tests['DBDriver'] !== 'MySQLi') { | ||
$this->markTestSkipped('Only MySQLi can complete this test.'); | ||
} | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testEnableFoundRows(): void | ||
{ | ||
$this->tests['foundRows'] = true; | ||
|
||
$db1 = Database::connect($this->tests); | ||
|
||
$this->assertTrue($db1->foundRows); | ||
} | ||
|
||
public function testDisableFoundRows(): void | ||
{ | ||
$this->tests['foundRows'] = false; | ||
|
||
$db1 = Database::connect($this->tests); | ||
|
||
$this->assertFalse($db1->foundRows); | ||
} | ||
|
||
public function testAffectedRowsAfterEnableFoundRowsWithNoChange(): void | ||
{ | ||
$this->tests['foundRows'] = true; | ||
|
||
$db1 = Database::connect($this->tests); | ||
|
||
$db1->table('db_user') | ||
->set('country', 'US') | ||
->where('country', 'US') | ||
->update(); | ||
|
||
$affectedRows = $db1->affectedRows(); | ||
|
||
$this->assertSame($affectedRows, 2); | ||
} | ||
|
||
public function testAffectedRowsAfterDisableFoundRowsWithNoChange(): void | ||
{ | ||
$this->tests['foundRows'] = false; | ||
|
||
$db1 = Database::connect($this->tests); | ||
|
||
$db1->table('db_user') | ||
->set('country', 'US') | ||
->where('country', 'US') | ||
->update(); | ||
|
||
$affectedRows = $db1->affectedRows(); | ||
|
||
$this->assertSame($affectedRows, 0); | ||
} | ||
|
||
public function testAffectedRowsAfterEnableFoundRowsWithChange(): void | ||
{ | ||
$this->tests['foundRows'] = true; | ||
|
||
$db1 = Database::connect($this->tests); | ||
|
||
$db1->table('db_user') | ||
->set('country', 'NZ') | ||
->where('country', 'US') | ||
->update(); | ||
|
||
$affectedRows = $db1->affectedRows(); | ||
|
||
$this->assertSame($affectedRows, 2); | ||
} | ||
|
||
public function testAffectedRowsAfterDisableFoundRowsWithChange(): void | ||
{ | ||
$this->tests['foundRows'] = false; | ||
|
||
$db1 = Database::connect($this->tests); | ||
|
||
$db1->table('db_user') | ||
->set('country', 'NZ') | ||
->where('country', 'US') | ||
->update(); | ||
|
||
$affectedRows = $db1->affectedRows(); | ||
|
||
$this->assertSame($affectedRows, 2); | ||
} | ||
|
||
public function testAffectedRowsAfterEnableFoundRowsWithPartialChange(): void | ||
{ | ||
$this->tests['foundRows'] = true; | ||
|
||
$db1 = Database::connect($this->tests); | ||
|
||
$db1->table('db_user') | ||
->set('name', 'Derek Jones') | ||
->where('country', 'US') | ||
->update(); | ||
|
||
$affectedRows = $db1->affectedRows(); | ||
|
||
$this->assertSame($affectedRows, 2); | ||
} | ||
|
||
public function testAffectedRowsAfterDisableFoundRowsWithPartialChange(): void | ||
{ | ||
$this->tests['foundRows'] = false; | ||
|
||
$db1 = Database::connect($this->tests); | ||
|
||
$db1->table('db_user') | ||
->set('name', 'Derek Jones') | ||
->where('country', 'US') | ||
->update(); | ||
|
||
$affectedRows = $db1->affectedRows(); | ||
|
||
$this->assertSame($affectedRows, 1); | ||
} | ||
} |
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