From 12a6da56e740a23da742ccaa3629f91881c1c2d9 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:49:56 +0200 Subject: [PATCH 1/9] add RequiresPhpExtension --- Tests/Mysql/MysqlDriverTest.php | 2 ++ Tests/Mysql/MysqlPreparedStatementTest.php | 2 ++ Tests/Mysqli/MysqliDriverTest.php | 2 ++ Tests/Mysqli/MysqliPreparedStatementTest.php | 2 ++ Tests/Mysqli/MysqliStatementTest.php | 2 ++ Tests/Pgsql/PgsqlDriverTest.php | 2 ++ Tests/Pgsql/PgsqlPreparedStatementTest.php | 2 ++ Tests/Sqlite/SqliteDriverTest.php | 3 +++ Tests/Sqlite/SqlitePreparedStatementTest.php | 3 +++ Tests/Sqlsrv/SqlsrvDriverTest.php | 2 ++ Tests/Sqlsrv/SqlsrvPreparedStatementTest.php | 2 ++ Tests/Sqlsrv/SqlsrvStatementTest.php | 2 ++ 12 files changed, 26 insertions(+) diff --git a/Tests/Mysql/MysqlDriverTest.php b/Tests/Mysql/MysqlDriverTest.php index feae9357..172854aa 100644 --- a/Tests/Mysql/MysqlDriverTest.php +++ b/Tests/Mysql/MysqlDriverTest.php @@ -15,10 +15,12 @@ use Joomla\Database\ParameterType; use Joomla\Database\Tests\AbstractDatabaseDriverTestCase; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Test class for Joomla\Database\Mysql\MysqlDriver */ +#[RequiresPhpExtension('pdo_mysql')] class MysqlDriverTest extends AbstractDatabaseDriverTestCase { /** diff --git a/Tests/Mysql/MysqlPreparedStatementTest.php b/Tests/Mysql/MysqlPreparedStatementTest.php index f450db22..ce7213e9 100644 --- a/Tests/Mysql/MysqlPreparedStatementTest.php +++ b/Tests/Mysql/MysqlPreparedStatementTest.php @@ -9,7 +9,9 @@ use Joomla\Database\DatabaseDriver; use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; +#[RequiresPhpExtension('pdo_mysql')] class MysqlPreparedStatementTest extends DatabaseTestCase { /** diff --git a/Tests/Mysqli/MysqliDriverTest.php b/Tests/Mysqli/MysqliDriverTest.php index 59d5d33d..71d20bc0 100644 --- a/Tests/Mysqli/MysqliDriverTest.php +++ b/Tests/Mysqli/MysqliDriverTest.php @@ -16,10 +16,12 @@ use Joomla\Database\ParameterType; use Joomla\Database\Tests\AbstractDatabaseDriverTestCase; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Test class for Joomla\Database\Mysqli\MysqliDriver */ +#[RequiresPhpExtension('mysqli')] class MysqliDriverTest extends AbstractDatabaseDriverTestCase { /** diff --git a/Tests/Mysqli/MysqliPreparedStatementTest.php b/Tests/Mysqli/MysqliPreparedStatementTest.php index 38d73d56..446e71d1 100644 --- a/Tests/Mysqli/MysqliPreparedStatementTest.php +++ b/Tests/Mysqli/MysqliPreparedStatementTest.php @@ -10,7 +10,9 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Mysqli\MysqliStatement; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; +#[RequiresPhpExtension('mysqli')] class MysqliPreparedStatementTest extends DatabaseTestCase { /** diff --git a/Tests/Mysqli/MysqliStatementTest.php b/Tests/Mysqli/MysqliStatementTest.php index 669b46f4..20eed94d 100644 --- a/Tests/Mysqli/MysqliStatementTest.php +++ b/Tests/Mysqli/MysqliStatementTest.php @@ -10,10 +10,12 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Mysqli\MysqliStatement; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Test class for Joomla\Database\Mysqli\MysqliStatement */ +#[RequiresPhpExtension('mysqli')] class MysqliStatementTest extends DatabaseTestCase { /** diff --git a/Tests/Pgsql/PgsqlDriverTest.php b/Tests/Pgsql/PgsqlDriverTest.php index ee297a71..81ab2b8b 100644 --- a/Tests/Pgsql/PgsqlDriverTest.php +++ b/Tests/Pgsql/PgsqlDriverTest.php @@ -13,10 +13,12 @@ use Joomla\Database\Pgsql\PgsqlQuery; use Joomla\Database\Tests\AbstractDatabaseDriverTestCase; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Test class for Joomla\Database\Pgsql\PgsqlDriver */ +#[RequiresPhpExtension('pdo_pgsql')] class PgsqlDriverTest extends AbstractDatabaseDriverTestCase { /** diff --git a/Tests/Pgsql/PgsqlPreparedStatementTest.php b/Tests/Pgsql/PgsqlPreparedStatementTest.php index 41b4fe18..10dd392f 100644 --- a/Tests/Pgsql/PgsqlPreparedStatementTest.php +++ b/Tests/Pgsql/PgsqlPreparedStatementTest.php @@ -9,10 +9,12 @@ use Joomla\Database\DatabaseDriver; use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Test class for Joomla\Database\Pgsql\PgsqlStatement */ +#[RequiresPhpExtension('pdo_pgsql')] class PgsqlPreparedStatementTest extends DatabaseTestCase { /** diff --git a/Tests/Sqlite/SqliteDriverTest.php b/Tests/Sqlite/SqliteDriverTest.php index 3d1ec2fc..97127c7a 100644 --- a/Tests/Sqlite/SqliteDriverTest.php +++ b/Tests/Sqlite/SqliteDriverTest.php @@ -14,10 +14,13 @@ use Joomla\Database\Sqlite\SqliteQuery; use Joomla\Database\Tests\AbstractDatabaseDriverTestCase; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Test class for Joomla\Database\Sqlite\SqliteDriver */ +#[RequiresPhpExtension('pdo_sqlite')] +#[RequiresPhpExtension('sqlite3')] class SqliteDriverTest extends AbstractDatabaseDriverTestCase { /** diff --git a/Tests/Sqlite/SqlitePreparedStatementTest.php b/Tests/Sqlite/SqlitePreparedStatementTest.php index 3ddb258c..5201c93a 100644 --- a/Tests/Sqlite/SqlitePreparedStatementTest.php +++ b/Tests/Sqlite/SqlitePreparedStatementTest.php @@ -9,7 +9,10 @@ use Joomla\Database\DatabaseDriver; use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; +#[RequiresPhpExtension('pdo_sqlite')] +#[RequiresPhpExtension('sqlite3')] class SqlitePreparedStatementTest extends DatabaseTestCase { /** diff --git a/Tests/Sqlsrv/SqlsrvDriverTest.php b/Tests/Sqlsrv/SqlsrvDriverTest.php index 19bda8fc..99bb9769 100644 --- a/Tests/Sqlsrv/SqlsrvDriverTest.php +++ b/Tests/Sqlsrv/SqlsrvDriverTest.php @@ -13,10 +13,12 @@ use Joomla\Database\Sqlsrv\SqlsrvQuery; use Joomla\Database\Tests\AbstractDatabaseDriverTestCase; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Test class for Joomla\Database\Sqlsrv\SqlsrvDriver. */ +#[RequiresPhpExtension('sqlsrv')] class SqlsrvDriverTest extends AbstractDatabaseDriverTestCase { /** diff --git a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php index f21e4b1f..48c60546 100644 --- a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php +++ b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php @@ -10,10 +10,12 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Sqlsrv\SqlsrvStatement; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Test class for Joomla\Database\Sqlsrv\SqlsrvStatement */ +#[RequiresPhpExtension('sqlsrv')] class SqlsrvPreparedStatementTest extends DatabaseTestCase { /** diff --git a/Tests/Sqlsrv/SqlsrvStatementTest.php b/Tests/Sqlsrv/SqlsrvStatementTest.php index 07b449f1..0bda08f0 100644 --- a/Tests/Sqlsrv/SqlsrvStatementTest.php +++ b/Tests/Sqlsrv/SqlsrvStatementTest.php @@ -10,10 +10,12 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Sqlsrv\SqlsrvStatement; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Test class for Joomla\Database\Sqlsrv\SqlsrvStatement */ +#[RequiresPhpExtension('sqlsrv')] class SqlsrvStatementTest extends DatabaseTestCase { /** From e19c16ae849d86f0a702708b304835bd843b7217 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:50:16 +0200 Subject: [PATCH 2/9] use Stub instead of Mock with no configured expectations or call any() --- Tests/DatabaseAwareTraitTest.php | 2 +- Tests/DatabaseExporterTest.php | 9 ++--- Tests/DatabaseFactoryTest.php | 8 ++--- Tests/DatabaseImporterTest.php | 8 ++--- Tests/DatabaseIteratorTest.php | 7 ++-- Tests/DatabaseQueryTest.php | 52 ++++++++++++++++++----------- Tests/Mysql/MysqlExporterTest.php | 26 ++++++--------- Tests/Mysql/MysqlImporterTest.php | 35 ++++++++----------- Tests/Mysql/MysqlQueryTest.php | 12 +++---- Tests/Mysqli/MysqliExporterTest.php | 26 ++++++--------- Tests/Mysqli/MysqliImporterTest.php | 35 ++++++++----------- Tests/Mysqli/MysqliQueryTest.php | 12 +++---- Tests/Pgsql/PgsqlExporterTest.php | 29 ++++++---------- Tests/Pgsql/PgsqlImporterTest.php | 38 ++++++++------------- Tests/Pgsql/PgsqlQueryTest.php | 12 +++---- Tests/Sqlite/SqliteQueryTest.php | 12 +++---- Tests/Sqlsrv/SqlsrvQueryTest.php | 12 +++---- 17 files changed, 142 insertions(+), 193 deletions(-) diff --git a/Tests/DatabaseAwareTraitTest.php b/Tests/DatabaseAwareTraitTest.php index d69e8978..cbad1d65 100644 --- a/Tests/DatabaseAwareTraitTest.php +++ b/Tests/DatabaseAwareTraitTest.php @@ -30,7 +30,7 @@ class DatabaseAwareTraitTest extends TestCase */ public function testGetSetDatabase(): void { - $db = $this->createMock(DatabaseInterface::class); + $db = $this->createStub(DatabaseInterface::class); $trait = new class () { use DatabaseAwareTrait; diff --git a/Tests/DatabaseExporterTest.php b/Tests/DatabaseExporterTest.php index e2bb22a9..6952a927 100644 --- a/Tests/DatabaseExporterTest.php +++ b/Tests/DatabaseExporterTest.php @@ -7,14 +7,10 @@ namespace Joomla\Database\Tests; -use Joomla\Database\DatabaseExporter; -use Joomla\Database\DatabaseImporter; use Joomla\Database\DatabaseInterface; use Joomla\Database\Tests\Stubs\TestDatabaseExporter; -use Joomla\Database\Tests\Stubs\TestDatabaseImporter; use Joomla\Test\TestHelper; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -111,12 +107,11 @@ public function testFrom($from, bool $shouldRaiseException) } /** - * @testdox A database drier can be set to the exporter + * @testdox A database driver can be set to the exporter */ public function testSetDbo() { - /** @var DatabaseInterface|MockObject $db */ - $db = $this->createMock(DatabaseInterface::class); + $db = $this->createStub(DatabaseInterface::class); $this->assertSame($this->exporter, $this->exporter->setDbo($db), 'The exporter supports method chaining'); } diff --git a/Tests/DatabaseFactoryTest.php b/Tests/DatabaseFactoryTest.php index 4fbfd714..90018937 100644 --- a/Tests/DatabaseFactoryTest.php +++ b/Tests/DatabaseFactoryTest.php @@ -131,7 +131,7 @@ public function testGetExporter(string $adapter, bool $shouldRaiseException, boo $databaseDriver = null; if ($createDb) { - $databaseDriver = $this->createMock(MysqliDriver::class); + $databaseDriver = $this->createStub(MysqliDriver::class); } $exporter = $this->factory->getExporter($adapter, $databaseDriver); @@ -194,7 +194,7 @@ public function testGetImporter(string $adapter, bool $shouldRaiseException, boo $databaseDriver = null; if ($createDb) { - $databaseDriver = $this->createMock(MysqliDriver::class); + $databaseDriver = $this->createStub(MysqliDriver::class); } $importer = $this->factory->getImporter($adapter, $databaseDriver); @@ -239,7 +239,7 @@ public function testGetIterator(string $adapter, bool $createStatement) $statement = null; if ($createStatement) { - $statement = $this->createMock(StatementInterface::class); + $statement = $this->createStub(StatementInterface::class); } $this->assertInstanceOf( @@ -287,7 +287,7 @@ public function testGetQuery(string $adapter, bool $shouldRaiseException, bool $ $databaseDriver = null; if ($createDb) { - $databaseDriver = $this->createMock(MysqliDriver::class); + $databaseDriver = $this->createStub(MysqliDriver::class); } $this->assertInstanceOf( diff --git a/Tests/DatabaseImporterTest.php b/Tests/DatabaseImporterTest.php index c3e36916..aa808318 100644 --- a/Tests/DatabaseImporterTest.php +++ b/Tests/DatabaseImporterTest.php @@ -7,12 +7,9 @@ namespace Joomla\Database\Tests; -use Joomla\Database\DatabaseImporter; use Joomla\Database\DatabaseInterface; use Joomla\Database\Tests\Stubs\TestDatabaseImporter; -use Joomla\Database\Tests\Stubs\TestDatabaseQuery; use Joomla\Test\TestHelper; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -65,12 +62,11 @@ public function testAsXml() } /** - * @testdox A database drier can be set to the importer + * @testdox A database driver can be set to the importer */ public function testSetDbo() { - /** @var DatabaseInterface|MockObject $db */ - $db = $this->createMock(DatabaseInterface::class); + $db = $this->createStub(DatabaseInterface::class); $this->assertSame($this->importer, $this->importer->setDbo($db), 'The importer supports method chaining'); } diff --git a/Tests/DatabaseIteratorTest.php b/Tests/DatabaseIteratorTest.php index 80697e55..3c3bf815 100644 --- a/Tests/DatabaseIteratorTest.php +++ b/Tests/DatabaseIteratorTest.php @@ -10,6 +10,7 @@ use Joomla\Database\FetchMode; use Joomla\Database\StatementInterface; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -27,7 +28,7 @@ public function testInstantiation() $i = 0; - $statement->expects($this->any()) + $statement->expects($this->once()) ->method('fetch') ->willReturnCallback( function () use ($i) { @@ -229,8 +230,8 @@ public function testConstructorExceptionForNonExistingClass() { $this->expectException(\InvalidArgumentException::class); - /** @var StatementInterface|MockObject $statement */ - $statement = $this->createMock(StatementInterface::class); + /** @var StatementInterface|Stub $statement */ + $statement = $this->createStub(StatementInterface::class); $iterator = new DatabaseIterator($statement, null, \NonExistingClass::class); } diff --git a/Tests/DatabaseQueryTest.php b/Tests/DatabaseQueryTest.php index e29402af..bd47170b 100644 --- a/Tests/DatabaseQueryTest.php +++ b/Tests/DatabaseQueryTest.php @@ -13,7 +13,7 @@ use Joomla\Database\ParameterType; use Joomla\Database\Tests\Stubs\TestDatabaseQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -24,14 +24,14 @@ class DatabaseQueryTest extends TestCase /** * Object being tested * - * @var MockObject|DatabaseQuery + * @var DatabaseQuery */ private $query; /** * Mock database driver * - * @var MockObject|DatabaseInterface + * @var Stub|DatabaseInterface */ private $db; @@ -46,7 +46,7 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(DatabaseInterface::class); + $this->db = $this->createStub(DatabaseInterface::class); $this->query = new TestDatabaseQuery($this->db); } @@ -168,8 +168,7 @@ public static function dataConcatenate(): array #[DataProvider('dataConcatenate')] public function testConcatenate(array $values, ?string $separator, string $expected) { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); @@ -538,11 +537,14 @@ public static function dataNullDate(): array #[DataProvider('dataNullDate')] public function testNullDate(bool $quoted, string $expected) { - $this->db->expects($this->once()) + $db = $this->createMock(DatabaseInterface::class); + $query = new TestDatabaseQuery($db); + + $db->expects($this->once()) ->method('getNullDate') ->willReturn('0000-00-00 00:00:00'); - $this->db->expects($this->any()) + $db->expects($this->exactly((int) $quoted)) ->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; @@ -550,7 +552,7 @@ public function testNullDate(bool $quoted, string $expected) $this->assertSame( $expected, - $this->query->nullDate($quoted) + $query->nullDate($quoted) ); } @@ -582,7 +584,9 @@ public function testIsNullDatetimeNoDates() */ public function testIsNullDatetimeWithDates() { - $this->db->expects($this->any()) + $db = $this->createMock(DatabaseInterface::class); + + $db->expects($this->once()) ->method('quote') ->willReturnCallback(function ($text, $escape = true) { foreach ($text as $k => $v) { @@ -592,7 +596,7 @@ public function testIsNullDatetimeWithDates() return $text; }); - $query = new class ($this->db) extends DatabaseQuery { + $query = new class ($db) extends DatabaseQuery { protected $nullDatetimeList = ['0000-00-00 00:00:00', '1000-01-01 00:00:00']; public function groupConcat($expression, $separator = ',') @@ -643,7 +647,10 @@ public function testOrder() */ public function testQuote() { - $this->db->expects($this->any()) + $db = $this->createMock(DatabaseInterface::class); + $query = new TestDatabaseQuery($db); + + $db->expects($this->once()) ->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; @@ -651,7 +658,7 @@ public function testQuote() $this->assertSame( "'foo'", - $this->query->quote('foo') + $query->quote('foo') ); } @@ -672,7 +679,10 @@ public function testQuoteException() */ public function testQuoteName() { - $this->db->expects($this->any()) + $db = $this->createMock(DatabaseInterface::class); + $query = new TestDatabaseQuery($db); + + $db->expects($this->once()) ->method('quoteName') ->willReturnCallback(function ($text, $escape = true) { return "`" . $text . "`"; @@ -680,7 +690,7 @@ public function testQuoteName() $this->assertSame( "`foo`", - $this->query->quoteName('foo') + $query->quoteName('foo') ); } @@ -1255,13 +1265,15 @@ public function processLimit($query, $limit, $offset = 0) */ public function testCastingToStringInsertSet() { - $this->db->expects($this->any()) + $db = $this->createMock(DatabaseInterface::class); + + $db->expects($this->once()) ->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); - $query = new class ($this->db) extends DatabaseQuery { + $query = new class ($db) extends DatabaseQuery { public function groupConcat($expression, $separator = ',') { return ''; @@ -1289,13 +1301,15 @@ public function processLimit($query, $limit, $offset = 0) */ public function testCastingToStringInsertColumnsValues() { - $this->db->expects($this->any()) + $db = $this->createMock(DatabaseInterface::class); + + $db->expects($this->once()) ->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); - $query = new class ($this->db) extends DatabaseQuery { + $query = new class ($db) extends DatabaseQuery { public function groupConcat($expression, $separator = ',') { return ''; diff --git a/Tests/Mysql/MysqlExporterTest.php b/Tests/Mysql/MysqlExporterTest.php index f7c4488f..156540c3 100644 --- a/Tests/Mysql/MysqlExporterTest.php +++ b/Tests/Mysql/MysqlExporterTest.php @@ -11,7 +11,7 @@ use Joomla\Database\Mysql\MysqlExporter; use Joomla\Database\Mysql\MysqlQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -22,7 +22,7 @@ class MysqlExporterTest extends TestCase /** * Mock database driver * - * @var MockObject|MysqlDriver + * @var Stub|MysqlDriver */ private $db; @@ -37,20 +37,17 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(MysqlDriver::class); + $this->db = $this->createStub(MysqlDriver::class); - $this->db->expects($this->any()) - ->method('getPrefix') + $this->db->method('getPrefix') ->willReturn('jos_'); - $this->db->expects($this->any()) - ->method('createQuery') + $this->db->method('createQuery') ->willReturnCallback(function () { return new MysqlQuery($this->db); }); - $this->db->expects($this->any()) - ->method('getTableColumns') + $this->db->method('getTableColumns') ->willReturn( [ 'id' => (object) [ @@ -78,8 +75,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableKeys') + $this->db->method('getTableKeys') ->willReturn( [ (object) [ @@ -99,8 +95,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('quoteName') + $this->db->method('quoteName') ->willReturnCallback( function ($name, $as = null) { if (is_string($name)) { @@ -224,8 +219,7 @@ public function testCastingToString(bool $withStructure, bool $withData, string ->withData($withData); if ($withData) { - $this->db->expects($this->once()) - ->method('loadObjectList') + $this->db->method('loadObjectList') ->willReturn( [ (object) [ @@ -295,7 +289,7 @@ public function testCheck(?string $db, $from, ?string $exceptionMessage) $exporter = new MysqlExporter(); if ($db) { - $exporter->setDbo($this->createMock($db)); + $exporter->setDbo($this->createStub($db)); } if ($from) { diff --git a/Tests/Mysql/MysqlImporterTest.php b/Tests/Mysql/MysqlImporterTest.php index 512d4439..7f2484f9 100644 --- a/Tests/Mysql/MysqlImporterTest.php +++ b/Tests/Mysql/MysqlImporterTest.php @@ -11,7 +11,7 @@ use Joomla\Database\Mysql\MysqlImporter; use Joomla\Database\Mysql\MysqlQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -22,7 +22,7 @@ class MysqlImporterTest extends TestCase /** * Mock database driver * - * @var MockObject|MysqlDriver + * @var Stub|MysqlDriver */ private $db; @@ -63,20 +63,17 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(MysqlDriver::class); + $this->db = $this->createStub(MysqlDriver::class); - $this->db->expects($this->any()) - ->method('getPrefix') + $this->db->method('getPrefix') ->willReturn('jos_'); - $this->db->expects($this->any()) - ->method('createQuery') + $this->db->method('createQuery') ->willReturnCallback(function () { return new MysqlQuery($this->db); }); - $this->db->expects($this->any()) - ->method('getTableColumns') + $this->db->method('getTableColumns') ->willReturn( [ 'id' => (object) [ @@ -104,8 +101,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableKeys') + $this->db->method('getTableKeys') ->willReturn( [ (object) [ @@ -125,16 +121,14 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableList') + $this->db->method('getTableList') ->willReturn( [ 'jos_dbtest', ] ); - $this->db->expects($this->any()) - ->method('insertObject') + $this->db->method('insertObject') ->willReturnCallback( function ($table, &$object, $key = null) { if (!isset($this->executedInsertObjects[$table])) { @@ -147,8 +141,7 @@ function ($table, &$object, $key = null) { } ); - $this->db->expects($this->any()) - ->method('quoteName') + $this->db->method('quoteName') ->willReturnCallback( function ($name, $as = null) { if (is_string($name)) { @@ -165,8 +158,7 @@ function ($name, $as = null) { } ); - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback( function ($text, $escape = true) { if (is_string($text)) { @@ -183,8 +175,7 @@ function ($text, $escape = true) { } ); - $this->db->expects($this->any()) - ->method('setQuery') + $this->db->method('setQuery') ->willReturnCallback( function ($query, $offset = 0, $limit = 0) { $this->executedQueries[] = $query; @@ -383,7 +374,7 @@ public function testCheck(?string $db, $from, ?string $exceptionMessage) $importer = new MysqlImporter(); if ($db) { - $importer->setDbo($this->createMock($db)); + $importer->setDbo($this->createStub($db)); } if ($from) { diff --git a/Tests/Mysql/MysqlQueryTest.php b/Tests/Mysql/MysqlQueryTest.php index a9d96c62..752499fc 100644 --- a/Tests/Mysql/MysqlQueryTest.php +++ b/Tests/Mysql/MysqlQueryTest.php @@ -9,7 +9,7 @@ use Joomla\Database\DatabaseInterface; use Joomla\Database\Mysql\MysqlQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -27,7 +27,7 @@ class MysqlQueryTest extends TestCase /** * Mock database driver * - * @var MockObject|DatabaseInterface + * @var Stub|DatabaseInterface */ private $db; @@ -42,7 +42,7 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(DatabaseInterface::class); + $this->db = $this->createStub(DatabaseInterface::class); $this->query = new MysqlQuery($this->db); } @@ -69,8 +69,7 @@ public static function dataConcatenate(): array #[DataProvider('dataConcatenate')] public function testConcatenate(array $values, ?string $separator, string $expected) { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); @@ -97,8 +96,7 @@ public function testFindInSet() */ public function testGroupConcat() { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); diff --git a/Tests/Mysqli/MysqliExporterTest.php b/Tests/Mysqli/MysqliExporterTest.php index 9059f3fd..f0661cb6 100644 --- a/Tests/Mysqli/MysqliExporterTest.php +++ b/Tests/Mysqli/MysqliExporterTest.php @@ -11,7 +11,7 @@ use Joomla\Database\Mysqli\MysqliExporter; use Joomla\Database\Mysqli\MysqliQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -22,7 +22,7 @@ class MysqliExporterTest extends TestCase /** * Mock database driver * - * @var MockObject|MysqliDriver + * @var Stub|MysqliDriver */ private $db; @@ -37,20 +37,17 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(MysqliDriver::class); + $this->db = $this->createStub(MysqliDriver::class); - $this->db->expects($this->any()) - ->method('getPrefix') + $this->db->method('getPrefix') ->willReturn('jos_'); - $this->db->expects($this->any()) - ->method('createQuery') + $this->db->method('createQuery') ->willReturnCallback(function () { return new MysqliQuery($this->db); }); - $this->db->expects($this->any()) - ->method('getTableColumns') + $this->db->method('getTableColumns') ->willReturn( [ 'id' => (object) [ @@ -78,8 +75,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableKeys') + $this->db->method('getTableKeys') ->willReturn( [ (object) [ @@ -99,8 +95,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('quoteName') + $this->db->method('quoteName') ->willReturnCallback( function ($name, $as = null) { if (is_string($name)) { @@ -224,8 +219,7 @@ public function testCastingToString(bool $withStructure, bool $withData, string ->withData($withData); if ($withData) { - $this->db->expects($this->once()) - ->method('loadObjectList') + $this->db->method('loadObjectList') ->willReturn( [ (object) [ @@ -295,7 +289,7 @@ public function testCheck(?string $db, $from, ?string $exceptionMessage) $exporter = new MysqliExporter(); if ($db) { - $exporter->setDbo($this->createMock($db)); + $exporter->setDbo($this->createStub($db)); } if ($from) { diff --git a/Tests/Mysqli/MysqliImporterTest.php b/Tests/Mysqli/MysqliImporterTest.php index b60f457d..884358a6 100644 --- a/Tests/Mysqli/MysqliImporterTest.php +++ b/Tests/Mysqli/MysqliImporterTest.php @@ -11,7 +11,7 @@ use Joomla\Database\Mysqli\MysqliImporter; use Joomla\Database\Mysqli\MysqliQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -22,7 +22,7 @@ class MysqliImporterTest extends TestCase /** * Mock database driver * - * @var MockObject|MysqliDriver + * @var Stub|MysqliDriver */ private $db; @@ -63,20 +63,17 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(MysqliDriver::class); + $this->db = $this->createStub(MysqliDriver::class); - $this->db->expects($this->any()) - ->method('getPrefix') + $this->db->method('getPrefix') ->willReturn('jos_'); - $this->db->expects($this->any()) - ->method('createQuery') + $this->db->method('createQuery') ->willReturnCallback(function () { return new MysqliQuery($this->db); }); - $this->db->expects($this->any()) - ->method('getTableColumns') + $this->db->method('getTableColumns') ->willReturn( [ 'id' => (object) [ @@ -104,8 +101,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableKeys') + $this->db->method('getTableKeys') ->willReturn( [ (object) [ @@ -125,16 +121,14 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableList') + $this->db->method('getTableList') ->willReturn( [ 'jos_dbtest', ] ); - $this->db->expects($this->any()) - ->method('insertObject') + $this->db->method('insertObject') ->willReturnCallback( function ($table, &$object, $key = null) { if (!isset($this->executedInsertObjects[$table])) { @@ -147,8 +141,7 @@ function ($table, &$object, $key = null) { } ); - $this->db->expects($this->any()) - ->method('quoteName') + $this->db->method('quoteName') ->willReturnCallback( function ($name, $as = null) { if (is_string($name)) { @@ -165,8 +158,7 @@ function ($name, $as = null) { } ); - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback( function ($text, $escape = true) { if (is_string($text)) { @@ -183,8 +175,7 @@ function ($text, $escape = true) { } ); - $this->db->expects($this->any()) - ->method('setQuery') + $this->db->method('setQuery') ->willReturnCallback( function ($query, $offset = 0, $limit = 0) { $this->executedQueries[] = $query; @@ -383,7 +374,7 @@ public function testCheck(?string $db, $from, ?string $exceptionMessage) $importer = new MysqliImporter(); if ($db) { - $importer->setDbo($this->createMock($db)); + $importer->setDbo($this->createStub($db)); } if ($from) { diff --git a/Tests/Mysqli/MysqliQueryTest.php b/Tests/Mysqli/MysqliQueryTest.php index 6b5893fe..e13777f2 100644 --- a/Tests/Mysqli/MysqliQueryTest.php +++ b/Tests/Mysqli/MysqliQueryTest.php @@ -9,7 +9,7 @@ use Joomla\Database\DatabaseInterface; use Joomla\Database\Mysqli\MysqliQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -27,7 +27,7 @@ class MysqliQueryTest extends TestCase /** * Mock database driver * - * @var MockObject|DatabaseInterface + * @var Stub|DatabaseInterface */ private $db; @@ -42,7 +42,7 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(DatabaseInterface::class); + $this->db = $this->createStub(DatabaseInterface::class); $this->query = new MysqliQuery($this->db); } @@ -69,8 +69,7 @@ public static function dataConcatenate(): array #[DataProvider('dataConcatenate')] public function testConcatenate(array $values, ?string $separator, string $expected) { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); @@ -97,8 +96,7 @@ public function testFindInSet() */ public function testGroupConcat() { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); diff --git a/Tests/Pgsql/PgsqlExporterTest.php b/Tests/Pgsql/PgsqlExporterTest.php index 468b7269..e5903555 100644 --- a/Tests/Pgsql/PgsqlExporterTest.php +++ b/Tests/Pgsql/PgsqlExporterTest.php @@ -11,7 +11,7 @@ use Joomla\Database\Pgsql\PgsqlExporter; use Joomla\Database\Pgsql\PgsqlQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -22,7 +22,7 @@ class PgsqlExporterTest extends TestCase /** * Mock database driver * - * @var MockObject|PgsqlDriver + * @var Stub|PgsqlDriver */ private $db; @@ -37,20 +37,17 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(PgsqlDriver::class); + $this->db = $this->createStub(PgsqlDriver::class); - $this->db->expects($this->any()) - ->method('getPrefix') + $this->db->method('getPrefix') ->willReturn('jos_'); - $this->db->expects($this->any()) - ->method('createQuery') + $this->db->method('createQuery') ->willReturnCallback(function () { return new PgsqlQuery($this->db); }); - $this->db->expects($this->any()) - ->method('getTableColumns') + $this->db->method('getTableColumns') ->willReturn( [ 'id' => (object) [ @@ -88,8 +85,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableKeys') + $this->db->method('getTableKeys') ->willReturn( [ (object) [ @@ -102,8 +98,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableSequences') + $this->db->method('getTableSequences') ->willReturn( [ (object) [ @@ -121,8 +116,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('quoteName') + $this->db->method('quoteName') ->willReturnCallback( function ($name, $as = null) { if (is_string($name)) { @@ -252,8 +246,7 @@ public function testCastingToString(bool $withStructure, bool $withData, string ->withData($withData); if ($withData) { - $this->db->expects($this->once()) - ->method('loadObjectList') + $this->db->method('loadObjectList') ->willReturn( [ (object) [ @@ -323,7 +316,7 @@ public function testCheck(?string $db, $from, ?string $exceptionMessage) $exporter = new PgsqlExporter(); if ($db) { - $exporter->setDbo($this->createMock($db)); + $exporter->setDbo($this->createStub($db)); } if ($from) { diff --git a/Tests/Pgsql/PgsqlImporterTest.php b/Tests/Pgsql/PgsqlImporterTest.php index b25ba792..0449720e 100644 --- a/Tests/Pgsql/PgsqlImporterTest.php +++ b/Tests/Pgsql/PgsqlImporterTest.php @@ -11,7 +11,7 @@ use Joomla\Database\Pgsql\PgsqlImporter; use Joomla\Database\Pgsql\PgsqlQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -22,7 +22,7 @@ class PgsqlImporterTest extends TestCase /** * Mock database driver * - * @var MockObject|PgsqlDriver + * @var Stub|PgsqlDriver */ private $db; @@ -63,20 +63,17 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(PgsqlDriver::class); + $this->db = $this->createStub(PgsqlDriver::class); - $this->db->expects($this->any()) - ->method('getPrefix') + $this->db->method('getPrefix') ->willReturn('jos_'); - $this->db->expects($this->any()) - ->method('createQuery') + $this->db->method('createQuery') ->willReturnCallback(function () { return new PgsqlQuery($this->db); }); - $this->db->expects($this->any()) - ->method('getTableColumns') + $this->db->method('getTableColumns') ->willReturn( [ 'id' => (object) [ @@ -98,8 +95,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableKeys') + $this->db->method('getTableKeys') ->willReturn( [ (object) [ @@ -112,16 +108,14 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('getTableList') + $this->db->method('getTableList') ->willReturn( [ 'jos_dbtest', ] ); - $this->db->expects($this->any()) - ->method('getTableSequences') + $this->db->method('getTableSequences') ->willReturn( [ (object) [ @@ -139,8 +133,7 @@ protected function setUp(): void ] ); - $this->db->expects($this->any()) - ->method('insertObject') + $this->db->method('insertObject') ->willReturnCallback( function ($table, &$object, $key = null) { if (!isset($this->executedInsertObjects[$table])) { @@ -153,8 +146,7 @@ function ($table, &$object, $key = null) { } ); - $this->db->expects($this->any()) - ->method('quoteName') + $this->db->method('quoteName') ->willReturnCallback( function ($name, $as = null) { if (is_string($name)) { @@ -171,8 +163,7 @@ function ($name, $as = null) { } ); - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback( function ($text, $escape = true) { if (is_string($text)) { @@ -189,8 +180,7 @@ function ($text, $escape = true) { } ); - $this->db->expects($this->any()) - ->method('setQuery') + $this->db->method('setQuery') ->willReturnCallback( function ($query, $offset = 0, $limit = 0) { $this->executedQueries[] = $query; @@ -397,7 +387,7 @@ public function testCheck(?string $db, $from, ?string $exceptionMessage) $importer = new PgsqlImporter(); if ($db) { - $importer->setDbo($this->createMock($db)); + $importer->setDbo($this->createStub($db)); } if ($from) { diff --git a/Tests/Pgsql/PgsqlQueryTest.php b/Tests/Pgsql/PgsqlQueryTest.php index b04f63a6..13a070f3 100644 --- a/Tests/Pgsql/PgsqlQueryTest.php +++ b/Tests/Pgsql/PgsqlQueryTest.php @@ -9,7 +9,7 @@ use Joomla\Database\DatabaseInterface; use Joomla\Database\Pgsql\PgsqlQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -27,7 +27,7 @@ class PgsqlQueryTest extends TestCase /** * Mock database driver * - * @var MockObject|DatabaseInterface + * @var Stub|DatabaseInterface */ private $db; @@ -42,7 +42,7 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(DatabaseInterface::class); + $this->db = $this->createStub(DatabaseInterface::class); $this->query = new PgsqlQuery($this->db); } @@ -99,8 +99,7 @@ public static function dataConcatenate(): array #[DataProvider('dataConcatenate')] public function testConcatenate(array $values, ?string $separator, string $expected) { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); @@ -138,8 +137,7 @@ public function testFindInSet() */ public function testGroupConcat() { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); diff --git a/Tests/Sqlite/SqliteQueryTest.php b/Tests/Sqlite/SqliteQueryTest.php index 5a444d40..3d831d4b 100644 --- a/Tests/Sqlite/SqliteQueryTest.php +++ b/Tests/Sqlite/SqliteQueryTest.php @@ -9,7 +9,7 @@ use Joomla\Database\DatabaseInterface; use Joomla\Database\Sqlite\SqliteQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -27,7 +27,7 @@ class SqliteQueryTest extends TestCase /** * Mock database driver * - * @var MockObject|DatabaseInterface + * @var Stub|DatabaseInterface */ private $db; @@ -42,7 +42,7 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(DatabaseInterface::class); + $this->db = $this->createStub(DatabaseInterface::class); $this->query = new SqliteQuery($this->db); } @@ -99,8 +99,7 @@ public static function dataConcatenate(): array #[DataProvider('dataConcatenate')] public function testConcatenate(array $values, ?string $separator, string $expected) { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); @@ -116,8 +115,7 @@ public function testConcatenate(array $values, ?string $separator, string $expec */ public function testGroupConcat() { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); diff --git a/Tests/Sqlsrv/SqlsrvQueryTest.php b/Tests/Sqlsrv/SqlsrvQueryTest.php index cddd4283..0cecd82d 100644 --- a/Tests/Sqlsrv/SqlsrvQueryTest.php +++ b/Tests/Sqlsrv/SqlsrvQueryTest.php @@ -9,7 +9,7 @@ use Joomla\Database\DatabaseInterface; use Joomla\Database\Sqlsrv\SqlsrvQuery; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; /** @@ -27,7 +27,7 @@ class SqlsrvQueryTest extends TestCase /** * Mock database driver * - * @var MockObject|DatabaseInterface + * @var Stub|DatabaseInterface */ private $db; @@ -42,7 +42,7 @@ protected function setUp(): void { parent::setUp(); - $this->db = $this->createMock(DatabaseInterface::class); + $this->db = $this->createStub(DatabaseInterface::class); $this->query = new SqlsrvQuery($this->db); } @@ -129,8 +129,7 @@ public static function dataConcatenate(): array #[DataProvider('dataConcatenate')] public function testConcatenate(array $values, ?string $separator, string $expected) { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); @@ -179,8 +178,7 @@ public function testFindInSet() */ public function testGroupConcat() { - $this->db->expects($this->any()) - ->method('quote') + $this->db->method('quote') ->willReturnCallback(function ($text, $escape = true) { return "'" . $text . "'"; }); From 0e8e84a564b5a2908e6c8ae3d4971fd900bc7b97 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:50:34 +0200 Subject: [PATCH 3/9] replace DoesNotPerformAssertions attribute --- Tests/Mysql/MysqlPreparedStatementTest.php | 7 +++---- Tests/Mysqli/MysqliPreparedStatementTest.php | 7 +++---- Tests/Mysqli/MysqliStatementTest.php | 10 ++++------ Tests/Pgsql/PgsqlPreparedStatementTest.php | 7 +++---- Tests/Sqlite/SqlitePreparedStatementTest.php | 7 +++---- Tests/Sqlsrv/SqlsrvPreparedStatementTest.php | 7 +++---- Tests/Sqlsrv/SqlsrvStatementTest.php | 16 +++++++--------- 7 files changed, 26 insertions(+), 35 deletions(-) diff --git a/Tests/Mysql/MysqlPreparedStatementTest.php b/Tests/Mysql/MysqlPreparedStatementTest.php index ce7213e9..fa7a54ef 100644 --- a/Tests/Mysql/MysqlPreparedStatementTest.php +++ b/Tests/Mysql/MysqlPreparedStatementTest.php @@ -9,6 +9,7 @@ use Joomla\Database\DatabaseDriver; use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('pdo_mysql')] @@ -68,9 +69,8 @@ protected function tearDown(): void /** * Make sure the mysqli driver correctly runs queries with named parameters appearing more than once. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithDuplicateKey() { $dummyValue = 'test'; @@ -88,9 +88,8 @@ public function testPreparedStatementWithDuplicateKey() /** * Regression test to ensure running queries with named parameters appearing once didn't break. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithSingleKey() { $dummyValue = 'test'; diff --git a/Tests/Mysqli/MysqliPreparedStatementTest.php b/Tests/Mysqli/MysqliPreparedStatementTest.php index 446e71d1..56b6a9ab 100644 --- a/Tests/Mysqli/MysqliPreparedStatementTest.php +++ b/Tests/Mysqli/MysqliPreparedStatementTest.php @@ -10,6 +10,7 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Mysqli\MysqliStatement; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('mysqli')] @@ -135,9 +136,8 @@ public function testPrepareParameterKeyMappingWithSingleKey() /** * Make sure the mysqli driver correctly runs queries with named parameters appearing more than once. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithDuplicateKey() { $statement = 'SELECT * FROM dbtest WHERE `title` LIKE :search OR `description` LIKE :search'; @@ -150,9 +150,8 @@ public function testPreparedStatementWithDuplicateKey() /** * Regression test to ensure running queries with named parameters appearing once didn't break. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithSingleKey() { $statement = 'SELECT * FROM dbtest WHERE `title` LIKE :search OR `description` LIKE :search2'; diff --git a/Tests/Mysqli/MysqliStatementTest.php b/Tests/Mysqli/MysqliStatementTest.php index 20eed94d..185c47e8 100644 --- a/Tests/Mysqli/MysqliStatementTest.php +++ b/Tests/Mysqli/MysqliStatementTest.php @@ -10,6 +10,7 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Mysqli\MysqliStatement; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** @@ -72,9 +73,8 @@ protected function tearDown(): void /** * Regression test to ensure that named values with matching named params are correctly prepared, this simulates a whereIn condition. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testStatementPreparesManyArrayValues() { $query = 'SELECT * FROM dbtest WHERE id IN (:preparedArray1,:preparedArray2,:preparedArray3,:preparedArray4,:preparedArray5,:preparedArray6,:preparedArray7,:preparedArray8,:preparedArray9,:preparedArray10)'; @@ -84,9 +84,8 @@ public function testStatementPreparesManyArrayValues() /** * Regression test to ensure that named values with matching named params are correctly prepared (part 2), this simulates a general use case. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testStatementWithKeysMatching() { $query = 'SELECT * FROM dbtest WHERE `id` = :id AND `title` = :id_title'; @@ -97,9 +96,8 @@ public function testStatementWithKeysMatching() /** * Regression test to ensure that named values with matching named params are correctly prepared (part 3). * This simulates a general use case for a search function where we reuse the same prepared statement term. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testStatementWithMultipleUseOfVars() { $query = 'SELECT * FROM `dbtest` WHERE `description` LIKE :search_term AND `title` LIKE :search_term'; diff --git a/Tests/Pgsql/PgsqlPreparedStatementTest.php b/Tests/Pgsql/PgsqlPreparedStatementTest.php index 10dd392f..169bccc2 100644 --- a/Tests/Pgsql/PgsqlPreparedStatementTest.php +++ b/Tests/Pgsql/PgsqlPreparedStatementTest.php @@ -9,6 +9,7 @@ use Joomla\Database\DatabaseDriver; use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** @@ -71,9 +72,8 @@ protected function tearDown(): void /** * Make sure the mysqli driver correctly runs queries with named parameters appearing more than once. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithDuplicateKey() { $dummyValue = 'test'; @@ -91,9 +91,8 @@ public function testPreparedStatementWithDuplicateKey() /** * Regression test to ensure running queries with named parameters appearing once didn't break. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithSingleKey() { $dummyValue = 'test'; diff --git a/Tests/Sqlite/SqlitePreparedStatementTest.php b/Tests/Sqlite/SqlitePreparedStatementTest.php index 5201c93a..ebaf8fa4 100644 --- a/Tests/Sqlite/SqlitePreparedStatementTest.php +++ b/Tests/Sqlite/SqlitePreparedStatementTest.php @@ -9,6 +9,7 @@ use Joomla\Database\DatabaseDriver; use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('pdo_sqlite')] @@ -79,9 +80,8 @@ function (string $table): bool { /** * Make sure the mysqli driver correctly runs queries with named parameters appearing more than once. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithDuplicateKey() { $dummyValue = 'test'; @@ -99,9 +99,8 @@ public function testPreparedStatementWithDuplicateKey() /** * Regression test to ensure running queries with named parameters appearing once didn't break. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithSingleKey() { $dummyValue = 'test'; diff --git a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php index 48c60546..77aa5d16 100644 --- a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php +++ b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php @@ -10,6 +10,7 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Sqlsrv\SqlsrvStatement; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** @@ -129,9 +130,8 @@ public function testPrepareParameterKeyMappingWithSingleKey() /** * Make sure the mysqli driver correctly runs queries with named parameters appearing more than once. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithDuplicateKey() { $dummyValue = 'test'; @@ -149,9 +149,8 @@ public function testPreparedStatementWithDuplicateKey() /** * Regression test to ensure running queries with named parameters appearing once didn't break. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testPreparedStatementWithSingleKey() { $dummyValue = 'test'; diff --git a/Tests/Sqlsrv/SqlsrvStatementTest.php b/Tests/Sqlsrv/SqlsrvStatementTest.php index 0bda08f0..121ad376 100644 --- a/Tests/Sqlsrv/SqlsrvStatementTest.php +++ b/Tests/Sqlsrv/SqlsrvStatementTest.php @@ -10,6 +10,7 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Sqlsrv\SqlsrvStatement; use Joomla\Test\DatabaseTestCase; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** @@ -72,9 +73,8 @@ protected function tearDown(): void /** * Regression test to ensure that named values with matching named params are correctly prepared, this simulates a whereIn condition. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testStatementPreparesManyArrayValues() { $query = 'SELECT * FROM dbtest WHERE id IN (:preparedArray1,:preparedArray2,:preparedArray3,:preparedArray4,:preparedArray5,:preparedArray6,:preparedArray7,:preparedArray8,:preparedArray9,:preparedArray10)'; @@ -84,9 +84,8 @@ public function testStatementPreparesManyArrayValues() /** * Regression test to ensure that named values with matching named params are correctly prepared (part 2), this simulates a general use case. - * - * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testStatementWithKeysMatching() { $query = 'SELECT * FROM dbtest WHERE id = :id AND title = :id_title'; @@ -95,11 +94,10 @@ public function testStatementWithKeysMatching() } /** - * Regression test to ensure that named values with matching named params are correctly prepared (part 3). - * This simulates a general use case for a search function where we reuse the same prepared statement term. - * -* @doesNotPerformAssertions - */ + * Regression test to ensure that named values with matching named params are correctly prepared (part 3). + * This simulates a general use case for a search function where we reuse the same prepared statement term. + */ + #[DoesNotPerformAssertions] public function testStatementWithMultipleUseOfVars() { $query = 'SELECT * FROM dbtest WHERE description LIKE :search_term AND title LIKE :search_term'; From 5d1ba4e72dd77615e616d0835eae0b783b6f9bc0 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:51:03 +0200 Subject: [PATCH 4/9] remove check connection driver --- Tests/Mysql/MysqlDriverTest.php | 2 +- Tests/Mysql/MysqlPreparedStatementTest.php | 2 +- Tests/Mysqli/MysqliDriverTest.php | 2 +- Tests/Mysqli/MysqliPreparedStatementTest.php | 2 +- Tests/Mysqli/MysqliStatementTest.php | 2 +- Tests/Pgsql/PgsqlDriverTest.php | 2 +- Tests/Pgsql/PgsqlPreparedStatementTest.php | 2 +- Tests/Sqlsrv/SqlsrvDriverTest.php | 2 +- Tests/Sqlsrv/SqlsrvPreparedStatementTest.php | 2 +- Tests/Sqlsrv/SqlsrvStatementTest.php | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Tests/Mysql/MysqlDriverTest.php b/Tests/Mysql/MysqlDriverTest.php index 172854aa..61d3ae5f 100644 --- a/Tests/Mysql/MysqlDriverTest.php +++ b/Tests/Mysql/MysqlDriverTest.php @@ -43,7 +43,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'mysql') { + if (!static::$connection) { self::markTestSkipped('MySQL database not configured.'); } } diff --git a/Tests/Mysql/MysqlPreparedStatementTest.php b/Tests/Mysql/MysqlPreparedStatementTest.php index fa7a54ef..62eaaa0c 100644 --- a/Tests/Mysql/MysqlPreparedStatementTest.php +++ b/Tests/Mysql/MysqlPreparedStatementTest.php @@ -24,7 +24,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'mysql') { + if (!static::$connection) { self::markTestSkipped('MySQL database not configured.'); } } diff --git a/Tests/Mysqli/MysqliDriverTest.php b/Tests/Mysqli/MysqliDriverTest.php index 71d20bc0..e41615b8 100644 --- a/Tests/Mysqli/MysqliDriverTest.php +++ b/Tests/Mysqli/MysqliDriverTest.php @@ -48,7 +48,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'mysqli') { + if (!static::$connection) { self::markTestSkipped('MySQL database not configured.'); } } diff --git a/Tests/Mysqli/MysqliPreparedStatementTest.php b/Tests/Mysqli/MysqliPreparedStatementTest.php index 56b6a9ab..b78cd85d 100644 --- a/Tests/Mysqli/MysqliPreparedStatementTest.php +++ b/Tests/Mysqli/MysqliPreparedStatementTest.php @@ -25,7 +25,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'mysqli') { + if (!static::$connection) { self::markTestSkipped('MySQL database not configured.'); } } diff --git a/Tests/Mysqli/MysqliStatementTest.php b/Tests/Mysqli/MysqliStatementTest.php index 185c47e8..6f697498 100644 --- a/Tests/Mysqli/MysqliStatementTest.php +++ b/Tests/Mysqli/MysqliStatementTest.php @@ -28,7 +28,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'mysqli') { + if (!static::$connection) { self::markTestSkipped('MySQL database not configured.'); } } diff --git a/Tests/Pgsql/PgsqlDriverTest.php b/Tests/Pgsql/PgsqlDriverTest.php index 81ab2b8b..2228c667 100644 --- a/Tests/Pgsql/PgsqlDriverTest.php +++ b/Tests/Pgsql/PgsqlDriverTest.php @@ -33,7 +33,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'pgsql') { + if (!static::$connection) { self::markTestSkipped('PostgreSQL database not configured.'); } } diff --git a/Tests/Pgsql/PgsqlPreparedStatementTest.php b/Tests/Pgsql/PgsqlPreparedStatementTest.php index 169bccc2..a7533858 100644 --- a/Tests/Pgsql/PgsqlPreparedStatementTest.php +++ b/Tests/Pgsql/PgsqlPreparedStatementTest.php @@ -27,7 +27,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'pgsql') { + if (!static::$connection) { self::markTestSkipped('PostgreSQL database not configured.'); } } diff --git a/Tests/Sqlsrv/SqlsrvDriverTest.php b/Tests/Sqlsrv/SqlsrvDriverTest.php index 99bb9769..a74891ee 100644 --- a/Tests/Sqlsrv/SqlsrvDriverTest.php +++ b/Tests/Sqlsrv/SqlsrvDriverTest.php @@ -33,7 +33,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'sqlsrv') { + if (!static::$connection) { self::markTestSkipped('SQL Server database not configured.'); } } diff --git a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php index 77aa5d16..4bb88632 100644 --- a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php +++ b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php @@ -28,7 +28,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'sqlsrv') { + if (!static::$connection) { self::markTestSkipped('SQL Server database not configured.'); } } diff --git a/Tests/Sqlsrv/SqlsrvStatementTest.php b/Tests/Sqlsrv/SqlsrvStatementTest.php index 121ad376..c8cf1088 100644 --- a/Tests/Sqlsrv/SqlsrvStatementTest.php +++ b/Tests/Sqlsrv/SqlsrvStatementTest.php @@ -28,7 +28,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - if (!static::$connection || static::$connection->getName() !== 'sqlsrv') { + if (!static::$connection) { self::markTestSkipped('SQL Server database not configured.'); } } From 2f60db616f32a95b9480f0d949760da2011dfec5 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:51:33 +0200 Subject: [PATCH 5/9] connection is not available in dataprovider --- Tests/Mysql/MysqlDriverTest.php | 60 ++++++++++++++++++++++--------- Tests/Mysqli/MysqliDriverTest.php | 58 +++++++++++++++++++++--------- 2 files changed, 86 insertions(+), 32 deletions(-) diff --git a/Tests/Mysql/MysqlDriverTest.php b/Tests/Mysql/MysqlDriverTest.php index 61d3ae5f..26525e4b 100644 --- a/Tests/Mysql/MysqlDriverTest.php +++ b/Tests/Mysql/MysqlDriverTest.php @@ -98,14 +98,6 @@ protected function tearDown(): void */ public static function dataGetTableColumns(): array { - // For unknown reasons, the connection gets lost on Travis. re-establish, if that happens - if (static::$connection === null) { - self::setUpBeforeClass(); - } - - $isMySQL8 = !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0', '>='); - $useDisplayWidth = static::$connection->isMariaDb() || version_compare(static::$connection->getVersion(), '8.0.17', '<'); - return [ 'only column types' => [ '#__dbtest', @@ -125,11 +117,11 @@ public static function dataGetTableColumns(): array [ 'id' => (object) [ 'Field' => 'id', - 'Type' => $useDisplayWidth ? 'int(10) unsigned' : 'int unsigned', - 'Collation' => $isMySQL8 ? null : '', + 'Type' => '<<>>', + 'Collation' => null, 'Null' => 'NO', 'Key' => 'PRI', - 'Default' => $isMySQL8 ? null : '', + 'Default' => null, 'Extra' => 'auto_increment', 'Privileges' => 'select,insert,update,references', 'Comment' => '', @@ -137,10 +129,10 @@ public static function dataGetTableColumns(): array 'title' => (object) [ 'Field' => 'title', 'Type' => 'varchar(50)', - 'Collation' => $isMySQL8 ? 'utf8mb3_general_ci' : 'utf8_general_ci', + 'Collation' => '<<>>', 'Null' => 'NO', 'Key' => '', - 'Default' => $isMySQL8 ? null : '', + 'Default' => '<<>>', 'Extra' => '', 'Privileges' => 'select,insert,update,references', 'Comment' => '', @@ -159,10 +151,10 @@ public static function dataGetTableColumns(): array 'description' => (object) [ 'Field' => 'description', 'Type' => 'text', - 'Collation' => $isMySQL8 ? 'utf8mb3_general_ci' : 'utf8_general_ci', + 'Collation' => '<<>>', 'Null' => 'NO', 'Key' => '', - 'Default' => $isMySQL8 ? null : '', + 'Default' => '<<>>', 'Extra' => '', 'Privileges' => 'select,insert,update,references', 'Comment' => '', @@ -244,6 +236,40 @@ public static function dataQuoteName(): array * Overrides for parent class test cases */ + /** + * @testdox Information about the columns of a database table is returned + * + * @param string $table The name of the database table. + * @param boolean $typeOnly True (default) to only return field types. + * @param array $expected Expected result. + */ + #[DataProvider('dataGetTableColumns')] + public function testGetTableColumns(string $table, bool $typeOnly, array $expected) + { + if (!$typeOnly) { + $isMySQL8 = !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0', '>='); + $useDisplayWidth = static::$connection->isMariaDb() || version_compare(static::$connection->getVersion(), '8.0.17', '<'); + + $collationText = match (true) { + !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0.30', '>=') => 'utf8mb3_general_ci', + default => 'utf8_general_ci', + }; + + $defaultText = match (true) { + !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0', '>=') => null, + default => '', + }; + + $expected['id']->Type = $useDisplayWidth ? 'int(10) unsigned' : 'int unsigned'; + $expected['title']->Collation = $collationText; + $expected['title']->Default = $defaultText; + $expected['description']->Collation = $collationText; + $expected['description']->Default = $defaultText; + } + + parent::testGetTableColumns($table, $typeOnly, $expected); + } + /* * Test cases for this subclass */ @@ -325,7 +351,9 @@ public function testGetTableKeys() // MySQL 8.0 adds additional data if (!static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0', '>=')) { $dbtestPrimaryKey['Visible'] = 'YES'; - $dbtestPrimaryKey['Expression'] = null; + if (version_compare(static::$connection->getVersion(), '8.0.13', '>=')) { + $dbtestPrimaryKey['Expression'] = null; + } } $keys = [ diff --git a/Tests/Mysqli/MysqliDriverTest.php b/Tests/Mysqli/MysqliDriverTest.php index e41615b8..d408b31a 100644 --- a/Tests/Mysqli/MysqliDriverTest.php +++ b/Tests/Mysqli/MysqliDriverTest.php @@ -117,14 +117,6 @@ public static function dataEscape(): array */ public static function dataGetTableColumns(): array { - // For unknown reasons, the connection gets lost on Travis. re-establish, if that happens - if (static::$connection === null) { - self::setUpBeforeClass(); - } - - $isMySQL8 = !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0', '>='); - $useDisplayWidth = static::$connection->isMariaDb() || version_compare(static::$connection->getVersion(), '8.0.17', '<'); - return [ 'only column types' => [ '#__dbtest', @@ -144,11 +136,11 @@ public static function dataGetTableColumns(): array [ 'id' => (object) [ 'Field' => 'id', - 'Type' => $useDisplayWidth ? 'int(10) unsigned' : 'int unsigned', - 'Collation' => $isMySQL8 ? null : '', + 'Type' => '<<>>', + 'Collation' => null, 'Null' => 'NO', 'Key' => 'PRI', - 'Default' => $isMySQL8 ? null : '', + 'Default' => null, 'Extra' => 'auto_increment', 'Privileges' => 'select,insert,update,references', 'Comment' => '', @@ -156,10 +148,10 @@ public static function dataGetTableColumns(): array 'title' => (object) [ 'Field' => 'title', 'Type' => 'varchar(50)', - 'Collation' => $isMySQL8 ? 'utf8mb3_general_ci' : 'utf8_general_ci', + 'Collation' => '<<>>', 'Null' => 'NO', 'Key' => '', - 'Default' => $isMySQL8 ? null : '', + 'Default' => '<<>>', 'Extra' => '', 'Privileges' => 'select,insert,update,references', 'Comment' => '', @@ -178,10 +170,10 @@ public static function dataGetTableColumns(): array 'description' => (object) [ 'Field' => 'description', 'Type' => 'text', - 'Collation' => $isMySQL8 ? 'utf8mb3_general_ci' : 'utf8_general_ci', + 'Collation' => '<<>>', 'Null' => 'NO', 'Key' => '', - 'Default' => $isMySQL8 ? null : '', + 'Default' => '<<>>', 'Extra' => '', 'Privileges' => 'select,insert,update,references', 'Comment' => '', @@ -248,6 +240,39 @@ public static function dataQuoteName(): array * Overrides for parent class test cases */ + /** + * @testdox Information about the columns of a database table is returned + * + * @param string $table The name of the database table. + * @param boolean $typeOnly True (default) to only return field types. + * @param array $expected Expected result. + */ + #[DataProvider('dataGetTableColumns')] + public function testGetTableColumns(string $table, bool $typeOnly, array $expected) + { + if (!$typeOnly) { + $useDisplayWidth = static::$connection->isMariaDb() || version_compare(static::$connection->getVersion(), '8.0.17', '<'); + + $collationText = match (true) { + !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0.30', '>=') => 'utf8mb3_general_ci', + default => 'utf8_general_ci', + }; + + $defaultText = match (true) { + !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0', '>=') => null, + default => '', + }; + + $expected['id']->Type = $useDisplayWidth ? 'int(10) unsigned' : 'int unsigned'; + $expected['title']->Collation = $collationText; + $expected['title']->Default = $defaultText; + $expected['description']->Collation = $collationText; + $expected['description']->Default = $defaultText; + } + + parent::testGetTableColumns($table, $typeOnly, $expected); + } + /* * Test cases for this subclass */ @@ -333,7 +358,8 @@ public function testGetTableKeys() $dbtestPrimaryKey['Cardinality'] = (int) $dbtestPrimaryKey['Cardinality']; $dbtestPrimaryKey['Visible'] = 'YES'; - $dbtestPrimaryKey['Expression'] = null; + if (version_compare(static::$connection->getVersion(), '8.0.13', '>=')) { + $dbtestPrimaryKey['Expression'] = null; } $keys = [ From 720a2ded5a26a1c22342f052552b8dfc2eac1ea5 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:51:50 +0200 Subject: [PATCH 6/9] updates for new mariadb versions --- Tests/Mysql/MysqlDriverTest.php | 17 ++++++++++++++++- Tests/Mysqli/MysqliDriverTest.php | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Tests/Mysql/MysqlDriverTest.php b/Tests/Mysql/MysqlDriverTest.php index 26525e4b..bce51d73 100644 --- a/Tests/Mysql/MysqlDriverTest.php +++ b/Tests/Mysql/MysqlDriverTest.php @@ -252,11 +252,14 @@ public function testGetTableColumns(string $table, bool $typeOnly, array $expect $collationText = match (true) { !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0.30', '>=') => 'utf8mb3_general_ci', + static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '11.5', '>=') => 'utf8mb3_uca1400_ai_ci', + static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '10.6', '>=') => 'utf8mb3_general_ci', default => 'utf8_general_ci', }; $defaultText = match (true) { !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0', '>=') => null, + static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '11.5', '>=') => null, default => '', }; @@ -348,12 +351,24 @@ public function testGetTableKeys() 'Index_comment' => '', ]; - // MySQL 8.0 adds additional data + // MySQL 8.0 adds additional data and casts certain keys to integers if (!static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0', '>=')) { + $dbtestPrimaryKey['Non_unique'] = (int) $dbtestPrimaryKey['Non_unique']; + $dbtestPrimaryKey['Seq_in_index'] = (int) $dbtestPrimaryKey['Seq_in_index']; + $dbtestPrimaryKey['Cardinality'] = (int) $dbtestPrimaryKey['Cardinality']; + $dbtestPrimaryKey['Visible'] = 'YES'; if (version_compare(static::$connection->getVersion(), '8.0.13', '>=')) { $dbtestPrimaryKey['Expression'] = null; } + + // MariaDB 10.6 adds additional data and casts certain keys to integers + } elseif (static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '10.6', '>=')) { + $dbtestPrimaryKey['Non_unique'] = (int) $dbtestPrimaryKey['Non_unique']; + $dbtestPrimaryKey['Seq_in_index'] = (int) $dbtestPrimaryKey['Seq_in_index']; + $dbtestPrimaryKey['Cardinality'] = (int) $dbtestPrimaryKey['Cardinality']; + + $dbtestPrimaryKey['Ignored'] = 'NO'; } $keys = [ diff --git a/Tests/Mysqli/MysqliDriverTest.php b/Tests/Mysqli/MysqliDriverTest.php index d408b31a..206987b1 100644 --- a/Tests/Mysqli/MysqliDriverTest.php +++ b/Tests/Mysqli/MysqliDriverTest.php @@ -255,11 +255,14 @@ public function testGetTableColumns(string $table, bool $typeOnly, array $expect $collationText = match (true) { !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0.30', '>=') => 'utf8mb3_general_ci', + static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '11.5', '>=') => 'utf8mb3_uca1400_ai_ci', + static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '10.6', '>=') => 'utf8mb3_general_ci', default => 'utf8_general_ci', }; $defaultText = match (true) { !static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '8.0', '>=') => null, + static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '11.5', '>=') => null, default => '', }; @@ -360,6 +363,15 @@ public function testGetTableKeys() $dbtestPrimaryKey['Visible'] = 'YES'; if (version_compare(static::$connection->getVersion(), '8.0.13', '>=')) { $dbtestPrimaryKey['Expression'] = null; + } + + // MariaDB 10.6 adds additional data and casts certain keys to integers + } elseif (static::$connection->isMariaDb() && version_compare(static::$connection->getVersion(), '10.6', '>=')) { + $dbtestPrimaryKey['Non_unique'] = (int) $dbtestPrimaryKey['Non_unique']; + $dbtestPrimaryKey['Seq_in_index'] = (int) $dbtestPrimaryKey['Seq_in_index']; + $dbtestPrimaryKey['Cardinality'] = (int) $dbtestPrimaryKey['Cardinality']; + + $dbtestPrimaryKey['Ignored'] = 'NO'; } $keys = [ From 9a7c908f1f291ca6154cf2e3dc6f0036c5e5180b Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:52:06 +0200 Subject: [PATCH 7/9] remove travis code --- Tests/Pgsql/PgsqlDriverTest.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Tests/Pgsql/PgsqlDriverTest.php b/Tests/Pgsql/PgsqlDriverTest.php index 2228c667..66e1f777 100644 --- a/Tests/Pgsql/PgsqlDriverTest.php +++ b/Tests/Pgsql/PgsqlDriverTest.php @@ -326,14 +326,7 @@ public function testGetConnectionCollation() */ public function testGetConnectionEncryption() { - $expectedResult = ''; - - if (\getenv('TRAVIS') === 'true' && in_array(\getenv('PGSQL_VERSION'), ['9.5', '9.6', '10.0'])) { - $expectedResult = 'TLSv1.2 (ECDHE-RSA-AES256-GCM-SHA384)'; - } - - $this->assertSame( - $expectedResult, + $this->assertEmpty( static::$connection->getConnectionEncryption(), 'The database connection is not encrypted by default' ); From b5125b663c32009ebc7dda0fab425992bdfbc29e Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:52:26 +0200 Subject: [PATCH 8/9] php8.2: Creation of dynamic property is deprecated --- Tests/Mysql/MysqlImporterTest.php | 2 +- Tests/Mysqli/MysqliImporterTest.php | 2 +- Tests/Pgsql/PgsqlImporterTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Mysql/MysqlImporterTest.php b/Tests/Mysql/MysqlImporterTest.php index 7f2484f9..1e219b0e 100644 --- a/Tests/Mysql/MysqlImporterTest.php +++ b/Tests/Mysql/MysqlImporterTest.php @@ -190,7 +190,7 @@ function ($query, $offset = 0, $limit = 0) { */ protected function tearDown(): void { - $this->expectedInsertObjects = []; + $this->executedInsertObjects = []; $this->executedQueries = []; } diff --git a/Tests/Mysqli/MysqliImporterTest.php b/Tests/Mysqli/MysqliImporterTest.php index 884358a6..88f966dd 100644 --- a/Tests/Mysqli/MysqliImporterTest.php +++ b/Tests/Mysqli/MysqliImporterTest.php @@ -190,7 +190,7 @@ function ($query, $offset = 0, $limit = 0) { */ protected function tearDown(): void { - $this->expectedInsertObjects = []; + $this->executedInsertObjects = []; $this->executedQueries = []; } diff --git a/Tests/Pgsql/PgsqlImporterTest.php b/Tests/Pgsql/PgsqlImporterTest.php index 0449720e..f94cc2dd 100644 --- a/Tests/Pgsql/PgsqlImporterTest.php +++ b/Tests/Pgsql/PgsqlImporterTest.php @@ -195,7 +195,7 @@ function ($query, $offset = 0, $limit = 0) { */ protected function tearDown(): void { - $this->expectedInsertObjects = []; + $this->executedInsertObjects = []; $this->executedQueries = []; } From 3aa7165212e4822ff047fcc0aab7c520da0ea08e Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:52:45 +0200 Subject: [PATCH 9/9] php 8.5: Method Reflection*::setAccessible() is deprecated --- Tests/Mysqli/MysqliPreparedStatementTest.php | 17 +++-------------- Tests/Sqlsrv/SqlsrvPreparedStatementTest.php | 17 +++-------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/Tests/Mysqli/MysqliPreparedStatementTest.php b/Tests/Mysqli/MysqliPreparedStatementTest.php index b78cd85d..5d916df8 100644 --- a/Tests/Mysqli/MysqliPreparedStatementTest.php +++ b/Tests/Mysqli/MysqliPreparedStatementTest.php @@ -10,6 +10,7 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Mysqli\MysqliStatement; use Joomla\Test\DatabaseTestCase; +use Joomla\Test\TestHelper; use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\RequiresPhpExtension; @@ -91,17 +92,11 @@ public function testPrepareParameterKeyMappingWithDuplicateKey() $rawQuery ); - $refObject = new \ReflectionObject($mysqliStatementObject); - $refMapping = $refObject->getProperty('parameterKeyMapping'); - /** @noinspection PhpExpressionResultUnusedInspection */ - $refMapping->setAccessible(true); - $parameterKeyMapping = $refMapping->getValue($mysqliStatementObject); - $this->assertEquals( [ ':search' => [0, 1], ], - $parameterKeyMapping + TestHelper::getValue($mysqliStatementObject, 'parameterKeyMapping') ); } @@ -119,18 +114,12 @@ public function testPrepareParameterKeyMappingWithSingleKey() $rawQuery ); - $refObject = new \ReflectionObject($mysqliStatementObject); - $refMapping = $refObject->getProperty('parameterKeyMapping'); - /** @noinspection PhpExpressionResultUnusedInspection */ - $refMapping->setAccessible(true); - $parameterKeyMapping = $refMapping->getValue($mysqliStatementObject); - $this->assertEquals( [ ':search' => [0], ':search2' => [1], ], - $parameterKeyMapping + TestHelper::getValue($mysqliStatementObject, 'parameterKeyMapping') ); } diff --git a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php index 4bb88632..331086ac 100644 --- a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php +++ b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php @@ -10,6 +10,7 @@ use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\Sqlsrv\SqlsrvStatement; use Joomla\Test\DatabaseTestCase; +use Joomla\Test\TestHelper; use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\RequiresPhpExtension; @@ -85,17 +86,11 @@ public function testPrepareParameterKeyMappingWithDuplicateKey() $rawQuery ); - $refObject = new \ReflectionObject($sqlsrvStatement); - $refMapping = $refObject->getProperty('parameterKeyMapping'); - /** @noinspection PhpExpressionResultUnusedInspection */ - $refMapping->setAccessible(true); - $parameterKeyMapping = $refMapping->getValue($sqlsrvStatement); - $this->assertEquals( [ ':search' => [0, 1], ], - $parameterKeyMapping + TestHelper::getValue($sqlsrvStatement, 'parameterKeyMapping') ); } @@ -113,18 +108,12 @@ public function testPrepareParameterKeyMappingWithSingleKey() $rawQuery ); - $refObject = new \ReflectionObject($sqlsrvStatement); - $refMapping = $refObject->getProperty('parameterKeyMapping'); - /** @noinspection PhpExpressionResultUnusedInspection */ - $refMapping->setAccessible(true); - $parameterKeyMapping = $refMapping->getValue($sqlsrvStatement); - $this->assertEquals( [ ':search' => [0], ':search2' => [1], ], - $parameterKeyMapping + TestHelper::getValue($sqlsrvStatement, 'parameterKeyMapping') ); }