New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Third parameter not allowed for PDO::FETCH_COLUMN #4173
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
70 changes: 70 additions & 0 deletions
70
tests/Doctrine/Tests/DBAL/Functional/ExternalPDOInstanceTest.php
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,70 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\DBAL\Functional; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Driver\PDO\SQLite\Driver as PDOSqliteDriver; | ||
use Doctrine\DBAL\FetchMode; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\Tests\DbalTestCase; | ||
use Doctrine\Tests\TestUtil; | ||
use PDO; | ||
|
||
class ExternalPDOInstanceTest extends DbalTestCase | ||
{ | ||
/** @var Connection */ | ||
protected $connection; | ||
|
||
protected function setUp(): void | ||
{ | ||
if (! TestUtil::getConnection()->getDriver() instanceof PDOSqliteDriver) { | ||
$this->markTestSkipped('External PDO instance tests are only run on PDO SQLite for now'); | ||
} | ||
|
||
$pdo = new PDO('sqlite::memory:'); | ||
|
||
$this->connection = new Connection(['pdo' => $pdo], new PDOSqliteDriver()); | ||
|
||
$table = new Table('stmt_fetch_all'); | ||
$table->addColumn('a', 'integer'); | ||
$table->addColumn('b', 'integer'); | ||
|
||
$this->connection->getSchemaManager()->createTable($table); | ||
|
||
$this->connection->insert('stmt_fetch_all', [ | ||
'a' => 1, | ||
'b' => 2, | ||
]); | ||
} | ||
|
||
public function testFetchAllWithOneArgument(): void | ||
{ | ||
$stmt = $this->connection->prepare('SELECT a, b FROM stmt_fetch_all'); | ||
$stmt->execute(); | ||
|
||
self::assertEquals([[1, 2]], $stmt->fetchAll(FetchMode::NUMERIC)); | ||
} | ||
|
||
public function testFetchAllWithTwoArguments(): void | ||
{ | ||
$stmt = $this->connection->prepare('SELECT a, b FROM stmt_fetch_all'); | ||
$stmt->execute(); | ||
|
||
self::assertEquals([2], $stmt->fetchAll(FetchMode::COLUMN, 1)); | ||
} | ||
|
||
public function testFetchAllWithThreeArguments(): void | ||
{ | ||
$stmt = $this->connection->prepare('SELECT a, b FROM stmt_fetch_all'); | ||
$stmt->execute(); | ||
|
||
[$obj] = $stmt->fetchAll(FetchMode::CUSTOM_OBJECT, StatementTestModel::class, ['foo', 'bar']); | ||
|
||
$this->assertInstanceOf(StatementTestModel::class, $obj); | ||
|
||
self::assertEquals(1, $obj->a); | ||
self::assertEquals(2, $obj->b); | ||
self::assertEquals('foo', $obj->x); | ||
self::assertEquals('bar', $obj->y); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Doctrine/Tests/DBAL/Functional/StatementTestModel.php
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,24 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\DBAL\Functional; | ||
|
||
class StatementTestModel | ||
{ | ||
public function __construct(string $x, string $y) | ||
{ | ||
$this->x = $x; | ||
$this->y = $y; | ||
} | ||
|
||
/** @var int */ | ||
public $a; | ||
|
||
/** @var int */ | ||
public $b; | ||
|
||
/** @var string */ | ||
public $x; | ||
|
||
/** @var string */ | ||
public $y; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen here if a run the test suite with say
sqlsrv
configuration and don't havepdo_sqlite
installed? All existing functional tests have proper checks for the installed extensions and current configuration. Why do you need it to not be a functional one?I'd write a proper functional test that:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I forgot that
PDOConnection
extendsPDO
in 2.x, so I can indeed get the PDO instance from the existingConnection
to create a new one. Done!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, while the tests do pass, they also pass on 2.10 now I'm afraid. This is because the PDO we extract from the Connection is a PDOConnection, not a raw PDO. So we're back to square one: there does not seem to be a way to run this test for all PDO drivers, without creating our own PDO instances, which requires duplicating the PDO creation logic from the driver (DSN etc.) in the tests.
This is what I called overkill in development time, for a quick fix that will be gone in 3.0 anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh... you're right. This is why we're getting rid of this untestable inheritance. Please restore the previous version and squash.
I can't agree. Fixing something that is not supposed to be used may be overkill. Proper testing is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! And re-introduced the PDO SQLite driver check to only run tests on CI that target SQLite, and prevent it from running when SQLite might not be available.