-
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 #5279 from paulbalandan/pgsql-close
Fix compatibility of `PgSql\Result` on closing the result instance
- Loading branch information
Showing
2 changed files
with
35 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
use CodeIgniter\Database\Query; | ||
use CodeIgniter\Test\CIUnitTestCase; | ||
use CodeIgniter\Test\DatabaseTestTrait; | ||
use Tests\Support\Database\Seeds\CITestSeeder; | ||
|
||
/** | ||
* @group DatabaseLive | ||
|
@@ -25,19 +26,38 @@ final class PreparedQueryTest extends CIUnitTestCase | |
{ | ||
use DatabaseTestTrait; | ||
|
||
protected $refresh = true; | ||
protected $seed = 'Tests\Support\Database\Seeds\CITestSeeder'; | ||
protected $seed = CITestSeeder::class; | ||
|
||
/** | ||
* @var BasePreparedQuery|null | ||
*/ | ||
private $query; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->query = null; | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
if ($this->query !== null) { | ||
$this->query->close(); | ||
} | ||
} | ||
|
||
public function testPrepareReturnsPreparedQuery() | ||
{ | ||
$query = $this->db->prepare(static function ($db) { | ||
$this->query = $this->db->prepare(static function ($db) { | ||
return $db->table('user')->insert([ | ||
'name' => 'a', | ||
'email' => '[email protected]', | ||
]); | ||
}); | ||
|
||
$this->assertInstanceOf(BasePreparedQuery::class, $query); | ||
$this->assertInstanceOf(BasePreparedQuery::class, $this->query); | ||
|
||
$ec = $this->db->escapeChar; | ||
$pre = $this->db->DBPrefix; | ||
|
@@ -54,20 +74,19 @@ public function testPrepareReturnsPreparedQuery() | |
} else { | ||
$expected = "INSERT INTO {$ec}{$pre}user{$ec} ({$ec}name{$ec}, {$ec}email{$ec}) VALUES ({$placeholders})"; | ||
} | ||
$this->assertSame($expected, $query->getQueryString()); | ||
|
||
$query->close(); | ||
$this->assertSame($expected, $this->query->getQueryString()); | ||
} | ||
|
||
public function testPrepareReturnsManualPreparedQuery() | ||
{ | ||
$query = $this->db->prepare(static function ($db) { | ||
$this->query = $this->db->prepare(static function ($db) { | ||
$sql = "INSERT INTO {$db->DBPrefix}user (name, email, country) VALUES (?, ?, ?)"; | ||
|
||
return (new Query($db))->setQuery($sql); | ||
}); | ||
|
||
$this->assertInstanceOf(BasePreparedQuery::class, $query); | ||
$this->assertInstanceOf(BasePreparedQuery::class, $this->query); | ||
|
||
$pre = $this->db->DBPrefix; | ||
|
||
|
@@ -78,33 +97,29 @@ public function testPrepareReturnsManualPreparedQuery() | |
} | ||
|
||
$expected = "INSERT INTO {$pre}user (name, email, country) VALUES ({$placeholders})"; | ||
$this->assertSame($expected, $query->getQueryString()); | ||
|
||
$query->close(); | ||
$this->assertSame($expected, $this->query->getQueryString()); | ||
} | ||
|
||
public function testExecuteRunsQueryAndReturnsResultObject() | ||
{ | ||
$query = $this->db->prepare(static function ($db) { | ||
$this->query = $this->db->prepare(static function ($db) { | ||
return $db->table('user')->insert([ | ||
'name' => 'a', | ||
'email' => '[email protected]', | ||
'country' => 'x', | ||
]); | ||
}); | ||
|
||
$query->execute('foo', '[email protected]', 'US'); | ||
$query->execute('bar', '[email protected]', 'GB'); | ||
$this->query->execute('foo', '[email protected]', 'US'); | ||
$this->query->execute('bar', '[email protected]', 'GB'); | ||
|
||
$this->seeInDatabase($this->db->DBPrefix . 'user', ['name' => 'foo', 'email' => '[email protected]']); | ||
$this->seeInDatabase($this->db->DBPrefix . 'user', ['name' => 'bar', 'email' => '[email protected]']); | ||
|
||
$query->close(); | ||
} | ||
|
||
public function testExecuteRunsQueryAndReturnsManualResultObject() | ||
{ | ||
$query = $this->db->prepare(static function ($db) { | ||
$this->query = $this->db->prepare(static function ($db) { | ||
$sql = "INSERT INTO {$db->DBPrefix}user (name, email, country) VALUES (?, ?, ?)"; | ||
|
||
if ($db->DBDriver === 'SQLSRV') { | ||
|
@@ -114,12 +129,10 @@ public function testExecuteRunsQueryAndReturnsManualResultObject() | |
return (new Query($db))->setQuery($sql); | ||
}); | ||
|
||
$query->execute('foo', '[email protected]', ''); | ||
$query->execute('bar', '[email protected]', ''); | ||
$this->query->execute('foo', '[email protected]', ''); | ||
$this->query->execute('bar', '[email protected]', ''); | ||
|
||
$this->seeInDatabase($this->db->DBPrefix . 'user', ['name' => 'foo', 'email' => '[email protected]']); | ||
$this->seeInDatabase($this->db->DBPrefix . 'user', ['name' => 'bar', 'email' => '[email protected]']); | ||
|
||
$query->close(); | ||
} | ||
} |