-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix failure when setting fetch mode before execute
- Loading branch information
Showing
4 changed files
with
153 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Nemo64\DbalRdsData\Tests; | ||
|
||
|
||
use Aws\RDSDataService\RDSDataServiceClient; | ||
use Aws\Result; | ||
use Nemo64\DbalRdsData\RdsDataConnection; | ||
|
||
trait RdsDataServiceClientTrait | ||
{ | ||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject|RDSDataServiceClient | ||
*/ | ||
private $client; | ||
|
||
private $expectedCalls = [ | ||
// ['executeStatement', ['options' => 'value'], 'returnValue'] | ||
]; | ||
|
||
/** | ||
* @var RdsDataConnection | ||
*/ | ||
private $connection; | ||
|
||
protected function createRdsDataServiceClient() | ||
{ | ||
$this->client = $this->createMock(RDSDataServiceClient::class); | ||
$this->client->method('__call')->willReturnCallback(function ($methodName, $arguments) { | ||
$nextCall = array_shift($this->expectedCalls); | ||
$this->assertIsArray($nextCall, "there must be another call planned"); | ||
$this->assertEquals($nextCall[0], $methodName, "method call"); | ||
$this->assertEquals($nextCall[1], $arguments[0], "options of $methodName"); | ||
return $nextCall[2]; | ||
}); | ||
|
||
$this->connection = new RdsDataConnection($this->client, 'arn:resource', 'arn:secret', 'db'); | ||
} | ||
|
||
private function addClientCall(string $method, array $options, array $result) | ||
{ | ||
$this->expectedCalls[] = [$method, $options, new Result($result)]; | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
namespace Nemo64\DbalRdsData\Tests; | ||
|
||
|
||
use Doctrine\DBAL\FetchMode; | ||
use Nemo64\DbalRdsData\RdsDataStatement; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RdsDataStatementTest extends TestCase | ||
{ | ||
use RdsDataServiceClientTrait; | ||
|
||
public function setUp() | ||
{ | ||
$this->createRdsDataServiceClient(); | ||
} | ||
|
||
public function testRetainFetchMode() | ||
{ | ||
foreach (range(1, 2) as $item) { | ||
$this->addClientCall( | ||
'executeStatement', | ||
[ | ||
'resourceArn' => 'arn:resource', | ||
'secretArn' => 'arn:secret', | ||
'database' => 'db', | ||
'continueAfterTimeout' => false, | ||
'includeResultMetadata' => true, | ||
'parameters' => [], | ||
'resultSetOptions' => ['decimalReturnType' => 'STRING'], | ||
'sql' => 'SELECT 1 AS id', | ||
], | ||
[ | ||
"columnMetadata" => [ | ||
["label" => "id"], | ||
], | ||
"numberOfRecordsUpdated" => 0, | ||
"records" => [ | ||
[ | ||
["longValue" => 1], | ||
], | ||
], | ||
] | ||
); | ||
} | ||
|
||
$statement = new RdsDataStatement($this->connection, 'SELECT 1 AS id'); | ||
|
||
$statement->setFetchMode(FetchMode::NUMERIC); | ||
$statement->execute(); | ||
$this->assertEquals([[1]], $statement->fetchAll()); | ||
$statement->execute(); | ||
$this->assertEquals([[1]], $statement->fetchAll()); | ||
} | ||
} |