diff --git a/composer.json b/composer.json
index fabca6d93..489baa40c 100644
--- a/composer.json
+++ b/composer.json
@@ -18,7 +18,7 @@
"config": {
"sort-packages": true,
"platform": {
- "php": "8.3.99"
+ "php": "8.1.99"
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
@@ -41,7 +41,6 @@
"laminas/laminas-servicemanager": "^3.23.0",
"phpunit/phpunit": "^11.5.12",
"psalm/plugin-phpunit": "^0.19.2",
- "rector/rector": "^2.0",
"vimeo/psalm": "^6.8.8"
},
"suggest": {
@@ -51,8 +50,7 @@
},
"autoload": {
"psr-4": {
- "Laminas\\Db\\": "src/",
- "CustomRule\\PHPUnit\\": "rector/"
+ "Laminas\\Db\\": "src/"
}
},
"autoload-dev": {
diff --git a/composer.lock b/composer.lock
index 3b43a85c5..1340aa7e4 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "25d9661790a6bab19a3198c0f8698fc1",
+ "content-hash": "f292133fa37217f99699ab8adb7ee306",
"packages": [
{
"name": "laminas/laminas-stdlib",
@@ -2576,64 +2576,6 @@
},
"time": "2025-02-19T13:28:12+00:00"
},
- {
- "name": "phpstan/phpstan",
- "version": "2.1.11",
- "source": {
- "type": "git",
- "url": "https://github.com/phpstan/phpstan.git",
- "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8ca5f79a8f63c49b2359065832a654e1ec70ac30",
- "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30",
- "shasum": ""
- },
- "require": {
- "php": "^7.4|^8.0"
- },
- "conflict": {
- "phpstan/phpstan-shim": "*"
- },
- "bin": [
- "phpstan",
- "phpstan.phar"
- ],
- "type": "library",
- "autoload": {
- "files": [
- "bootstrap.php"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "description": "PHPStan - PHP Static Analysis Tool",
- "keywords": [
- "dev",
- "static analysis"
- ],
- "support": {
- "docs": "https://phpstan.org/user-guide/getting-started",
- "forum": "https://github.com/phpstan/phpstan/discussions",
- "issues": "https://github.com/phpstan/phpstan/issues",
- "security": "https://github.com/phpstan/phpstan/security/policy",
- "source": "https://github.com/phpstan/phpstan-src"
- },
- "funding": [
- {
- "url": "https://github.com/ondrejmirtes",
- "type": "github"
- },
- {
- "url": "https://github.com/phpstan",
- "type": "github"
- }
- ],
- "time": "2025-03-24T13:45:00+00:00"
- },
{
"name": "phpunit/php-code-coverage",
"version": "11.0.9",
@@ -3324,65 +3266,6 @@
},
"time": "2024-09-11T13:17:53+00:00"
},
- {
- "name": "rector/rector",
- "version": "2.0.11",
- "source": {
- "type": "git",
- "url": "https://github.com/rectorphp/rector.git",
- "reference": "059b827cc648929711606e9824337e41e2f9ed92"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/rectorphp/rector/zipball/059b827cc648929711606e9824337e41e2f9ed92",
- "reference": "059b827cc648929711606e9824337e41e2f9ed92",
- "shasum": ""
- },
- "require": {
- "php": "^7.4|^8.0",
- "phpstan/phpstan": "^2.1.9"
- },
- "conflict": {
- "rector/rector-doctrine": "*",
- "rector/rector-downgrade-php": "*",
- "rector/rector-phpunit": "*",
- "rector/rector-symfony": "*"
- },
- "suggest": {
- "ext-dom": "To manipulate phpunit.xml via the custom-rule command"
- },
- "bin": [
- "bin/rector"
- ],
- "type": "library",
- "autoload": {
- "files": [
- "bootstrap.php"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "description": "Instant Upgrade and Automated Refactoring of any PHP code",
- "keywords": [
- "automation",
- "dev",
- "migration",
- "refactoring"
- ],
- "support": {
- "issues": "https://github.com/rectorphp/rector/issues",
- "source": "https://github.com/rectorphp/rector/tree/2.0.11"
- },
- "funding": [
- {
- "url": "https://github.com/tomasvotruba",
- "type": "github"
- }
- ],
- "time": "2025-03-28T10:25:17+00:00"
- },
{
"name": "revolt/event-loop",
"version": "v1.0.7",
@@ -5732,7 +5615,7 @@
},
"platform-dev": {},
"platform-overrides": {
- "php": "8.3.99"
+ "php": "8.1.99"
},
"plugin-api-version": "2.6.0"
}
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 2546eb3cf..dff207e69 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -941,6 +941,9 @@
connectionParameters]]>
connectionParameters]]>
+
+
+
@@ -1305,6 +1308,9 @@
+
+
+
@@ -5597,6 +5603,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ adapter]]>
+ adapter]]>
+
+
@@ -5609,6 +5660,9 @@
+
+
+
@@ -5656,6 +5710,9 @@
current()]]>
+
+
+
@@ -5687,6 +5744,9 @@
name]]>
value]]>
+
+
+
adapter]]>
adapter]]>
@@ -5718,7 +5778,9 @@
-
+
+
+
@@ -5846,6 +5908,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -5859,6 +5936,12 @@
+
+
+
+
+
+
fixtureFile)]]>
@@ -5879,6 +5962,9 @@
+
+
+
@@ -5887,6 +5973,12 @@
+
+
+
+
+
+
fixtureFile)]]>
@@ -5903,6 +5995,9 @@
+
+
+
@@ -5911,6 +6006,11 @@
+
+
+
+
+
@@ -5939,6 +6039,9 @@
+
+
+
@@ -5958,6 +6061,10 @@
+
+
+
+
@@ -6008,6 +6115,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -6027,9 +6155,26 @@
+ adapter->DrivER]]>
+ adapter->PlatForm]]>
adapter->foo]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -6042,6 +6187,7 @@
+
@@ -6066,6 +6212,10 @@
getResource())]]>
getCurrentSchema())]]>
+
+ variables);]]>
+ getLastGeneratedValue();]]>
+
@@ -6109,8 +6259,13 @@
+
+
+
+
+
@@ -6121,6 +6276,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -6159,14 +6329,23 @@
+
+
+
+
+
+
+
+
+
@@ -6195,22 +6374,61 @@
+
+
+ variables]]>
+
+
+
+
+
+
+
+
+
+
+
getResource())]]>
getCurrentSchema())]]>
+
+ variables);]]>
+
+
+ disconnect();]]>
+ disconnect();]]>
+ getLastGeneratedValue();]]>
+ setResource($resource);]]>
+ variables['username'],
+ $this->variables['password'],
+ $this->variables['hostname']
+ );]]>
+ variables['username'],
+ $this->variables['password'],
+ $this->variables['hostname']
+ );]]>
+ connect());]]>
+ setResource($resource));]]>
+
+
+
+
+
@@ -6225,10 +6443,19 @@
+
+
+
+
+
+
+
+
+
@@ -6261,8 +6488,13 @@
+
+
+
+
+
@@ -6272,6 +6504,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -6331,11 +6578,14 @@
+
+
+
@@ -6350,16 +6600,24 @@
+
+
+
+
+
+ variables);]]>
+ getLastGeneratedValue();]]>
+
@@ -6394,18 +6652,80 @@
+
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+ wrapper]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
@@ -6414,23 +6734,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
@@ -6439,11 +6777,15 @@
+
+
+
+
@@ -6471,6 +6813,12 @@
+
+
+
+
+
+
@@ -6503,7 +6851,11 @@
-
+
+ pdoStatementMock = $this->getMockBuilder('PDOStatement')
+ ->setMethods(['execute', 'bindParam'])
+ ->getMock()]]>
+
@@ -6525,6 +6877,15 @@
+
+
+
+
+
+
+
+
+
@@ -6542,6 +6903,9 @@
+
+
+
@@ -6560,9 +6924,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -6578,8 +6954,13 @@
+
+
+
+
+
@@ -6591,6 +6972,20 @@
+
+
+ adapters]]>
+ variables]]>
+ variables]]>
+
+
+
+
+
+
+
+
+
@@ -6599,20 +6994,28 @@
+
+
+
+
+
+ variables);]]>
+ getLastGeneratedValue();]]>
+
@@ -6645,6 +7048,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -6675,6 +7093,14 @@
+
+ driver]]>
+ driver]]>
+ driver]]>
+ driver]]>
+ driver]]>
+
+
@@ -6686,8 +7112,13 @@
+
+
+
+
+
@@ -6721,9 +7152,15 @@
+
+
+
+
+
+
@@ -6798,6 +7235,12 @@
+
+
+
+
+
+
@@ -6816,6 +7259,12 @@
+
+
+
+
+
+
@@ -6846,6 +7295,12 @@
+
+
+
+
+
+
@@ -6864,6 +7319,12 @@
+
+
+
+
+
+
@@ -6882,6 +7343,12 @@
+
+
+
+
+
+
@@ -6906,6 +7373,12 @@
+
+
+
+
+
+
@@ -6928,6 +7401,12 @@
+
+
+
+
+
+
@@ -6970,6 +7449,12 @@
+
+
+
+
+
+
@@ -6983,11 +7468,63 @@
+
+
+
+
+
+
+
+
+
+
+ [adapter, expected return class]
+ 'MySQL' => [$createAdapterForPlatform('MySQL'), MysqlMetadata::class],
+ 'SQLServer' => [$createAdapterForPlatform('SQLServer'), SqlServerMetadata::class],
+ 'SQLite' => [$createAdapterForPlatform('SQLite'), SqliteMetadata::class],
+ 'PostgreSQL' => [$createAdapterForPlatform('PostgreSQL'), PostgresqlMetadata::class],
+ 'Oracle' => [$createAdapterForPlatform('Oracle'), OracleMetadata::class],
+ ]]]>
+
+
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -7014,6 +7551,8 @@
+
+
@@ -7061,6 +7600,7 @@
+
@@ -7149,6 +7689,11 @@
+
+
+
+
+
@@ -7219,12 +7764,24 @@
+
+
+
+
+
+
+
+
+
+
+
getMockForAbstractClass(AbstractRowGateway::class)]]>
getMockForAbstractClass(AbstractRowGateway::class)]]>
+
@@ -7267,11 +7824,21 @@
rowGateway->testColumn]]>
rowGateway->testColumn]]>
+
+
+
+
+
+
+
+
+
+
@@ -7286,6 +7853,8 @@
+
+
@@ -7334,6 +7903,9 @@
+
+
+
@@ -7342,6 +7914,13 @@
+
+
+
+
+
+
+
@@ -7668,6 +8247,12 @@
+
+ at(2)]]>
+ at(2)]]>
+ at(2)]]>
+ at(2)]]>
+
@@ -7712,6 +8297,15 @@
+
+
+
+
+
+
+
+
+
@@ -7746,6 +8340,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -7769,6 +8379,12 @@
+
+ at(1)]]>
+ at(1)]]>
+ at(1)]]>
+ at(1)]]>
+
@@ -7787,11 +8403,33 @@
insert->foo]]>
insert->foo]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -7815,12 +8453,21 @@
+
+ at(1)]]>
+ at(1)]]>
+ at(1)]]>
+ at(1)]]>
+
+
+
+
@@ -7833,6 +8480,12 @@
insert->foo]]>
insert->foo]]>
+
+
+
+
+
+
@@ -7870,10 +8523,18 @@
+
+
+
+
+
+
+
+
@@ -7920,11 +8581,23 @@
+
+
+
+
+
+
+
-
+
+
+
+
+
+
@@ -7934,6 +8607,15 @@
+
+
+ * 3: string,
+ * 4: string
+ * }>]]>
+
@@ -7957,11 +8639,27 @@
-
+
+
+
+
+
+
+
+
+
+
+ * 3: string,
+ * 4: int
+ * }>]]>
+
@@ -7972,6 +8670,10 @@
+
+
+
+
@@ -7981,6 +8683,8 @@
+
+
@@ -7989,6 +8693,14 @@
+
+
+
+
+
+
+
+
@@ -8002,6 +8714,11 @@
+
+
+
+
+
@@ -8024,6 +8741,11 @@
+
+
+
+
+
@@ -8402,12 +9124,22 @@
+
+
+
+
+
+
+ getMockBuilder(Operator::class)
+ ->setMethods()
+ ->setConstructorArgs(['rating', '<', '10'])
+ ->getMock()]]>
@@ -8417,7 +9149,9 @@
new Predicate\Operator('number', '>', 20),
])]]>
-
+
+
+
@@ -8517,6 +9251,16 @@
->isNull('bar')
->or]]>
+
+ ,
+ * 3 string,
+ * 4: array,
+ * 5: bool,
+ * }]]>
+
@@ -8534,6 +9278,9 @@
+
+
+
@@ -8558,21 +9305,59 @@
->where
->nest]]>
+
+
+
+
+
+
+
+
+
+
+
+ $this->select('c')->where(['cc' => 'CC']),
+ ]]]>
+ $this
+ ->select([
+ 'b' => $this->select('c')->where(['cc' => 'CC']),
+ ])
+ ->where(['bb' => 'BB']),
+ ]]]>
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -8580,6 +9365,7 @@
+
@@ -8616,13 +9402,35 @@
* },
* }
* }>]]>
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -8659,9 +9467,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -8680,6 +9500,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -8706,6 +9537,11 @@
+
+ at(1)]]>
+ at(1)]]>
+ at(1)]]>
+
@@ -8745,6 +9581,14 @@
+
+
+
+
+
+
+
+
update->__get('what')]]>
@@ -8756,8 +9600,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ getMockBuilder(Adapter::class)
+ ->setMethods()
+ ->setConstructorArgs([$mockDriver])
+ ->getMock()]]>
+ getMockBuilder(\Laminas\Db\Sql\Sql::class)
+ ->setMethods(['select', 'insert', 'update', 'delete'])
+ ->setConstructorArgs([$this->mockAdapter, 'foo'])
+ ->getMock()]]>
+
@@ -8807,6 +9672,7 @@
+
@@ -8821,6 +9687,21 @@
+
+ mockSql]]>
+ mockSql]]>
+ mockSql]]>
+ mockSql]]>
+ mockSql]]>
+ mockSql]]>
+ mockSql]]>
+
+
+
+
+
+
+
@@ -8913,6 +9794,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -8925,6 +9819,9 @@
+
+
+
@@ -8934,6 +9831,14 @@
+
+
+
+
+
+
+
+
@@ -8943,6 +9848,8 @@
+
+
@@ -8961,6 +9868,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -8972,6 +9889,10 @@
+
+
+
+
@@ -8979,6 +9900,12 @@
+
+
+
+
+
+
@@ -8988,6 +9915,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rector.php b/rector.php
deleted file mode 100644
index 1d20630f6..000000000
--- a/rector.php
+++ /dev/null
@@ -1,17 +0,0 @@
-withPaths([
- __DIR__ . '/test',
- ])
- ->withRules([
- ReplaceGetMockForAbstractClassRector::class
- ])
- ->withTypeCoverageLevel(0)
- ->withDeadCodeLevel(0)
- ->withCodeQualityLevel(0);
diff --git a/rector/ReplaceGetMockForAbstractClassRector.php b/rector/ReplaceGetMockForAbstractClassRector.php
deleted file mode 100644
index 3f8c6b353..000000000
--- a/rector/ReplaceGetMockForAbstractClassRector.php
+++ /dev/null
@@ -1,81 +0,0 @@
-getMockForAbstractClass() with $this->createMock() in PHPUnit tests',
- [
- new CodeSample(
- '$this->getMockForAbstractClass(SomeClass::class);',
- '$this->createMock(SomeClass::class);'
- ),
- ]
- );
- }
-
- public function getNodeTypes(): array
- {
- return [MethodCall::class];
- }
-
- public function refactor(Node $node): ?Node
- {
- if (! $this->isName($node->name, 'getMockForAbstractClass')) {
- return null;
- }
-
- if (! $this->isName($node->var, 'this')) {
- return null;
- }
-
- $args = $node->args;
- if (count($args) < 1) {
- return null;
- }
-
- $builderCall = $this->nodeFactory->createMethodCall(
- new Variable('this'),
- 'getMockBuilder',
- [new Arg($args[0]->value)]
- );
-
- $currentCall = $builderCall;
-
- // Derive constructor arguments
- if (isset($args[1])) {
- $currentCall = new MethodCall($currentCall, 'setConstructorArgs', [new Arg($args[1]->value)]);
- }
-
- // Derive methods
- $methodArgs = (isset($args[6])) ? $args[6]->value : new Node\Expr\Array_();
- $currentCall = new MethodCall($currentCall, 'onlyMethods', [new Arg($methodArgs)]);
-
- // Original constructor flag (false -> disable)
- if (isset($args[3]) && $this->valueResolver->isFalse($args[3]->value)) {
- $currentCall = new MethodCall($currentCall, 'disableOriginalConstructor');
- }
-
- return new MethodCall($currentCall, 'getMock');
- }
-}
diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php
index 3d76b87b0..0b154ca58 100644
--- a/src/ConfigProvider.php
+++ b/src/ConfigProvider.php
@@ -32,6 +32,12 @@ public function getDependencyConfig()
],
'aliases' => [
Adapter\Adapter::class => Adapter\AdapterInterface::class,
+
+ // Legacy Zend Framework aliases
+ // phpcs:disable WebimpressCodingStandard.Formatting.StringClassReference.Found
+ 'Zend\Db\Adapter\AdapterInterface' => Adapter\AdapterInterface::class,
+ 'Zend\Db\Adapter\Adapter' => Adapter\Adapter::class,
+ // phpcs:enable WebimpressCodingStandard.Formatting.StringClassReference.Found
],
];
}
diff --git a/src/Sql/Ddl/Column/Column.php b/src/Sql/Ddl/Column/Column.php
index dde4c35e6..fbfb595e4 100644
--- a/src/Sql/Ddl/Column/Column.php
+++ b/src/Sql/Ddl/Column/Column.php
@@ -108,7 +108,7 @@ public function setOptions(array $options)
/**
* @param string $name
- * @param string|boolean $value
+ * @param string $value
* @return $this Provides a fluent interface
*/
public function setOption($name, $value)
diff --git a/src/Sql/Delete.php b/src/Sql/Delete.php
index e7fb0e83a..cd83070ef 100644
--- a/src/Sql/Delete.php
+++ b/src/Sql/Delete.php
@@ -32,8 +32,8 @@ class Delete extends AbstractPreparableSql
self::SPECIFICATION_WHERE => 'WHERE %1$s',
];
- /** @var string|array|TableIdentifier */
- protected TableIdentifier|string|array $table = '';
+ /** @var string|TableIdentifier */
+ protected $table = '';
/** @var bool */
protected $emptyWhereProtection = true;
@@ -60,20 +60,20 @@ public function __construct($table = null)
/**
* Create from statement
*
- * @param string|array|TableIdentifier $table
+ * @param string|TableIdentifier $table
* @return $this Provides a fluent interface
*/
- public function from($table): static
+ public function from($table)
{
$this->table = $table;
return $this;
}
/**
- * @param ?string $key
+ * @param null $key
* @return mixed
*/
- public function getRawState(?string $key = null)
+ public function getRawState($key = null)
{
$rawState = [
'emptyWhereProtection' => $this->emptyWhereProtection,
diff --git a/src/Sql/Insert.php b/src/Sql/Insert.php
index f7612ebc2..fe134f37c 100644
--- a/src/Sql/Insert.php
+++ b/src/Sql/Insert.php
@@ -33,14 +33,14 @@ class Insert extends AbstractPreparableSql
public const VALUES_SET = 'set';
/**#@-*/
- /** @var string[]|array[] $specifications */
+ /** @var array Specification array */
protected $specifications = [
self::SPECIFICATION_INSERT => 'INSERT INTO %1$s (%2$s) VALUES (%3$s)',
self::SPECIFICATION_SELECT => 'INSERT INTO %1$s %2$s %3$s',
];
- /** @var string|array|TableIdentifier */
- protected TableIdentifier|string|array $table = '';
+ /** @var string|TableIdentifier */
+ protected $table;
/** @var string[] */
protected $columns = [];
@@ -63,10 +63,10 @@ public function __construct($table = null)
/**
* Create INTO clause
*
- * @param string|array|TableIdentifier $table
+ * @param string|TableIdentifier $table
* @return $this Provides a fluent interface
*/
- public function into($table): static
+ public function into($table)
{
$this->table = $table;
return $this;
diff --git a/src/Sql/Predicate/Predicate.php b/src/Sql/Predicate/Predicate.php
index 0d5c2cd5f..41a00006f 100644
--- a/src/Sql/Predicate/Predicate.php
+++ b/src/Sql/Predicate/Predicate.php
@@ -14,15 +14,13 @@
* @property Predicate $or
* @property Predicate $AND
* @property Predicate $OR
- * @property Predicate $nest
- * @property Predicate $unnest
* @property Predicate $NEST
* @property Predicate $UNNEST
*/
class Predicate extends PredicateSet
{
/** @var null|Predicate */
- private $unnest;
+ protected $unnest;
/** @var null|string */
protected $nextPredicateCombineOperator;
@@ -246,7 +244,7 @@ public function notLike($identifier, $notLike)
* Create an expression, with parameter placeholders
*
* @param string $expression
- * @param null|string|int|array $parameters
+ * @param null|array $parameters
* @return $this Provides a fluent interface
*/
public function expression($expression, $parameters = null)
diff --git a/src/Sql/Predicate/PredicateSet.php b/src/Sql/Predicate/PredicateSet.php
index 579a1f5ec..61d271856 100644
--- a/src/Sql/Predicate/PredicateSet.php
+++ b/src/Sql/Predicate/PredicateSet.php
@@ -27,7 +27,8 @@ class PredicateSet implements PredicateInterface, Countable
/** @var string */
protected $defaultCombination = self::COMBINED_BY_AND;
- protected array $predicates = [];
+ /** @var PredicateInterface[] */
+ protected $predicates = [];
/**
* Constructor
@@ -134,9 +135,9 @@ public function addPredicates($predicates, $combination = self::OP_AND)
/**
* Return the predicates
*
- * @return array
+ * @return PredicateInterface[]
*/
- public function getPredicates(): array
+ public function getPredicates()
{
return $this->predicates;
}
diff --git a/src/Sql/Select.php b/src/Sql/Select.php
index 338a8dc12..41905702f 100644
--- a/src/Sql/Select.php
+++ b/src/Sql/Select.php
@@ -70,7 +70,7 @@ class Select extends AbstractPreparableSql
public const COMBINE_INTERSECT = 'intersect';
/**#@-*/
- /** @var string[]|array[] $specifications */
+ /** @var array Specifications */
protected $specifications = [
'statementStart' => '%1$s',
self::SELECT => [
@@ -114,8 +114,8 @@ class Select extends AbstractPreparableSql
protected bool $prefixColumnsWithTable = true;
- /** @var null|string|array|TableIdentifier */
- protected $table = null;
+ /** @var string|array|TableIdentifier */
+ protected $table;
/** @var null|string|Expression */
protected $quantifier;
@@ -170,7 +170,7 @@ public function __construct($table = null)
* @return $this Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function from($table): static
+ public function from($table)
{
if ($this->tableReadOnly) {
throw new Exception\InvalidArgumentException(
@@ -239,7 +239,7 @@ public function columns(array $columns, $prefixColumnsWithTable = true)
* Create join clause
*
* @param string|array|TableIdentifier $name
- * @param string|Predicate\PredicateInterface $on
+ * @param string|Predicate\Expression $on
* @param string|array $columns
* @param string $type one of the JOIN_* constants
* @return $this Provides a fluent interface
@@ -329,7 +329,7 @@ public function order($order)
}
/**
- * @param int|string $limit
+ * @param int $limit
* @return $this Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
@@ -348,7 +348,7 @@ public function limit($limit)
}
/**
- * @param int|string $offset
+ * @param int $offset
* @return $this Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
diff --git a/src/Sql/Update.php b/src/Sql/Update.php
index d85ca8661..8c13fee7e 100644
--- a/src/Sql/Update.php
+++ b/src/Sql/Update.php
@@ -47,8 +47,8 @@ class Update extends AbstractPreparableSql
self::SPECIFICATION_WHERE => 'WHERE %1$s',
];
- /** @var string|array|TableIdentifier */
- protected TableIdentifier|string|array $table = '';
+ /** @var string|TableIdentifier */
+ protected $table = '';
/** @var bool */
protected $emptyWhereProtection = true;
@@ -81,10 +81,10 @@ public function __construct($table = null)
/**
* Specify table for statement
*
- * @param string|array|TableIdentifier $table
+ * @param string|TableIdentifier $table
* @return $this Provides a fluent interface
*/
- public function table($table): static
+ public function table($table)
{
$this->table = $table;
return $this;
diff --git a/test/integration/Adapter/Driver/Mysqli/ConnectionTest.php b/test/integration/Adapter/Driver/Mysqli/ConnectionTest.php
index ea69da28c..75439a333 100644
--- a/test/integration/Adapter/Driver/Mysqli/ConnectionTest.php
+++ b/test/integration/Adapter/Driver/Mysqli/ConnectionTest.php
@@ -3,16 +3,17 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Mysqli;
use Laminas\Db\Adapter\Driver\Mysqli\Connection;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-#[Group('integration')]
-#[Group('integration-mysqli')]
-final class ConnectionTest extends TestCase
+/**
+ * @group integration
+ * @group integration-mysqli
+ */
+class ConnectionTest extends TestCase
{
use TraitSetup;
- public function testConnectionOk(): void
+ public function testConnectionOk()
{
$connection = new Connection($this->variables);
$connection->connect();
diff --git a/test/integration/Adapter/Driver/Mysqli/TableGatewayTest.php b/test/integration/Adapter/Driver/Mysqli/TableGatewayTest.php
index 18d52d5a8..65ab93d97 100644
--- a/test/integration/Adapter/Driver/Mysqli/TableGatewayTest.php
+++ b/test/integration/Adapter/Driver/Mysqli/TableGatewayTest.php
@@ -6,14 +6,14 @@
use Laminas\Db\TableGateway\TableGateway;
use PHPUnit\Framework\TestCase;
-final class TableGatewayTest extends TestCase
+class TableGatewayTest extends TestCase
{
use TraitSetup;
/**
* @see https://github.com/zendframework/zend-db/issues/330
*/
- public function testSelectWithEmptyCurrentWithBufferResult(): void
+ public function testSelectWithEmptyCurrentWithBufferResult()
{
$adapter = new Adapter([
'driver' => 'mysqli',
@@ -34,7 +34,7 @@ public function testSelectWithEmptyCurrentWithBufferResult(): void
/**
* @see https://github.com/zendframework/zend-db/issues/330
*/
- public function testSelectWithEmptyCurrentWithoutBufferResult(): void
+ public function testSelectWithEmptyCurrentWithoutBufferResult()
{
$adapter = new Adapter([
'driver' => 'mysqli',
@@ -47,8 +47,6 @@ public function testSelectWithEmptyCurrentWithoutBufferResult(): void
$tableGateway = new TableGateway('test', $adapter);
$rowset = $tableGateway->select('id = 0');
- /** @todo Have resultset implememt Iterator */
- /** @psalm-suppress UndefinedInterfaceMethod */
$this->assertNull($rowset->current());
$adapter->getDriver()->getConnection()->disconnect();
diff --git a/test/integration/Adapter/Driver/Mysqli/TraitSetup.php b/test/integration/Adapter/Driver/Mysqli/TraitSetup.php
index 5c11e006c..220316adb 100644
--- a/test/integration/Adapter/Driver/Mysqli/TraitSetup.php
+++ b/test/integration/Adapter/Driver/Mysqli/TraitSetup.php
@@ -2,20 +2,15 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Mysqli;
-use Override;
-use PHPUnit\Framework\Attributes\RequiresPhpExtension;
-
use function extension_loaded;
use function getenv;
-use function is_string;
use function sprintf;
-use function strtolower;
// phpcs:ignore WebimpressCodingStandard.NamingConventions.Trait.Suffix
trait TraitSetup
{
/** @var array */
- protected array $variables = [
+ protected $variables = [
'hostname' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME',
'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_USERNAME',
'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PASSWORD',
@@ -23,7 +18,7 @@ trait TraitSetup
];
/** @var array */
- protected array $optional = [
+ protected $optional = [
'port' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PORT',
];
@@ -31,12 +26,9 @@ trait TraitSetup
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[RequiresPhpExtension('mysqli')]
- #[Override]
protected function setUp(): void
{
- $testEnabled = (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_ENABLED');
- if (strtolower($testEnabled) !== 'true') {
+ if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) {
$this->markTestSkipped('Mysqli integration test disabled');
}
@@ -45,19 +37,18 @@ protected function setUp(): void
}
foreach ($this->variables as $name => $value) {
- if (! is_string(getenv($value)) || '' === getenv($value)) {
+ if (! getenv($value)) {
$this->markTestSkipped(sprintf(
- 'Missing required variable %s $this->mockUpdate phpunit.xml for this integration test',
+ 'Missing required variable %s from phpunit.xml for this integration test',
$value
));
- } else {
- $this->variables[$name] = (string) getenv($value);
}
+ $this->variables[$name] = getenv($value);
}
foreach ($this->optional as $name => $value) {
- if (is_string(getenv($value)) && '' === getenv($value)) {
- $this->variables[$name] = (string) getenv($value);
+ if (getenv($value)) {
+ $this->variables[$name] = getenv($value);
}
}
}
diff --git a/test/integration/Adapter/Driver/Pdo/AbstractAdapterTestCase.php b/test/integration/Adapter/Driver/Pdo/AbstractAdapterTestCase.php
index b599d6344..e42186b84 100644
--- a/test/integration/Adapter/Driver/Pdo/AbstractAdapterTestCase.php
+++ b/test/integration/Adapter/Driver/Pdo/AbstractAdapterTestCase.php
@@ -2,55 +2,57 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo;
-use Laminas\Db\Adapter\AdapterInterface;
-use PHPUnit\Framework\Attributes\CoversMethod;
+use Laminas\Db\Adapter\Adapter;
use PHPUnit\Framework\TestCase;
use function getmypid;
use function shell_exec;
-#[CoversMethod(AdapterInterface::class, '__construct()')]
+/**
+ * @property Adapter $adapter
+ */
abstract class AbstractAdapterTestCase extends TestCase
{
- use AdapterTrait;
+ public const DB_SERVER_PORT = null;
- public ?int $port = null;
-
- public function testConnection(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Adapter::__construct()
+ */
+ public function testConnection()
{
- $this->assertInstanceOf(AdapterInterface::class, $this->adapter);
+ $this->assertInstanceOf(Adapter::class, $this->adapter);
}
- public function testDriverDisconnectAfterQuoteWithPlatform(): void
+ public function testDriverDisconnectAfterQuoteWithPlatform()
{
$isTcpConnection = $this->isTcpConnection();
- $this->getAdapter()->getDriver()->getConnection()->connect();
+ $this->adapter->getDriver()->getConnection()->connect();
- self::assertTrue($this->getAdapter()->getDriver()->getConnection()->isConnected());
+ self::assertTrue($this->adapter->getDriver()->getConnection()->isConnected());
if ($isTcpConnection) {
self::assertTrue($this->isConnectedTcp());
}
- $this->getAdapter()->getDriver()->getConnection()->disconnect();
+ $this->adapter->getDriver()->getConnection()->disconnect();
- self::assertFalse($this->getAdapter()->getDriver()->getConnection()->isConnected());
+ self::assertFalse($this->adapter->getDriver()->getConnection()->isConnected());
if ($isTcpConnection) {
self::assertFalse($this->isConnectedTcp());
}
- $this->getAdapter()->getDriver()->getConnection()->connect();
+ $this->adapter->getDriver()->getConnection()->connect();
- self::assertTrue($this->getAdapter()->getDriver()->getConnection()->isConnected());
+ self::assertTrue($this->adapter->getDriver()->getConnection()->isConnected());
if ($isTcpConnection) {
self::assertTrue($this->isConnectedTcp());
}
- $this->getAdapter()->getPlatform()->quoteValue('test');
+ $this->adapter->getPlatform()->quoteValue('test');
- $this->getAdapter()->getDriver()->getConnection()->disconnect();
+ $this->adapter->getDriver()->getConnection()->disconnect();
- self::assertFalse($this->getAdapter()->getDriver()->getConnection()->isConnected());
+ self::assertFalse($this->adapter->getDriver()->getConnection()->isConnected());
if ($isTcpConnection) {
self::assertFalse($this->isConnectedTcp());
}
@@ -59,9 +61,8 @@ public function testDriverDisconnectAfterQuoteWithPlatform(): void
protected function isConnectedTcp(): bool
{
$mypid = getmypid();
- $dbPort = (string) $this->port;
- /** @psalm-suppress ForbiddenCode - running lsof */
- $lsof = shell_exec("lsof -i -P -n | grep $dbPort | grep $mypid");
+ $dbPort = static::DB_SERVER_PORT;
+ $lsof = shell_exec("lsof -i -P -n | grep $dbPort | grep $mypid");
return $lsof !== null;
}
@@ -70,4 +71,6 @@ protected function isTcpConnection(): bool
{
return $this->getHostname() !== 'localhost';
}
+
+ abstract protected function getHostname();
}
diff --git a/test/integration/Adapter/Driver/Pdo/AdapterTrait.php b/test/integration/Adapter/Driver/Pdo/AdapterTrait.php
deleted file mode 100644
index 11c38cc1f..000000000
--- a/test/integration/Adapter/Driver/Pdo/AdapterTrait.php
+++ /dev/null
@@ -1,25 +0,0 @@
-adapter === null) {
- $this->fail('Adapter not initialized');
- }
-
- return $this->adapter;
- }
-
- protected function getHostname(): ?string
- {
- return $this->hostname;
- }
-}
diff --git a/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTest.php b/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTest.php
index a1fd9e75d..0aaabf8cf 100644
--- a/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTest.php
+++ b/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTest.php
@@ -2,13 +2,13 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo\Mysql;
+use Laminas\Db\Adapter\Adapter;
use LaminasIntegrationTest\Db\Adapter\Driver\Pdo\AbstractAdapterTestCase;
-use LaminasIntegrationTest\Db\Adapter\Driver\Pdo\AdapterTrait as BaseAdapterTrait;
-final class AdapterTest extends AbstractAdapterTestCase
+class AdapterTest extends AbstractAdapterTestCase
{
use AdapterTrait;
- use BaseAdapterTrait;
- public ?int $port = 3306;
+ /** @var Adapter */
+ public const DB_SERVER_PORT = 3306;
}
diff --git a/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTrait.php b/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTrait.php
index cf3f1cffd..f3e87de95 100644
--- a/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTrait.php
+++ b/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTrait.php
@@ -3,32 +3,32 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo\Mysql;
use Laminas\Db\Adapter\Adapter;
-use Override;
use function getenv;
-use function is_string;
-use function strtolower;
trait AdapterTrait
{
- protected ?string $hostname = 'localhost';
+ /** @var $adapter */
+ protected ?Adapter $adapter;
- #[Override]
protected function setUp(): void
{
- if (! is_string(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) ||
- strtolower((string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) !== 'true') {
+ if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) {
$this->markTestSkipped('pdo_mysql integration tests are not enabled!');
}
$this->adapter = new Adapter([
'driver' => 'pdo_mysql',
- 'database' => (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_DATABASE'),
- 'hostname' => (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME'),
- 'username' => (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_USERNAME'),
- 'password' => (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PASSWORD'),
+ 'database' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_DATABASE'),
+ 'hostname' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME'),
+ 'username' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_USERNAME'),
+ 'password' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PASSWORD'),
]);
+ }
- $this->hostname = (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME');
+ /** @return null|string */
+ protected function getHostname()
+ {
+ return getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME');
}
}
diff --git a/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php b/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php
index f9584d522..ad47c17c4 100644
--- a/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php
+++ b/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php
@@ -2,29 +2,20 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo\Mysql;
-use Exception;
-use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Adapter\Driver\Pdo\Result as PdoResult;
-use Laminas\Db\Adapter\Driver\StatementInterface;
use Laminas\Db\Adapter\Exception\RuntimeException;
use Laminas\Db\ResultSet\ResultSet;
use Laminas\Db\Sql\Sql;
-use LaminasIntegrationTest\Db\Adapter\Driver\Pdo\AdapterTrait as BaseAdapterTrait;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Adapter::class, 'query')]
-#[CoversMethod(ResultSet::class, 'current')]
-final class QueryTest extends TestCase
+class QueryTest extends TestCase
{
use AdapterTrait;
- use BaseAdapterTrait;
/**
* @psalm-return array,
+ * 1: mixed[]|array,
* 2: array
* }>
*/
@@ -45,20 +36,18 @@ public static function getQueriesWithRowResult(): array
}
/**
- * @throws Exception
+ * @dataProvider getQueriesWithRowResult
+ * @covers \Laminas\Db\Adapter\Adapter::query
+ * @covers \Laminas\Db\ResultSet\ResultSet::current
*/
- #[DataProvider('getQueriesWithRowResult')]
- public function testQuery(string $query, array $params, array $expected): void
+ public function testQuery(string $query, array $params, array $expected)
{
- /** @todo Have AdapterInterface implement query */
- /** @psalm-suppress UndefinedInterfaceMethod */
- $result = $this->getAdapter()->query($query, $params);
+ $result = $this->adapter->query($query, $params);
$this->assertInstanceOf(ResultSet::class, $result);
$current = $result->current();
// test as array value
$this->assertEquals($expected, (array) $current);
// test as object value
- /** @var string $value */
foreach ($expected as $key => $value) {
$this->assertEquals($value, $current->$key);
}
@@ -66,34 +55,26 @@ public function testQuery(string $query, array $params, array $expected): void
/**
* @see https://github.com/zendframework/zend-db/issues/288
- *
- * @throws Exception
*/
- public function testSetSessionTimeZone(): void
+ public function testSetSessionTimeZone()
{
- /** @todo Have AdapterInterface implement query */
- /** @psalm-suppress UndefinedInterfaceMethod */
- $result = $this->getAdapter()->query('SET @@session.time_zone = :tz', [':tz' => 'SYSTEM']);
+ $result = $this->adapter->query('SET @@session.time_zone = :tz', [':tz' => 'SYSTEM']);
$this->assertInstanceOf(PdoResult::class, $result);
}
- /**
- * @throws Exception
- */
- public function testSelectWithNotPermittedBindParamName(): void
+ public function testSelectWithNotPermittedBindParamName()
{
$this->expectException(RuntimeException::class);
- /** @todo Have AdapterInterface implement query */
- /** @psalm-suppress UndefinedInterfaceMethod */
- $this->getAdapter()->query('SET @@session.time_zone = :tz$', [':tz$' => 'SYSTEM']);
+ $this->adapter->query('SET @@session.time_zone = :tz$', [':tz$' => 'SYSTEM']);
}
/**
* @see https://github.com/laminas/laminas-db/issues/47
*/
- public function testNamedParameters(): void
+ public function testNamedParameters()
{
- $this->assertNotNull($this->adapter);
+ $this->expectNotToPerformAssertions();
+
$sql = new Sql($this->adapter);
$insert = $sql->update('test');
@@ -102,7 +83,6 @@ public function testNamedParameters(): void
'value' => ':value',
])->where(['id' => ':id']);
$stmt = $sql->prepareStatementForSqlObject($insert);
- $this->assertInstanceOf(StatementInterface::class, $stmt);
//positional parameters
$stmt->execute([
diff --git a/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayAndAdapterTest.php b/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayAndAdapterTest.php
index 136fad9b7..7db962790 100644
--- a/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayAndAdapterTest.php
+++ b/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayAndAdapterTest.php
@@ -2,10 +2,7 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo\Mysql;
-use Exception;
use Laminas\Db\TableGateway\TableGateway;
-use LaminasIntegrationTest\Db\Adapter\Driver\Pdo\AdapterTrait as BaseAdapterTrait;
-use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use function array_fill;
@@ -16,15 +13,13 @@
* On tear down disconnected from the database and set the driver adapter on null
* Running many tests ended up in consuming all mysql connections and not releasing them
*/
-final class TableGatewayAndAdapterTest extends TestCase
+class TableGatewayAndAdapterTest extends TestCase
{
use AdapterTrait;
- use BaseAdapterTrait;
/**
- * @throws Exception
+ * @dataProvider connections
*/
- #[DataProvider('connections')]
public function testGetOutOfConnections(): void
{
$this->adapter->query('SELECT VERSION();');
diff --git a/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php b/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php
index c00379901..54d15544f 100644
--- a/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php
+++ b/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php
@@ -5,35 +5,32 @@
use Laminas\Db\Sql\TableIdentifier;
use Laminas\Db\TableGateway\Feature\MetadataFeature;
use Laminas\Db\TableGateway\TableGateway;
-use LaminasIntegrationTest\Db\Adapter\Driver\Pdo\AdapterTrait as BaseAdapterTrait;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;
use function count;
-#[CoversMethod(TableGateway::class, '__construct')]
-#[CoversMethod(TableGateway::class, 'select')]
-#[CoversMethod(TableGateway::class, 'insert')]
-final class TableGatewayTest extends TestCase
+class TableGatewayTest extends TestCase
{
use AdapterTrait;
- use BaseAdapterTrait;
- public function testConstructor(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\TableGateway::__construct
+ */
+ public function testConstructor()
{
- $tableGateway = new TableGateway('test', $this->getAdapter());
+ $tableGateway = new TableGateway('test', $this->adapter);
$this->assertInstanceOf(TableGateway::class, $tableGateway);
}
- public function testSelect(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\TableGateway::select
+ */
+ public function testSelect()
{
- $tableGateway = new TableGateway('test', $this->getAdapter());
+ $tableGateway = new TableGateway('test', $this->adapter);
$rowset = $tableGateway->select();
$this->assertTrue(count($rowset) > 0);
- /** @var object $row */
foreach ($rowset as $row) {
$this->assertTrue(isset($row->id));
$this->assertNotEmpty(isset($row->name));
@@ -41,11 +38,15 @@ public function testSelect(): void
}
}
- public function testInsert(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\TableGateway::insert
+ * @covers \Laminas\Db\TableGateway\TableGateway::select
+ */
+ public function testInsert()
{
- $tableGateway = new TableGateway('test', $this->getAdapter());
+ $tableGateway = new TableGateway('test', $this->adapter);
- $tableGateway->select();
+ $rowset = $tableGateway->select();
$data = [
'name' => 'test_name',
'value' => 'test_value',
@@ -54,8 +55,7 @@ public function testInsert(): void
$this->assertEquals(1, $affectedRows);
$rowSet = $tableGateway->select(['id' => $tableGateway->getLastInsertValue()]);
- /** @var object $row */
- $row = $rowSet->current();
+ $row = $rowSet->current();
foreach ($data as $key => $value) {
$this->assertEquals($row->$key, $value);
@@ -65,10 +65,12 @@ public function testInsert(): void
/**
* @see https://github.com/zendframework/zend-db/issues/35
* @see https://github.com/zendframework/zend-db/pull/178
+ *
+ * @return mixed
*/
- public function testInsertWithExtendedCharsetFieldName(): int
+ public function testInsertWithExtendedCharsetFieldName()
{
- $tableGateway = new TableGateway('test_charset', $this->getAdapter());
+ $tableGateway = new TableGateway('test_charset', $this->adapter);
$affectedRows = $tableGateway->insert([
'field$' => 'test_value1',
@@ -79,10 +81,13 @@ public function testInsertWithExtendedCharsetFieldName(): int
return $tableGateway->getLastInsertValue();
}
- #[Depends('testInsertWithExtendedCharsetFieldName')]
- public function testUpdateWithExtendedCharsetFieldName(mixed $id): void
+ /**
+ * @depends testInsertWithExtendedCharsetFieldName
+ * @param mixed $id
+ */
+ public function testUpdateWithExtendedCharsetFieldName($id)
{
- $tableGateway = new TableGateway('test_charset', $this->getAdapter());
+ $tableGateway = new TableGateway('test_charset', $this->adapter);
$data = [
'field$' => 'test_value3',
@@ -92,18 +97,20 @@ public function testUpdateWithExtendedCharsetFieldName(mixed $id): void
$this->assertEquals(1, $affectedRows);
$rowSet = $tableGateway->select(['id' => $id]);
- /** @var object $row */
- $row = $rowSet->current();
+ $row = $rowSet->current();
foreach ($data as $key => $value) {
$this->assertEquals($row->$key, $value);
}
}
- #[DataProvider('tableProvider')]
- public function testTableGatewayWithMetadataFeature(array|string|TableIdentifier $table): void
+ /**
+ * @dataProvider tableProvider
+ * @param string|TableIdentifier|array $table
+ */
+ public function testTableGatewayWithMetadataFeature($table)
{
- $tableGateway = new TableGateway($table, $this->getAdapter(), new MetadataFeature());
+ $tableGateway = new TableGateway($table, $this->adapter, new MetadataFeature());
self::assertInstanceOf(TableGateway::class, $tableGateway);
self::assertSame($table, $tableGateway->getTable());
diff --git a/test/integration/Adapter/Driver/Pdo/Postgresql/AdapterTest.php b/test/integration/Adapter/Driver/Pdo/Postgresql/AdapterTest.php
index b62cb0b6e..b23487dff 100644
--- a/test/integration/Adapter/Driver/Pdo/Postgresql/AdapterTest.php
+++ b/test/integration/Adapter/Driver/Pdo/Postgresql/AdapterTest.php
@@ -2,13 +2,14 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo\Postgresql;
+use Laminas\Db\Adapter\Adapter;
use LaminasIntegrationTest\Db\Adapter\Driver\Pdo\AbstractAdapterTestCase;
-use LaminasIntegrationTest\Db\Adapter\Driver\Pdo\AdapterTrait as BaseAdapterTrait;
-final class AdapterTest extends AbstractAdapterTestCase
+class AdapterTest extends AbstractAdapterTestCase
{
use AdapterTrait;
- use BaseAdapterTrait;
- public ?int $port = 5432;
+ /** @var Adapter */
+ protected $adapter;
+ public const DB_SERVER_PORT = 5432;
}
diff --git a/test/integration/Adapter/Driver/Pdo/Postgresql/AdapterTrait.php b/test/integration/Adapter/Driver/Pdo/Postgresql/AdapterTrait.php
index 9bdbc5bc2..01268a300 100644
--- a/test/integration/Adapter/Driver/Pdo/Postgresql/AdapterTrait.php
+++ b/test/integration/Adapter/Driver/Pdo/Postgresql/AdapterTrait.php
@@ -3,31 +3,29 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo\Postgresql;
use Laminas\Db\Adapter\Adapter;
-use Override;
use function getenv;
-use function is_string;
-use function strtolower;
trait AdapterTrait
{
- protected ?string $hostname = 'localhost';
-
- #[Override]
protected function setUp(): void
{
- if (! is_string(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL')) || strtolower(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL')) !== 'true') {
+ if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL')) {
$this->markTestSkipped('pdo_pgsql integration tests are not enabled!');
}
$this->adapter = new Adapter([
'driver' => 'pdo_pgsql',
- 'database' => (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_DATABASE'),
- 'hostname' => (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME'),
- 'username' => (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_USERNAME'),
- 'password' => (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_PASSWORD'),
+ 'database' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_DATABASE'),
+ 'hostname' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME'),
+ 'username' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_USERNAME'),
+ 'password' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_PASSWORD'),
]);
+ }
- $this->hostname = (string) getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME');
+ /** @return null|string */
+ protected function getHostname()
+ {
+ return getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME');
}
}
diff --git a/test/integration/Adapter/Driver/Pdo/Postgresql/TableGatewayTest.php b/test/integration/Adapter/Driver/Pdo/Postgresql/TableGatewayTest.php
index b471be209..707fb9170 100644
--- a/test/integration/Adapter/Driver/Pdo/Postgresql/TableGatewayTest.php
+++ b/test/integration/Adapter/Driver/Pdo/Postgresql/TableGatewayTest.php
@@ -2,25 +2,26 @@
namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo\Postgresql;
+use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Sql\TableIdentifier;
use Laminas\Db\TableGateway\Feature\FeatureSet;
use Laminas\Db\TableGateway\Feature\SequenceFeature;
use Laminas\Db\TableGateway\TableGateway;
-use LaminasIntegrationTest\Db\Adapter\Driver\Pdo\AdapterTrait as BaseAdapterTrait;
use PHPUnit\Framework\TestCase;
-final class TableGatewayTest extends TestCase
+class TableGatewayTest extends TestCase
{
use AdapterTrait;
- use BaseAdapterTrait;
- public function testLastInsertValue(): void
+ /** @var Adapter */
+ protected $adapter;
+ public function testLastInsertValue()
{
$table = new TableIdentifier('test_seq');
$featureSet = new FeatureSet();
$featureSet->addFeature(new SequenceFeature('id', 'test_seq_id_seq'));
- $tableGateway = new TableGateway($table, $this->getAdapter(), $featureSet);
+ $tableGateway = new TableGateway($table, $this->adapter, $featureSet);
$tableGateway->insert(['foo' => 'bar']);
self::assertSame(1, $tableGateway->getLastInsertValue());
diff --git a/test/integration/Adapter/Platform/MysqlTest.php b/test/integration/Adapter/Platform/MysqlTest.php
index f606b48d5..358a9d602 100644
--- a/test/integration/Adapter/Platform/MysqlTest.php
+++ b/test/integration/Adapter/Platform/MysqlTest.php
@@ -5,21 +5,20 @@
use Laminas\Db\Adapter\Driver\Mysqli;
use Laminas\Db\Adapter\Driver\Pdo;
use Laminas\Db\Adapter\Platform\Mysql;
-use Override;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
use function getenv;
-#[Group('integration')]
-#[Group('integration-mysql')]
-final class MysqlTest extends TestCase
+/**
+ * @group integration
+ * @group integration-mysql
+ */
+class MysqlTest extends TestCase
{
/** @var array */
- public array|\PDO $adapters = [];
+ public $adapters = [];
- #[Override]
protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) {
@@ -43,9 +42,6 @@ protected function setUp(): void
}
}
- /**
- * @return void
- */
public function testQuoteValueWithMysqli()
{
if (! $this->adapters['mysqli'] instanceof \Mysqli) {
@@ -60,9 +56,6 @@ public function testQuoteValueWithMysqli()
self::assertEquals('\'value\'', $value);
}
- /**
- * @return void
- */
public function testQuoteValueWithPdoMysql()
{
if (! $this->adapters['pdo_mysql'] instanceof \PDO) {
diff --git a/test/integration/Adapter/Platform/PostgresqlTest.php b/test/integration/Adapter/Platform/PostgresqlTest.php
index de135cb62..4bd979131 100644
--- a/test/integration/Adapter/Platform/PostgresqlTest.php
+++ b/test/integration/Adapter/Platform/PostgresqlTest.php
@@ -5,9 +5,7 @@
use Laminas\Db\Adapter\Driver\Pdo;
use Laminas\Db\Adapter\Driver\Pgsql;
use Laminas\Db\Adapter\Platform\Postgresql;
-use Override;
use PgSql\Connection as PgSqlConnection;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
@@ -15,14 +13,15 @@
use function is_resource;
use function pg_connect;
-#[Group('integration')]
-#[Group('integration-postgres')]
-final class PostgresqlTest extends TestCase
+/**
+ * @group integration
+ * @group integration-postgres
+ */
+class PostgresqlTest extends TestCase
{
/** @var array */
- public array|\PDO $adapters = [];
+ public $adapters = [];
- #[Override]
protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL')) {
@@ -46,9 +45,6 @@ protected function setUp(): void
}
}
- /**
- * @return void
- */
public function testQuoteValueWithPgsql()
{
if (
@@ -69,9 +65,6 @@ public function testQuoteValueWithPgsql()
self::assertEquals('\'value\'', $value);
}
- /**
- * @return void
- */
public function testQuoteValueWithPdoPgsql()
{
if (! isset($this->adapters['pdo_pgsql']) || ! $this->adapters['pdo_pgsql'] instanceof \PDO) {
diff --git a/test/integration/Adapter/Platform/SqlServerTest.php b/test/integration/Adapter/Platform/SqlServerTest.php
index e6e8e6568..de8244b7b 100644
--- a/test/integration/Adapter/Platform/SqlServerTest.php
+++ b/test/integration/Adapter/Platform/SqlServerTest.php
@@ -3,9 +3,7 @@
namespace LaminasIntegrationTest\Db\Adapter\Platform;
use Laminas\Db\Adapter\Platform\SqlServer;
-use Override;
use PDO;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
@@ -14,14 +12,15 @@
use function sqlsrv_errors;
use function var_dump;
-#[Group('integration')]
-#[Group('integration-sqlserver')]
-final class SqlServerTest extends TestCase
+/**
+ * @group integration
+ * @group integration-sqlserver
+ */
+class SqlServerTest extends TestCase
{
/** @var array */
- public array|PDO $adapters = [];
+ public $adapters = [];
- #[Override]
protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV')) {
@@ -57,9 +56,6 @@ protected function setUp(): void
}
}
- /**
- * @return void
- */
public function testQuoteValueWithSqlServer()
{
if (! isset($this->adapters['pdo_sqlsrv'])) {
diff --git a/test/integration/Adapter/Platform/SqliteTest.php b/test/integration/Adapter/Platform/SqliteTest.php
index d3bf10140..3d9881d26 100644
--- a/test/integration/Adapter/Platform/SqliteTest.php
+++ b/test/integration/Adapter/Platform/SqliteTest.php
@@ -4,21 +4,20 @@
use Laminas\Db\Adapter\Driver\Pdo;
use Laminas\Db\Adapter\Platform\Sqlite;
-use Override;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
use function getenv;
-#[Group('integration')]
-#[Group('integration-sqlite')]
-final class SqliteTest extends TestCase
+/**
+ * @group integration
+ * @group integration-sqlite
+ */
+class SqliteTest extends TestCase
{
/** @var array */
- public array|\PDO $adapters = [];
+ public $adapters = [];
- #[Override]
protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY')) {
@@ -31,9 +30,6 @@ protected function setUp(): void
}
}
- /**
- * @return void
- */
public function testQuoteValueWithPdoSqlite()
{
if (! $this->adapters['pdo_sqlite'] instanceof \PDO) {
diff --git a/test/integration/Extension/IntegrationTestStartedListener.php b/test/integration/Extension/IntegrationTestStartedListener.php
index 980c865aa..8e775e8d2 100644
--- a/test/integration/Extension/IntegrationTestStartedListener.php
+++ b/test/integration/Extension/IntegrationTestStartedListener.php
@@ -2,7 +2,6 @@
namespace LaminasIntegrationTest\Db\Extension;
-use Exception;
use LaminasIntegrationTest\Db\Platform\FixtureLoader;
use LaminasIntegrationTest\Db\Platform\MysqlFixtureLoader;
use LaminasIntegrationTest\Db\Platform\PgsqlFixtureLoader;
@@ -16,11 +15,8 @@
final class IntegrationTestStartedListener implements StartedSubscriber
{
/** @var FixtureLoader[] */
- private array $fixtureLoaders = [];
+ private $fixtureLoaders = [];
- /**
- * @throws Exception
- */
public function notify(Started $event): void
{
if ($event->testSuite()->name() !== 'integration test') {
diff --git a/test/integration/Extension/IntegrationTestStoppedListener.php b/test/integration/Extension/IntegrationTestStoppedListener.php
index 645069a5f..04f2ab276 100644
--- a/test/integration/Extension/IntegrationTestStoppedListener.php
+++ b/test/integration/Extension/IntegrationTestStoppedListener.php
@@ -11,7 +11,7 @@
final class IntegrationTestStoppedListener implements FinishedSubscriber
{
/** @var FixtureLoader[] */
- private array $fixtureLoaders = [];
+ private $fixtureLoaders = [];
public function notify(Finished $event): void
{
diff --git a/test/integration/Platform/MysqlFixtureLoader.php b/test/integration/Platform/MysqlFixtureLoader.php
index 4aff9f56c..4784d0f0b 100644
--- a/test/integration/Platform/MysqlFixtureLoader.php
+++ b/test/integration/Platform/MysqlFixtureLoader.php
@@ -10,16 +10,15 @@
use function print_r;
use function sprintf;
-final class MysqlFixtureLoader implements FixtureLoader
+class MysqlFixtureLoader implements FixtureLoader
{
- private string $fixtureFile = __DIR__ . '/../TestFixtures/mysql.sql';
+ /** @var string */
+ private $fixtureFile = __DIR__ . '/../TestFixtures/mysql.sql';
- private PDO $pdo;
+ /** @var PDO */
+ private $pdo;
- /**
- * @throws Exception
- */
- public function createDatabase(): void
+ public function createDatabase()
{
$this->connect();
@@ -50,7 +49,7 @@ public function createDatabase(): void
$this->disconnect();
}
- public function dropDatabase(): void
+ public function dropDatabase()
{
$this->connect();
@@ -62,7 +61,7 @@ public function dropDatabase(): void
$this->disconnect();
}
- protected function connect(): void
+ protected function connect()
{
$dsn = 'mysql:host=' . getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME');
if (getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PORT')) {
@@ -76,7 +75,7 @@ protected function connect(): void
);
}
- protected function disconnect(): void
+ protected function disconnect()
{
$this->pdo = null;
}
diff --git a/test/integration/Platform/PgsqlFixtureLoader.php b/test/integration/Platform/PgsqlFixtureLoader.php
index e82a62fa4..9649a4ddc 100644
--- a/test/integration/Platform/PgsqlFixtureLoader.php
+++ b/test/integration/Platform/PgsqlFixtureLoader.php
@@ -10,18 +10,18 @@
use function print_r;
use function sprintf;
-final class PgsqlFixtureLoader implements FixtureLoader
+class PgsqlFixtureLoader implements FixtureLoader
{
- private string $fixtureFile = __DIR__ . '/../TestFixtures/pgsql.sql';
+ /** @var string */
+ private $fixtureFile = __DIR__ . '/../TestFixtures/pgsql.sql';
- private PDO $pdo;
+ /** @var PDO */
+ private $pdo;
- private bool $initialRun = true;
+ /** @var bool */
+ private $initialRun = true;
- /**
- * @throws Exception
- */
- public function createDatabase(): void
+ public function createDatabase()
{
$this->connect();
@@ -59,7 +59,7 @@ public function createDatabase(): void
$this->disconnect();
}
- public function dropDatabase(): void
+ public function dropDatabase()
{
if (! $this->initialRun) {
// Not possible to drop in PostgreSQL.
@@ -82,7 +82,7 @@ public function dropDatabase(): void
/**
* @param bool $useDb add dbname using in dsn
*/
- protected function connect(bool $useDb = false): void
+ protected function connect($useDb = false)
{
$dsn = 'pgsql:host=' . getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME');
@@ -97,7 +97,7 @@ protected function connect(bool $useDb = false): void
);
}
- protected function disconnect(): void
+ protected function disconnect()
{
$this->pdo = null;
}
diff --git a/test/integration/Platform/SqlServerFixtureLoader.php b/test/integration/Platform/SqlServerFixtureLoader.php
index d6cc6615e..4f420b124 100644
--- a/test/integration/Platform/SqlServerFixtureLoader.php
+++ b/test/integration/Platform/SqlServerFixtureLoader.php
@@ -12,16 +12,14 @@
use function sqlsrv_errors;
use function sqlsrv_query;
-final class SqlServerFixtureLoader implements FixtureLoader
+class SqlServerFixtureLoader implements FixtureLoader
{
- private string $fixtureFilePrefix = __DIR__ . '/../TestFixtures/sqlsrv';
+ /** @var string */
+ private $fixtureFilePrefix = __DIR__ . '/../TestFixtures/sqlsrv';
/** @var resource */
private $connection;
- /**
- * @throws Exception
- */
public function createDatabase(): void
{
$this->connect();
@@ -70,10 +68,7 @@ public function createDatabase(): void
// phpcs:enable Squiz.PHP.NonExecutableCode.Unreachable
}
- /**
- * @throws Exception
- */
- public function dropDatabase(): void
+ public function dropDatabase()
{
$this->connect();
@@ -99,10 +94,7 @@ public function dropDatabase(): void
$this->disconnect();
}
- /**
- * @throws Exception
- */
- protected function connect(): void
+ protected function connect()
{
$this->connection = sqlsrv_connect(
getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_HOSTNAME'),
@@ -122,7 +114,7 @@ protected function connect(): void
}
}
- protected function disconnect(): void
+ protected function disconnect()
{
$this->connection = null;
}
diff --git a/test/unit/Adapter/AdapterAbstractServiceFactoryTest.php b/test/unit/Adapter/AdapterAbstractServiceFactoryTest.php
index fa17bbd65..f90516309 100644
--- a/test/unit/Adapter/AdapterAbstractServiceFactoryTest.php
+++ b/test/unit/Adapter/AdapterAbstractServiceFactoryTest.php
@@ -6,20 +6,15 @@
use Laminas\Db\Adapter\AdapterAbstractServiceFactory;
use Laminas\ServiceManager\Config;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
+use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\ServiceManager;
-use Override;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\TestCase;
-use Psr\Container\ContainerExceptionInterface;
-use Psr\Container\ContainerInterface;
-use Psr\Container\NotFoundExceptionInterface;
-final class AdapterAbstractServiceFactoryTest extends TestCase
+class AdapterAbstractServiceFactoryTest extends TestCase
{
- private ServiceManager|ContainerInterface $serviceManager;
+ /** @var ServiceLocatorInterface */
+ private $serviceManager;
- #[Override]
protected function setUp(): void
{
$this->serviceManager = new ServiceManager();
@@ -43,7 +38,10 @@ protected function setUp(): void
]);
}
- public static function providerValidService(): array
+ /**
+ * @return array
+ */
+ public function providerValidService()
{
return [
['Laminas\Db\Adapter\Writer'],
@@ -51,7 +49,10 @@ public static function providerValidService(): array
];
}
- public static function providerInvalidService(): array
+ /**
+ * @return array
+ */
+ public function providerInvalidService()
{
return [
['Laminas\Db\Adapter\Unknown'],
@@ -59,23 +60,21 @@ public static function providerInvalidService(): array
}
/**
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
+ * @param string $service
+ * @dataProvider providerValidService
+ * @requires extension mysqli
*/
- #[RequiresPhpExtension('mysqli')]
- #[DataProvider('providerValidService')]
- public function testValidService(string $service): void
+ public function testValidService($service)
{
$actual = $this->serviceManager->get($service);
self::assertInstanceOf(Adapter::class, $actual);
}
/**
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
+ * @dataProvider providerInvalidService
+ * @param string $service
*/
- #[DataProvider('providerInvalidService')]
- public function testInvalidService(string $service): void
+ public function testInvalidService($service)
{
$this->expectException(ServiceNotFoundException::class);
$this->serviceManager->get($service);
diff --git a/test/unit/Adapter/AdapterAwareTraitTest.php b/test/unit/Adapter/AdapterAwareTraitTest.php
index c6939748c..24e1458b3 100644
--- a/test/unit/Adapter/AdapterAwareTraitTest.php
+++ b/test/unit/Adapter/AdapterAwareTraitTest.php
@@ -7,19 +7,13 @@
use Laminas\Db\Adapter\Driver\DriverInterface;
use Laminas\Db\Adapter\Platform\PlatformInterface;
use LaminasTest\Db\DeprecatedAssertionsTrait;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
-final class AdapterAwareTraitTest extends TestCase
+class AdapterAwareTraitTest extends TestCase
{
use DeprecatedAssertionsTrait;
- /**
- * @throws ReflectionException
- * @throws Exception
- */
- public function testSetDbAdapter(): void
+ public function testSetDbAdapter()
{
$object = $this->getObjectForTrait(AdapterAwareTrait::class);
diff --git a/test/unit/Adapter/AdapterServiceDelegatorTest.php b/test/unit/Adapter/AdapterServiceDelegatorTest.php
index c9d32b530..69ee3a76e 100644
--- a/test/unit/Adapter/AdapterServiceDelegatorTest.php
+++ b/test/unit/Adapter/AdapterServiceDelegatorTest.php
@@ -10,18 +10,12 @@
use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\ServiceManager;
use LaminasTest\Db\Adapter\TestAsset\ConcreteAdapterAwareObject;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
-use Psr\Container\NotFoundExceptionInterface;
use stdClass;
final class AdapterServiceDelegatorTest extends TestCase
{
- /**
- * @throws Exception
- */
public function testSetAdapterShouldBeCalledForExistingAdapter(): void
{
$container = $this->createMock(ContainerInterface::class);
@@ -36,7 +30,9 @@ public function testSetAdapterShouldBeCalledForExistingAdapter(): void
->with(AdapterInterface::class)
->willReturn($this->createMock(Adapter::class));
- $callback = static fn(): ConcreteAdapterAwareObject => new ConcreteAdapterAwareObject();
+ $callback = static function (): ConcreteAdapterAwareObject {
+ return new ConcreteAdapterAwareObject();
+ };
/** @var ConcreteAdapterAwareObject $result */
$result = (new AdapterServiceDelegator())(
@@ -51,9 +47,6 @@ public function testSetAdapterShouldBeCalledForExistingAdapter(): void
);
}
- /**
- * @throws Exception
- */
public function testSetAdapterShouldBeCalledForOnlyConcreteAdapter(): void
{
$container = $this
@@ -70,7 +63,9 @@ public function testSetAdapterShouldBeCalledForOnlyConcreteAdapter(): void
->with(AdapterInterface::class)
->willReturn($this->createMock(AdapterInterface::class));
- $callback = static fn(): ConcreteAdapterAwareObject => new ConcreteAdapterAwareObject();
+ $callback = static function (): ConcreteAdapterAwareObject {
+ return new ConcreteAdapterAwareObject();
+ };
/** @var ConcreteAdapterAwareObject $result */
$result = (new AdapterServiceDelegator())(
@@ -82,9 +77,6 @@ public function testSetAdapterShouldBeCalledForOnlyConcreteAdapter(): void
$this->assertNull($result->getAdapter());
}
- /**
- * @throws Exception
- */
public function testSetAdapterShouldNotBeCalledForMissingAdapter(): void
{
$container = $this->createMock(ContainerInterface::class);
@@ -97,7 +89,9 @@ public function testSetAdapterShouldNotBeCalledForMissingAdapter(): void
->expects(self::never())
->method('get');
- $callback = static fn(): ConcreteAdapterAwareObject => new ConcreteAdapterAwareObject();
+ $callback = static function (): ConcreteAdapterAwareObject {
+ return new ConcreteAdapterAwareObject();
+ };
/** @var ConcreteAdapterAwareObject $result */
$result = (new AdapterServiceDelegator())(
@@ -109,9 +103,6 @@ public function testSetAdapterShouldNotBeCalledForMissingAdapter(): void
$this->assertNull($result->getAdapter());
}
- /**
- * @throws Exception
- */
public function testSetAdapterShouldNotBeCalledForWrongClassInstance(): void
{
$container = $this->createMock(ContainerInterface::class);
@@ -119,7 +110,9 @@ public function testSetAdapterShouldNotBeCalledForWrongClassInstance(): void
->expects(self::never())
->method('has');
- $callback = static fn(): stdClass => new stdClass();
+ $callback = static function (): stdClass {
+ return new stdClass();
+ };
$result = (new AdapterServiceDelegator())(
$container,
@@ -130,11 +123,6 @@ public function testSetAdapterShouldNotBeCalledForWrongClassInstance(): void
$this->assertNotInstanceOf(AdapterAwareInterface::class, $result);
}
- /**
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- * @throws Exception
- */
public function testDelegatorWithServiceManager(): void
{
$databaseAdapter = new Adapter($this->createMock(DriverInterface::class));
@@ -144,7 +132,11 @@ public function testDelegatorWithServiceManager(): void
ConcreteAdapterAwareObject::class => ConcreteAdapterAwareObject::class,
],
'factories' => [
- AdapterInterface::class => static fn() => $databaseAdapter,
+ AdapterInterface::class => static function () use (
+ $databaseAdapter
+ ) {
+ return $databaseAdapter;
+ },
],
'delegators' => [
ConcreteAdapterAwareObject::class => [
@@ -153,6 +145,7 @@ public function testDelegatorWithServiceManager(): void
],
]);
+ /** @var ConcreteAdapterAwareObject $result */
$result = $container->get(ConcreteAdapterAwareObject::class);
$this->assertInstanceOf(
@@ -161,12 +154,7 @@ public function testDelegatorWithServiceManager(): void
);
}
- /**
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- * @throws Exception
- */
- public function testDelegatorWithServiceManagerAndCustomAdapterName(): void
+ public function testDelegatorWithServiceManagerAndCustomAdapterName()
{
$databaseAdapter = new Adapter($this->createMock(DriverInterface::class));
@@ -175,7 +163,11 @@ public function testDelegatorWithServiceManagerAndCustomAdapterName(): void
ConcreteAdapterAwareObject::class => ConcreteAdapterAwareObject::class,
],
'factories' => [
- 'alternate-database-adapter' => static fn() => $databaseAdapter,
+ 'alternate-database-adapter' => static function () use (
+ $databaseAdapter
+ ) {
+ return $databaseAdapter;
+ },
],
'delegators' => [
ConcreteAdapterAwareObject::class => [
@@ -184,6 +176,7 @@ public function testDelegatorWithServiceManagerAndCustomAdapterName(): void
],
]);
+ /** @var ConcreteAdapterAwareObject $result */
$result = $container->get(ConcreteAdapterAwareObject::class);
$this->assertInstanceOf(
@@ -192,16 +185,17 @@ public function testDelegatorWithServiceManagerAndCustomAdapterName(): void
);
}
- /**
- * @throws Exception
- */
- public function testDelegatorWithPluginManager(): void
+ public function testDelegatorWithPluginManager()
{
$databaseAdapter = new Adapter($this->createMock(DriverInterface::class));
$container = new ServiceManager([
'factories' => [
- AdapterInterface::class => static fn() => $databaseAdapter,
+ AdapterInterface::class => static function () use (
+ $databaseAdapter
+ ) {
+ return $databaseAdapter;
+ },
],
]);
$pluginManagerConfig = [
diff --git a/test/unit/Adapter/AdapterServiceFactoryTest.php b/test/unit/Adapter/AdapterServiceFactoryTest.php
index 3978d2ae9..e40f52b7a 100644
--- a/test/unit/Adapter/AdapterServiceFactoryTest.php
+++ b/test/unit/Adapter/AdapterServiceFactoryTest.php
@@ -5,23 +5,19 @@
use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Adapter\AdapterServiceFactory;
use Laminas\ServiceManager\ServiceLocatorInterface;
-use Override;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
-final class AdapterServiceFactoryTest extends TestCase
+class AdapterServiceFactoryTest extends TestCase
{
- private ServiceLocatorInterface&MockObject $services;
+ /** @var ServiceLocatorInterface&MockObject */
+ private $services;
- private AdapterServiceFactory $factory;
+ /** @var AdapterServiceFactory */
+ private $factory;
- /**
- * @throws Exception
- */
- #[Override]
protected function setUp(): void
{
if (! extension_loaded('pdo_sqlite')) {
@@ -33,7 +29,7 @@ protected function setUp(): void
$this->factory = new AdapterServiceFactory();
}
- public function testV2FactoryReturnsAdapter(): void
+ public function testV2FactoryReturnsAdapter()
{
$this->services
->method('get')
@@ -49,7 +45,7 @@ public function testV2FactoryReturnsAdapter(): void
self::assertInstanceOf(Adapter::class, $adapter);
}
- public function testV3FactoryReturnsAdapter(): void
+ public function testV3FactoryReturnsAdapter()
{
$this->services
->method('get')
diff --git a/test/unit/Adapter/AdapterTest.php b/test/unit/Adapter/AdapterTest.php
index a3e697e41..a77ee1826 100644
--- a/test/unit/Adapter/AdapterTest.php
+++ b/test/unit/Adapter/AdapterTest.php
@@ -24,77 +24,71 @@
use Laminas\Db\ResultSet\ResultSet;
use Laminas\Db\ResultSet\ResultSetInterface;
use LaminasTest\Db\TestAsset\TemporaryResultSet;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
-use PHPUnit\Framework\Attributes\TestDox;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
-#[CoversMethod(Adapter::class, 'setProfiler')]
-#[CoversMethod(Adapter::class, 'getProfiler')]
-#[CoversMethod(Adapter::class, 'createDriver')]
-#[CoversMethod(Adapter::class, 'createPlatform')]
-#[CoversMethod(Adapter::class, 'getDriver')]
-#[CoversMethod(Adapter::class, 'getPlatform')]
-#[CoversMethod(Adapter::class, 'getQueryResultSetPrototype')]
-#[CoversMethod(Adapter::class, 'getCurrentSchema')]
-#[CoversMethod(Adapter::class, 'query')]
-#[CoversMethod(Adapter::class, 'createStatement')]
-#[CoversMethod(Adapter::class, '__get')]
-final class AdapterTest extends TestCase
+class AdapterTest extends TestCase
{
- protected DriverInterface&MockObject $mockDriver;
+ /** @var MockObject&DriverInterface */
+ protected $mockDriver;
- protected PlatformInterface&MockObject $mockPlatform;
+ /** @var MockObject&PlatformInterface */
+ protected $mockPlatform;
- protected ConnectionInterface&MockObject $mockConnection;
+ /** @var MockObject&ConnectionInterface */
+ protected $mockConnection;
- protected StatementInterface&MockObject $mockStatement;
+ /** @var MockObject&StatementInterface */
+ protected $mockStatement;
- protected Adapter $adapter;
+ /** @var Adapter */
+ protected $adapter;
- /**
- * @throws Exception
- */
- #[Override]
protected function setUp(): void
{
$this->mockDriver = $this->createMock(DriverInterface::class);
$this->mockConnection = $this->createMock(ConnectionInterface::class);
- $this->mockDriver->method('checkEnvironment')->willReturn(true);
+ $this->mockDriver->method('checkEnvironment')->will($this->returnValue(true));
$this->mockDriver->method('getConnection')
- ->willReturn($this->mockConnection);
+ ->will($this->returnValue($this->mockConnection));
$this->mockPlatform = $this->createMock(PlatformInterface::class);
$this->mockStatement = $this->createMock(StatementInterface::class);
$this->mockDriver->method('createStatement')
- ->willReturn($this->mockStatement);
+ ->will($this->returnValue($this->mockStatement));
$this->adapter = new Adapter($this->mockDriver, $this->mockPlatform);
}
- #[TestDox('unit test: Test setProfiler() will store profiler')]
- public function testSetProfiler(): void
+ /**
+ * @testdox unit test: Test setProfiler() will store profiler
+ * @covers \Laminas\Db\Adapter\Adapter::setProfiler
+ */
+ public function testSetProfiler()
{
$ret = $this->adapter->setProfiler(new Profiler\Profiler());
self::assertSame($this->adapter, $ret);
}
- #[TestDox('unit test: Test getProfiler() will store profiler')]
- public function testGetProfiler(): void
+ /**
+ * @testdox unit test: Test getProfiler() will store profiler
+ * @covers \Laminas\Db\Adapter\Adapter::getProfiler
+ */
+ public function testGetProfiler()
{
$this->adapter->setProfiler($profiler = new Profiler\Profiler());
self::assertSame($profiler, $this->adapter->getProfiler());
$adapter = new Adapter(['driver' => $this->mockDriver, 'profiler' => true], $this->mockPlatform);
- self::assertInstanceOf(Profiler\Profiler::class, $adapter->getProfiler());
+ self::assertInstanceOf(\Laminas\Db\Adapter\Profiler\Profiler::class, $adapter->getProfiler());
}
- #[TestDox('unit test: Test createDriverFromParameters() will create proper driver type')]
- public function testCreateDriver(): void
+ /**
+ * @testdox unit test: Test createDriverFromParameters() will create proper driver type
+ * @covers \Laminas\Db\Adapter\Adapter::createDriver
+ */
+ public function testCreateDriver()
{
if (extension_loaded('mysqli')) {
$adapter = new Adapter(['driver' => 'mysqli'], $this->mockPlatform);
@@ -121,47 +115,50 @@ public function testCreateDriver(): void
}
}
- #[TestDox('unit test: Test createPlatformFromDriver() will create proper platform from driver')]
- public function testCreatePlatform(): void
+ /**
+ * @testdox unit test: Test createPlatformFromDriver() will create proper platform from driver
+ * @covers \Laminas\Db\Adapter\Adapter::createPlatform
+ */
+ public function testCreatePlatform()
{
$driver = clone $this->mockDriver;
- $driver->expects($this->any())->method('getDatabasePlatformName')->willReturn('Mysql');
+ $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Mysql'));
$adapter = new Adapter($driver);
self::assertInstanceOf(Mysql::class, $adapter->platform);
unset($adapter, $driver);
$driver = clone $this->mockDriver;
- $driver->expects($this->any())->method('getDatabasePlatformName')->willReturn('SqlServer');
+ $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('SqlServer'));
$adapter = new Adapter($driver);
self::assertInstanceOf(SqlServer::class, $adapter->platform);
unset($adapter, $driver);
$driver = clone $this->mockDriver;
- $driver->expects($this->any())->method('getDatabasePlatformName')->willReturn('Postgresql');
+ $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Postgresql'));
$adapter = new Adapter($driver);
self::assertInstanceOf(Postgresql::class, $adapter->platform);
unset($adapter, $driver);
$driver = clone $this->mockDriver;
- $driver->expects($this->any())->method('getDatabasePlatformName')->willReturn('Sqlite');
+ $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Sqlite'));
$adapter = new Adapter($driver);
self::assertInstanceOf(Sqlite::class, $adapter->platform);
unset($adapter, $driver);
$driver = clone $this->mockDriver;
- $driver->expects($this->any())->method('getDatabasePlatformName')->willReturn('IbmDb2');
+ $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('IbmDb2'));
$adapter = new Adapter($driver);
self::assertInstanceOf(IbmDb2::class, $adapter->platform);
unset($adapter, $driver);
$driver = clone $this->mockDriver;
- $driver->expects($this->any())->method('getDatabasePlatformName')->willReturn('Oracle');
+ $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Oracle'));
$adapter = new Adapter($driver);
self::assertInstanceOf(Oracle::class, $adapter->platform);
unset($adapter, $driver);
$driver = clone $this->mockDriver;
- $driver->expects($this->any())->method('getDatabasePlatformName')->willReturn('Foo');
+ $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Foo'));
$adapter = new Adapter($driver);
self::assertInstanceOf(Sql92::class, $adapter->platform);
unset($adapter, $driver);
@@ -178,47 +175,55 @@ public function testCreatePlatform(): void
unset($adapter, $driver);
}
- #[TestDox('unit test: Test getDriver() will return driver object')]
- public function testGetDriver(): void
+ /**
+ * @testdox unit test: Test getDriver() will return driver object
+ * @covers \Laminas\Db\Adapter\Adapter::getDriver
+ */
+ public function testGetDriver()
{
self::assertSame($this->mockDriver, $this->adapter->getDriver());
}
- #[TestDox('unit test: Test getPlatform() returns platform object')]
- public function testGetPlatform(): void
+ /**
+ * @testdox unit test: Test getPlatform() returns platform object
+ * @covers \Laminas\Db\Adapter\Adapter::getPlatform
+ */
+ public function testGetPlatform()
{
self::assertSame($this->mockPlatform, $this->adapter->getPlatform());
}
- #[TestDox('unit test: Test getPlatform() returns platform object')]
- public function testGetQueryResultSetPrototype(): void
+ /**
+ * @testdox unit test: Test getPlatform() returns platform object
+ * @covers \Laminas\Db\Adapter\Adapter::getQueryResultSetPrototype
+ */
+ public function testGetQueryResultSetPrototype()
{
self::assertInstanceOf(ResultSetInterface::class, $this->adapter->getQueryResultSetPrototype());
}
- #[TestDox('unit test: Test getCurrentSchema() returns current schema from connection object')]
- public function testGetCurrentSchema(): void
+ /**
+ * @testdox unit test: Test getCurrentSchema() returns current schema from connection object
+ * @covers \Laminas\Db\Adapter\Adapter::getCurrentSchema
+ */
+ public function testGetCurrentSchema()
{
- $this->mockConnection->expects($this->any())->method('getCurrentSchema')->willReturn('FooSchema');
+ $this->mockConnection->expects($this->any())->method('getCurrentSchema')->will($this->returnValue('FooSchema'));
self::assertEquals('FooSchema', $this->adapter->getCurrentSchema());
}
/**
- * @throws \Exception
+ * @testdox unit test: Test query() in prepare mode produces a statement object
+ * @covers \Laminas\Db\Adapter\Adapter::query
*/
- #[TestDox('unit test: Test query() in prepare mode produces a statement object')]
- public function testQueryWhenPreparedProducesStatement(): void
+ public function testQueryWhenPreparedProducesStatement()
{
$s = $this->adapter->query('SELECT foo');
self::assertSame($this->mockStatement, $s);
}
- /**
- * @throws Exception
- * @throws \Exception
- */
- #[Group('#210')]
- public function testProducedResultSetPrototypeIsDifferentForEachQuery(): void
+ /** @group #210 */
+ public function testProducedResultSetPrototypeIsDifferentForEachQuery()
{
$statement = $this->createMock(StatementInterface::class);
$result = $this->createMock(ResultInterface::class);
@@ -237,66 +242,66 @@ public function testProducedResultSetPrototypeIsDifferentForEachQuery(): void
}
/**
- * @throws \Exception
+ * @testdox unit test: Test query() in prepare mode, with array of parameters, produces a result object
+ * @covers \Laminas\Db\Adapter\Adapter::query
*/
- #[TestDox('unit test: Test query() in prepare mode, with array of parameters, produces a result object')]
- public function testQueryWhenPreparedWithParameterArrayProducesResult(): void
+ public function testQueryWhenPreparedWithParameterArrayProducesResult()
{
$parray = ['bar' => 'foo'];
$sql = 'SELECT foo, :bar';
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$result = $this->getMockBuilder(ResultInterface::class)->getMock();
$this->mockDriver->expects($this->any())->method('createStatement')
- ->with($sql)->willReturn($statement);
- $this->mockStatement->expects($this->any())->method('execute')->willReturn($result);
+ ->with($sql)->will($this->returnValue($statement));
+ $this->mockStatement->expects($this->any())->method('execute')->will($this->returnValue($result));
$r = $this->adapter->query($sql, $parray);
self::assertSame($result, $r);
}
/**
- * @throws \Exception
+ * @testdox unit test: Test query() in prepare mode, with ParameterContainer, produces a result object
+ * @covers \Laminas\Db\Adapter\Adapter::query
*/
- #[TestDox('unit test: Test query() in prepare mode, with ParameterContainer, produces a result object')]
- public function testQueryWhenPreparedWithParameterContainerProducesResult(): void
+ public function testQueryWhenPreparedWithParameterContainerProducesResult()
{
$sql = 'SELECT foo';
$parameterContainer = $this->getMockBuilder(ParameterContainer::class)->getMock();
$result = $this->getMockBuilder(ResultInterface::class)->getMock();
$this->mockDriver->expects($this->any())->method('createStatement')
- ->with($sql)->willReturn($this->mockStatement);
- $this->mockStatement->expects($this->any())->method('execute')->willReturn($result);
- $result->expects($this->any())->method('isQueryResult')->willReturn(true);
+ ->with($sql)->will($this->returnValue($this->mockStatement));
+ $this->mockStatement->expects($this->any())->method('execute')->will($this->returnValue($result));
+ $result->expects($this->any())->method('isQueryResult')->will($this->returnValue(true));
$r = $this->adapter->query($sql, $parameterContainer);
self::assertInstanceOf(ResultSet::class, $r);
}
/**
- * @throws \Exception
+ * @testdox unit test: Test query() in execute mode produces a driver result object
+ * @covers \Laminas\Db\Adapter\Adapter::query
*/
- #[TestDox('unit test: Test query() in execute mode produces a driver result object')]
- public function testQueryWhenExecutedProducesAResult(): void
+ public function testQueryWhenExecutedProducesAResult()
{
$sql = 'SELECT foo';
$result = $this->getMockBuilder(ResultInterface::class)->getMock();
- $this->mockConnection->expects($this->any())->method('execute')->with($sql)->willReturn($result);
+ $this->mockConnection->expects($this->any())->method('execute')->with($sql)->will($this->returnValue($result));
$r = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE);
self::assertSame($result, $r);
}
/**
- * @throws \Exception
+ * @testdox unit test: Test query() in execute mode produces a resultset object
+ * @covers \Laminas\Db\Adapter\Adapter::query
*/
- #[TestDox('unit test: Test query() in execute mode produces a resultset object')]
- public function testQueryWhenExecutedProducesAResultSetObjectWhenResultIsQuery(): void
+ public function testQueryWhenExecutedProducesAResultSetObjectWhenResultIsQuery()
{
$sql = 'SELECT foo';
$result = $this->getMockBuilder(ResultInterface::class)->getMock();
- $this->mockConnection->expects($this->any())->method('execute')->with($sql)->willReturn($result);
- $result->expects($this->any())->method('isQueryResult')->willReturn(true);
+ $this->mockConnection->expects($this->any())->method('execute')->with($sql)->will($this->returnValue($result));
+ $result->expects($this->any())->method('isQueryResult')->will($this->returnValue(true));
$r = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE);
self::assertInstanceOf(ResultSet::class, $r);
@@ -305,20 +310,25 @@ public function testQueryWhenExecutedProducesAResultSetObjectWhenResultIsQuery()
self::assertInstanceOf(TemporaryResultSet::class, $r);
}
- #[TestDox('unit test: Test createStatement() produces a statement object')]
- public function testCreateStatement(): void
+ /**
+ * @testdox unit test: Test createStatement() produces a statement object
+ * @covers \Laminas\Db\Adapter\Adapter::createStatement
+ */
+ public function testCreateStatement()
{
self::assertSame($this->mockStatement, $this->adapter->createStatement());
}
+ /**
+ * @testdox unit test: Test __get() works
+ * @covers \Laminas\Db\Adapter\Adapter::__get
+ */
// @codingStandardsIgnoreStart
- public function test__get(): void
+ public function test__get()
{
// @codingStandardsIgnoreEnd
self::assertSame($this->mockDriver, $this->adapter->driver);
- /** @psalm-suppress UndefinedMagicPropertyFetch */
self::assertSame($this->mockDriver, $this->adapter->DrivER);
- /** @psalm-suppress UndefinedMagicPropertyFetch */
self::assertSame($this->mockPlatform, $this->adapter->PlatForm);
self::assertSame($this->mockPlatform, $this->adapter->platform);
diff --git a/test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTestCase.php b/test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTest.php
similarity index 88%
rename from test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTestCase.php
rename to test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTest.php
index 302391870..f71eb94a0 100644
--- a/test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTestCase.php
+++ b/test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTest.php
@@ -2,16 +2,15 @@
namespace LaminasTest\Db\Adapter\Driver\IbmDb2;
-use Override;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
use function getenv;
-abstract class AbstractIntegrationTestCase extends TestCase
+abstract class AbstractIntegrationTest extends TestCase
{
/** @var array */
- protected string|array|false $variables = [
+ protected $variables = [
'database' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_DATABASE',
'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_USERNAME',
'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_PASSWORD',
@@ -21,7 +20,6 @@ abstract class AbstractIntegrationTestCase extends TestCase
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
foreach ($this->variables as $name => $value) {
diff --git a/test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php b/test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php
index bd1b7d822..4697f4a81 100644
--- a/test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php
+++ b/test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php
@@ -5,34 +5,29 @@
use Laminas\Db\Adapter\Driver\IbmDb2\Connection;
use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2;
use Laminas\Db\Adapter\Driver\IbmDb2\Result;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use function ini_get;
use function php_uname;
-#[CoversMethod(Connection::class, 'getCurrentSchema')]
-#[CoversMethod(Connection::class, 'setResource')]
-#[CoversMethod(Connection::class, 'getResource')]
-#[CoversMethod(Connection::class, 'connect')]
-#[CoversMethod(Connection::class, 'isConnected')]
-#[CoversMethod(Connection::class, 'disconnect')]
-#[CoversMethod(Connection::class, 'beginTransaction')]
-#[CoversMethod(Connection::class, 'commit')]
-#[CoversMethod(Connection::class, 'rollback')]
-#[CoversMethod(Connection::class, 'execute')]
-#[CoversMethod(Connection::class, 'getLastGeneratedValue')]
-#[Group('integration')]
-#[Group('integration-ibm_db2')]
-final class ConnectionIntegrationTest extends AbstractIntegrationTestCase
+/**
+ * @group integration
+ * @group integration-ibm_db2
+ */
+class ConnectionIntegrationTest extends AbstractIntegrationTest
{
- public function testGetCurrentSchema(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::getCurrentSchema
+ */
+ public function testGetCurrentSchema()
{
$connection = new Connection($this->variables);
self::assertInternalType('string', $connection->getCurrentSchema());
}
- public function testSetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::setResource
+ */
+ public function testSetResource()
{
$resource = db2_connect(
$this->variables['database'],
@@ -47,7 +42,10 @@ public function testSetResource(): void
unset($resource);
}
- public function testGetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::getResource
+ */
+ public function testGetResource()
{
$connection = new Connection($this->variables);
$connection->connect();
@@ -57,7 +55,10 @@ public function testGetResource(): void
unset($connection);
}
- public function testConnect(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::connect
+ */
+ public function testConnect()
{
$connection = new Connection($this->variables);
self::assertSame($connection, $connection->connect());
@@ -67,7 +68,10 @@ public function testConnect(): void
unset($connection);
}
- public function testIsConnected(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::isConnected
+ */
+ public function testIsConnected()
{
$connection = new Connection($this->variables);
self::assertFalse($connection->isConnected());
@@ -78,7 +82,10 @@ public function testIsConnected(): void
unset($connection);
}
- public function testDisconnect(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::disconnect
+ */
+ public function testDisconnect()
{
$connection = new Connection($this->variables);
$connection->connect();
@@ -88,7 +95,7 @@ public function testDisconnect(): void
}
/**
- * @return void
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::beginTransaction
*/
public function testBeginTransaction()
{
@@ -104,7 +111,7 @@ public function testBeginTransaction()
}
/**
- * @return void
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::commit
*/
public function testCommit()
{
@@ -125,7 +132,7 @@ public function testCommit()
}
/**
- * @return void
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::rollback
*/
public function testRollback()
{
@@ -147,8 +154,10 @@ public function testRollback()
/**
* Return true if the transaction is enabled for DB2
+ *
+ * @return bool
*/
- protected function isTransactionEnabled(): bool
+ protected function isTransactionEnabled()
{
$os = php_uname('s') === 'OS400';
if ($os) {
@@ -158,7 +167,10 @@ protected function isTransactionEnabled(): bool
return true;
}
- public function testExecute(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::execute
+ */
+ public function testExecute()
{
$ibmdb2 = new IbmDb2($this->variables);
$connection = $ibmdb2->getConnection();
@@ -167,17 +179,20 @@ public function testExecute(): void
self::assertInstanceOf(Result::class, $result);
}
- public function testGetLastGeneratedValue(): never
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::getLastGeneratedValue
+ */
+ public function testGetLastGeneratedValue()
{
$this->markTestIncomplete('Need to create a temporary sequence.');
- /*
$connection = new Connection($this->variables);
$connection->getLastGeneratedValue();
- */
}
- #[Group('laminas3469')]
- public function testConnectReturnsConnectionWhenResourceSet(): void
+ /**
+ * @group laminas3469
+ */
+ public function testConnectReturnsConnectionWhenResourceSet()
{
$resource = db2_connect(
$this->variables['database'],
diff --git a/test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php b/test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php
index a5812cfe4..6cb0db26d 100644
--- a/test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php
+++ b/test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php
@@ -4,22 +4,17 @@
use Laminas\Db\Adapter\Driver\IbmDb2\Connection;
use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Connection::class, 'setDriver')]
-#[CoversMethod(Connection::class, 'setConnectionParameters')]
-#[CoversMethod(Connection::class, 'getConnectionParameters')]
-final class ConnectionTest extends TestCase
+class ConnectionTest extends TestCase
{
- protected Connection $connection;
+ /** @var Connection */
+ protected $connection;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->connection = new Connection([]);
@@ -33,17 +28,26 @@ protected function tearDown(): void
{
}
- public function testSetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::setDriver
+ */
+ public function testSetDriver()
{
self::assertEquals($this->connection, $this->connection->setDriver(new IbmDb2([])));
}
- public function testSetConnectionParameters(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::setConnectionParameters
+ */
+ public function testSetConnectionParameters()
{
self::assertEquals($this->connection, $this->connection->setConnectionParameters([]));
}
- public function testGetConnectionParameters(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::getConnectionParameters
+ */
+ public function testGetConnectionParameters()
{
$this->connection->setConnectionParameters(['foo' => 'bar']);
self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters());
diff --git a/test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php b/test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php
index 248ed8404..ea6810328 100644
--- a/test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php
+++ b/test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php
@@ -5,23 +5,25 @@
use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2;
use Laminas\Db\Adapter\Driver\IbmDb2\Statement;
use Laminas\Db\Adapter\Exception\InvalidArgumentException;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use stdClass;
-#[CoversMethod(IbmDb2::class, 'checkEnvironment')]
-#[Group('integration')]
-#[Group('integration-ibm_db2')]
-final class IbmDb2IntegrationTest extends AbstractIntegrationTestCase
+/**
+ * @group integration
+ * @group integration-ibm_db2
+ */
+class IbmDb2IntegrationTest extends AbstractIntegrationTest
{
- #[Group('integration-ibm_db2')]
- public function testCheckEnvironment(): void
+ /**
+ * @group integration-ibm_db2
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::checkEnvironment
+ */
+ public function testCheckEnvironment()
{
$ibmdb2 = new IbmDb2([]);
self::assertNull($ibmdb2->checkEnvironment());
}
- public function testCreateStatement(): void
+ public function testCreateStatement()
{
$driver = new IbmDb2([]);
diff --git a/test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php b/test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php
index 73b78460b..60c6ddb45 100644
--- a/test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php
+++ b/test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php
@@ -6,77 +6,92 @@
use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2;
use Laminas\Db\Adapter\Driver\IbmDb2\Result;
use Laminas\Db\Adapter\Driver\IbmDb2\Statement;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Depends;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(IbmDb2::class, 'registerConnection')]
-#[CoversMethod(IbmDb2::class, 'registerStatementPrototype')]
-#[CoversMethod(IbmDb2::class, 'registerResultPrototype')]
-#[CoversMethod(IbmDb2::class, 'getDatabasePlatformName')]
-#[CoversMethod(IbmDb2::class, 'getConnection')]
-#[CoversMethod(IbmDb2::class, 'createStatement')]
-#[CoversMethod(IbmDb2::class, 'createResult')]
-#[CoversMethod(IbmDb2::class, 'getPrepareType')]
-#[CoversMethod(IbmDb2::class, 'formatParameterName')]
-#[CoversMethod(IbmDb2::class, 'getLastGeneratedValue')]
-#[CoversMethod(IbmDb2::class, 'getResultPrototype')]
-final class IbmDb2Test extends TestCase
+class IbmDb2Test extends TestCase
{
- protected IbmDb2 $ibmdb2;
+ /** @var IbmDb2 */
+ protected $ibmdb2;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->ibmdb2 = new IbmDb2([]);
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::registerConnection
*/
- public function testRegisterConnection(): void
+ public function testRegisterConnection()
{
- $mockConnection = $this->getMockBuilder(Connection::class)->setConstructorArgs([[]])->onlyMethods(['setDriver'])->getMock();
+ $mockConnection = $this->getMockForAbstractClass(
+ Connection::class,
+ [[]],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
$mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->ibmdb2));
self::assertSame($this->ibmdb2, $this->ibmdb2->registerConnection($mockConnection));
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::registerStatementPrototype
*/
- public function testRegisterStatementPrototype(): void
+ public function testRegisterStatementPrototype()
{
$this->ibmdb2 = new IbmDb2([]);
- $mockStatement = $this->getMockBuilder(Statement::class)->setConstructorArgs([])->onlyMethods(['setDriver'])->getMock();
+ $mockStatement = $this->getMockForAbstractClass(
+ Statement::class,
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
$mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->ibmdb2));
self::assertSame($this->ibmdb2, $this->ibmdb2->registerStatementPrototype($mockStatement));
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::registerResultPrototype
*/
- public function testRegisterResultPrototype(): void
+ public function testRegisterResultPrototype()
{
$this->ibmdb2 = new IbmDb2([]);
- $mockStatement = $this->getMockBuilder(Result::class)->setConstructorArgs([])->onlyMethods([])->getMock();
+ $mockStatement = $this->getMockForAbstractClass(
+ Result::class,
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
self::assertSame($this->ibmdb2, $this->ibmdb2->registerResultPrototype($mockStatement));
}
- public function testGetDatabasePlatformName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getDatabasePlatformName
+ */
+ public function testGetDatabasePlatformName()
{
$this->ibmdb2 = new IbmDb2([]);
self::assertEquals('IbmDb2', $this->ibmdb2->getDatabasePlatformName());
self::assertEquals('IBM DB2', $this->ibmdb2->getDatabasePlatformName(IbmDb2::NAME_FORMAT_NATURAL));
}
- #[Depends('testRegisterConnection')]
- public function testGetConnection(): void
+ /**
+ * @depends testRegisterConnection
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getConnection
+ */
+ public function testGetConnection()
{
$conn = new Connection([]);
$this->ibmdb2->registerConnection($conn);
@@ -84,9 +99,10 @@ public function testGetConnection(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::createStatement
* @todo Implement testGetPrepareType().
*/
- public function testCreateStatement(): never
+ public function testCreateStatement()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -95,9 +111,10 @@ public function testCreateStatement(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::createResult
* @todo Implement testGetPrepareType().
*/
- public function testCreateResult(): never
+ public function testCreateResult()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -106,9 +123,10 @@ public function testCreateResult(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getPrepareType
* @todo Implement testGetPrepareType().
*/
- public function testGetPrepareType(): never
+ public function testGetPrepareType()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -117,9 +135,10 @@ public function testGetPrepareType(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::formatParameterName
* @todo Implement testFormatParameterName().
*/
- public function testFormatParameterName(): never
+ public function testFormatParameterName()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -128,9 +147,10 @@ public function testFormatParameterName(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getLastGeneratedValue
* @todo Implement testGetLastGeneratedValue().
*/
- public function testGetLastGeneratedValue(): never
+ public function testGetLastGeneratedValue()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -138,7 +158,10 @@ public function testGetLastGeneratedValue(): never
);
}
- public function testGetResultPrototype(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getResultPrototype
+ */
+ public function testGetResultPrototype()
{
$resultPrototype = $this->ibmdb2->getResultPrototype();
diff --git a/test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php b/test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php
index 649b0570b..682d3ea6e 100644
--- a/test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php
+++ b/test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php
@@ -3,35 +3,21 @@
namespace LaminasTest\Db\Adapter\Driver\IbmDb2;
use Laminas\Db\Adapter\Driver\IbmDb2\Result;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Result::class, 'initialize')]
-#[CoversMethod(Result::class, 'buffer')]
-#[CoversMethod(Result::class, 'getResource')]
-#[CoversMethod(Result::class, 'current')]
-#[CoversMethod(Result::class, 'next')]
-#[CoversMethod(Result::class, 'key')]
-#[CoversMethod(Result::class, 'rewind')]
-#[CoversMethod(Result::class, 'valid')]
-#[CoversMethod(Result::class, 'count')]
-#[CoversMethod(Result::class, 'getFieldCount')]
-#[CoversMethod(Result::class, 'isQueryResult')]
-#[CoversMethod(Result::class, 'getAffectedRows')]
-#[CoversMethod(Result::class, 'getGeneratedValue')]
-#[Group('integration')]
-#[Group('integration-ibm_db2')]
-final class ResultIntegrationTest extends TestCase
+/**
+ * @group integration
+ * @group integration-ibm_db2
+ */
+class ResultIntegrationTest extends TestCase
{
- protected Result $object;
+ /** @var Result */
+ protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->object = new Result();
@@ -46,9 +32,10 @@ protected function tearDown(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::initialize
* @todo Implement testInitialize().
*/
- public function testInitialize(): never
+ public function testInitialize()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -57,9 +44,10 @@ public function testInitialize(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::buffer
* @todo Implement testBuffer().
*/
- public function testBuffer(): never
+ public function testBuffer()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -68,9 +56,10 @@ public function testBuffer(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::getResource
* @todo Implement testGetResource().
*/
- public function testGetResource(): never
+ public function testGetResource()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -79,9 +68,10 @@ public function testGetResource(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::current
* @todo Implement testCurrent().
*/
- public function testCurrent(): never
+ public function testCurrent()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -90,9 +80,10 @@ public function testCurrent(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::next
* @todo Implement testNext().
*/
- public function testNext(): never
+ public function testNext()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -101,9 +92,10 @@ public function testNext(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::key
* @todo Implement testKey().
*/
- public function testKey(): never
+ public function testKey()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -112,9 +104,10 @@ public function testKey(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::rewind
* @todo Implement testRewind().
*/
- public function testRewind(): never
+ public function testRewind()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -123,9 +116,10 @@ public function testRewind(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::valid
* @todo Implement testValid().
*/
- public function testValid(): never
+ public function testValid()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -134,9 +128,10 @@ public function testValid(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::count
* @todo Implement testCount().
*/
- public function testCount(): never
+ public function testCount()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -145,9 +140,10 @@ public function testCount(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::getFieldCount
* @todo Implement testGetFieldCount().
*/
- public function testGetFieldCount(): never
+ public function testGetFieldCount()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -156,9 +152,10 @@ public function testGetFieldCount(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::isQueryResult
* @todo Implement testIsQueryResult().
*/
- public function testIsQueryResult(): never
+ public function testIsQueryResult()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -167,9 +164,10 @@ public function testIsQueryResult(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::getAffectedRows
* @todo Implement testGetAffectedRows().
*/
- public function testGetAffectedRows(): never
+ public function testGetAffectedRows()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -178,9 +176,10 @@ public function testGetAffectedRows(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::getGeneratedValue
* @todo Implement testGetGeneratedValue().
*/
- public function testGetGeneratedValue(): never
+ public function testGetGeneratedValue()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
diff --git a/test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php b/test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php
index 1a8e9ef46..be00b5569 100644
--- a/test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php
+++ b/test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php
@@ -6,26 +6,20 @@
use Laminas\Db\Adapter\Driver\IbmDb2\Result;
use Laminas\Db\Adapter\Driver\IbmDb2\Statement;
use Laminas\Db\Adapter\Exception\RuntimeException;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
use function get_resource_type;
use function getenv;
-#[CoversMethod(Statement::class, 'initialize')]
-#[CoversMethod(Statement::class, 'getResource')]
-#[CoversMethod(Statement::class, 'prepare')]
-#[CoversMethod(Statement::class, 'isPrepared')]
-#[CoversMethod(Statement::class, 'execute')]
-#[Group('integration')]
-#[Group('integration-ibm_db2')]
-final class StatementIntegrationTest extends TestCase
+/**
+ * @group integration
+ * @group integration-ibm_db2
+ */
+class StatementIntegrationTest extends TestCase
{
/** @var array */
- protected string|array|false $variables = [
+ protected $variables = [
'database' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_DATABASE',
'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_USERNAME',
'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_PASSWORD',
@@ -35,7 +29,6 @@ final class StatementIntegrationTest extends TestCase
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
foreach ($this->variables as $name => $value) {
@@ -52,7 +45,10 @@ protected function setUp(): void
}
}
- public function testInitialize(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::initialize
+ */
+ public function testInitialize()
{
$db2Resource = db2_connect(
$this->variables['database'],
@@ -65,7 +61,10 @@ public function testInitialize(): void
unset($stmtResource, $db2Resource);
}
- public function testGetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::getResource
+ */
+ public function testGetResource()
{
$db2Resource = db2_connect(
$this->variables['database'],
@@ -81,7 +80,11 @@ public function testGetResource(): void
unset($resource, $db2Resource);
}
- public function testPrepare(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::isPrepared
+ */
+ public function testPrepare()
{
$db2Resource = db2_connect(
$this->variables['database'],
@@ -97,7 +100,10 @@ public function testPrepare(): void
unset($resource, $db2Resource);
}
- public function testPrepareThrowsAnExceptionOnFailure(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare
+ */
+ public function testPrepareThrowsAnExceptionOnFailure()
{
$db2Resource = db2_connect(
$this->variables['database'],
@@ -110,7 +116,10 @@ public function testPrepareThrowsAnExceptionOnFailure(): void
$statement->prepare("SELECT");
}
- public function testExecute(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::execute
+ */
+ public function testExecute()
{
$ibmdb2 = new IbmDb2($this->variables);
$statement = $ibmdb2->createStatement("SELECT 'foo' FROM SYSIBM.SYSDUMMY1");
diff --git a/test/unit/Adapter/Driver/IbmDb2/StatementTest.php b/test/unit/Adapter/Driver/IbmDb2/StatementTest.php
index 55d4826fd..5aa71abbf 100644
--- a/test/unit/Adapter/Driver/IbmDb2/StatementTest.php
+++ b/test/unit/Adapter/Driver/IbmDb2/StatementTest.php
@@ -6,33 +6,23 @@
use Laminas\Db\Adapter\Driver\IbmDb2\Statement;
use Laminas\Db\Adapter\Exception\RuntimeException;
use Laminas\Db\Adapter\ParameterContainer;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
use function error_reporting;
include __DIR__ . '/TestAsset/Db2Functions.php';
-#[CoversMethod(Statement::class, 'setDriver')]
-#[CoversMethod(Statement::class, 'setParameterContainer')]
-#[CoversMethod(Statement::class, 'getParameterContainer')]
-#[CoversMethod(Statement::class, 'getResource')]
-#[CoversMethod(Statement::class, 'setSql')]
-#[CoversMethod(Statement::class, 'getSql')]
-#[CoversMethod(Statement::class, 'prepare')]
-#[CoversMethod(Statement::class, 'isPrepared')]
-#[CoversMethod(Statement::class, 'execute')]
-final class StatementTest extends TestCase
+class StatementTest extends TestCase
{
- protected Statement $statement;
- protected int $currentErrorReporting;
+ /** @var Statement */
+ protected $statement;
+ /** @var int */
+ protected $currentErrorReporting;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
// store current error_reporting value as we may change it
@@ -51,20 +41,27 @@ protected function tearDown(): void
error_reporting($this->currentErrorReporting);
}
- public function testSetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setDriver
+ */
+ public function testSetDriver()
{
self::assertEquals($this->statement, $this->statement->setDriver(new IbmDb2([])));
}
- public function testSetParameterContainer(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setParameterContainer
+ */
+ public function testSetParameterContainer()
{
self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer()));
}
/**
- * @todo Implement testGetParameterContainer().
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::getParameterContainer
+ * @todo Implement testGetParameterContainer().
*/
- public function testGetParameterContainer(): void
+ public function testGetParameterContainer()
{
$container = new ParameterContainer();
$this->statement->setParameterContainer($container);
@@ -72,9 +69,10 @@ public function testGetParameterContainer(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::getResource
* @todo Implement testGetResource().
*/
- public function testGetResource(): never
+ public function testGetResource()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -83,9 +81,10 @@ public function testGetResource(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setSql
* @todo Implement testSetSql().
*/
- public function testSetSql(): never
+ public function testSetSql()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -94,9 +93,10 @@ public function testSetSql(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::getSql
* @todo Implement testGetSql().
*/
- public function testGetSql(): never
+ public function testGetSql()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -104,32 +104,46 @@ public function testGetSql(): never
);
}
- public function testPrepare(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::isPrepared
+ */
+ public function testPrepare()
{
$sql = "SELECT 'foo' FROM SYSIBM.SYSDUMMY1";
$this->statement->prepare($sql);
$this->assertTrue($this->statement->isPrepared());
}
- public function testPreparingTwiceErrors(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::isPrepared
+ */
+ public function testPreparingTwiceErrors()
{
$sql = "SELECT 'foo' FROM SYSIBM.SYSDUMMY1";
$this->statement->prepare($sql);
$this->assertTrue($this->statement->isPrepared());
$this->expectException(
- RuntimeException::class
+ RuntimeException::class,
+ 'This statement has been prepared already'
);
$this->statement->prepare($sql);
}
- public function testPrepareThrowsRuntimeExceptionOnInvalidSql(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setSql
+ */
+ public function testPrepareThrowsRuntimeExceptionOnInvalidSql()
{
$sql = "INVALID SQL";
$this->statement->setSql($sql);
$this->expectException(
- RuntimeException::class
+ RuntimeException::class,
+ 'SQL is invalid. Error message'
);
$this->statement->prepare();
}
@@ -138,23 +152,28 @@ public function testPrepareThrowsRuntimeExceptionOnInvalidSql(): void
* If error_reporting() is turned off, then the error handler will not
* be called, but a RuntimeException will still be generated as the
* resource is false
+ *
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setSql
*/
- public function testPrepareThrowsRuntimeExceptionOnInvalidSqlWithErrorReportingDisabled(): void
+ public function testPrepareThrowsRuntimeExceptionOnInvalidSqlWithErrorReportingDisabled()
{
error_reporting(0);
$sql = "INVALID SQL";
$this->statement->setSql($sql);
$this->expectException(
- RuntimeException::class
+ RuntimeException::class,
+ 'Error message'
);
$this->statement->prepare();
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::execute
* @todo Implement testExecute().
*/
- public function testExecute(): never
+ public function testExecute()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
diff --git a/test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php b/test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php
index e6842c7e4..bbaa9a51d 100644
--- a/test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php
+++ b/test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php
@@ -9,11 +9,15 @@
/**
* Mock db2_prepare by placing in same namespace as Statement
+ *
* Return false if $sql is "invalid sql", otherwise return true
*
* @param resource $connection
+ * @param string $sql
+ * @param array $options
+ * @return bool
*/
-function db2_prepare($connection, string $sql, array $options = []): bool
+function db2_prepare($connection, $sql, $options = [])
{
if ($sql === 'INVALID SQL') {
// db2_prepare issues a warning with invalid SQL
@@ -26,9 +30,13 @@ function db2_prepare($connection, string $sql, array $options = []): bool
/**
* Mock db2_stmt_errormsg
+ *
* If you pass a string to $stmt, it will be returned to you
+ *
+ * @param mixed $stmt
+ * @return string
*/
-function db2_stmt_errormsg(mixed $stmt = null): string
+function db2_stmt_errormsg($stmt = null)
{
if (is_string($stmt)) {
return $stmt;
@@ -39,9 +47,13 @@ function db2_stmt_errormsg(mixed $stmt = null): string
/**
* Mock db2_stmt_error
+ *
* If you pass a string to $stmt, it will be returned to you
+ *
+ * @param mixed $stmt
+ * @return string
*/
-function db2_stmt_error(mixed $stmt = null): string
+function db2_stmt_error($stmt = null)
{
if (is_string($stmt)) {
return $stmt;
diff --git a/test/unit/Adapter/Driver/Mysqli/ConnectionTest.php b/test/unit/Adapter/Driver/Mysqli/ConnectionTest.php
index 0236fe5c6..5ccbb0b6c 100644
--- a/test/unit/Adapter/Driver/Mysqli/ConnectionTest.php
+++ b/test/unit/Adapter/Driver/Mysqli/ConnectionTest.php
@@ -5,8 +5,6 @@
use Laminas\Db\Adapter\Driver\Mysqli\Connection;
use Laminas\Db\Adapter\Driver\Mysqli\Mysqli;
use Laminas\Db\Adapter\Exception\RuntimeException;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
@@ -15,18 +13,15 @@
use const MYSQLI_CLIENT_SSL;
use const MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
-#[CoversMethod(Connection::class, 'setDriver')]
-#[CoversMethod(Connection::class, 'setConnectionParameters')]
-#[CoversMethod(Connection::class, 'getConnectionParameters')]
-final class ConnectionTest extends TestCase
+class ConnectionTest extends TestCase
{
- protected Connection $connection;
+ /** @var Connection */
+ protected $connection;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) {
@@ -43,23 +38,32 @@ protected function tearDown(): void
{
}
- public function testSetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Mysqli\Connection::setDriver
+ */
+ public function testSetDriver()
{
self::assertEquals($this->connection, $this->connection->setDriver(new Mysqli([])));
}
- public function testSetConnectionParameters(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Mysqli\Connection::setConnectionParameters
+ */
+ public function testSetConnectionParameters()
{
self::assertEquals($this->connection, $this->connection->setConnectionParameters([]));
}
- public function testGetConnectionParameters(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Mysqli\Connection::getConnectionParameters
+ */
+ public function testGetConnectionParameters()
{
$this->connection->setConnectionParameters(['foo' => 'bar']);
self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters());
}
- public function testNonSecureConnection(): void
+ public function testNonSecureConnection()
{
$mysqli = $this->createMockMysqli(0);
$connection = $this->createMockConnection(
@@ -76,7 +80,7 @@ public function testNonSecureConnection(): void
$connection->connect();
}
- public function testSslConnection(): void
+ public function testSslConnection()
{
$mysqli = $this->createMockMysqli(MYSQLI_CLIENT_SSL);
$connection = $this->createMockConnection(
@@ -94,7 +98,7 @@ public function testSslConnection(): void
$connection->connect();
}
- public function testSslConnectionNoVerify(): void
+ public function testSslConnectionNoVerify()
{
$mysqli = $this->createMockMysqli(MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
$connection = $this->createMockConnection(
@@ -115,7 +119,7 @@ public function testSslConnectionNoVerify(): void
$connection->connect();
}
- public function testConnectionFails(): void
+ public function testConnectionFails()
{
$connection = new Connection([]);
@@ -128,8 +132,9 @@ public function testConnectionFails(): void
* Create a mock mysqli
*
* @param int $flags Expected flags to real_connect
+ * @return MockObject
*/
- protected function createMockMysqli(int $flags): MockObject
+ protected function createMockMysqli($flags)
{
$mysqli = $this->getMockBuilder(\mysqli::class)->getMock();
$mysqli->expects($flags ? $this->once() : $this->never())
@@ -178,12 +183,13 @@ protected function createMockMysqli(int $flags): MockObject
* Create a mock connection
*
* @param MockObject $mysqli Mock mysqli object
- * @param array $params Connection params
+ * @param array $params Connection params
+ * @return MockObject
*/
- protected function createMockConnection(MockObject $mysqli, array $params): MockObject
+ protected function createMockConnection($mysqli, $params)
{
$connection = $this->getMockBuilder(Connection::class)
- ->onlyMethods(['createResource'])
+ ->setMethods(['createResource'])
->setConstructorArgs([$params])
->getMock();
$connection->expects($this->once())
diff --git a/test/unit/Adapter/Driver/Oci8/AbstractIntegrationTestCase.php b/test/unit/Adapter/Driver/Oci8/AbstractIntegrationTest.php
similarity index 88%
rename from test/unit/Adapter/Driver/Oci8/AbstractIntegrationTestCase.php
rename to test/unit/Adapter/Driver/Oci8/AbstractIntegrationTest.php
index 9dce72831..1b8023f3b 100644
--- a/test/unit/Adapter/Driver/Oci8/AbstractIntegrationTestCase.php
+++ b/test/unit/Adapter/Driver/Oci8/AbstractIntegrationTest.php
@@ -2,16 +2,15 @@
namespace LaminasTest\Db\Adapter\Driver\Oci8;
-use Override;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
use function getenv;
-abstract class AbstractIntegrationTestCase extends TestCase
+abstract class AbstractIntegrationTest extends TestCase
{
/** @var array */
- protected string|array|false $variables = [
+ protected $variables = [
'hostname' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_HOSTNAME',
'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_USERNAME',
'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_PASSWORD',
@@ -21,7 +20,6 @@ abstract class AbstractIntegrationTestCase extends TestCase
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
foreach ($this->variables as $name => $value) {
diff --git a/test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php b/test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php
index 260f5ec86..05baf04f6 100644
--- a/test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php
@@ -5,34 +5,28 @@
use Laminas\Db\Adapter\Driver\Oci8\Connection;
use Laminas\Db\Adapter\Driver\Oci8\Oci8;
use Laminas\Db\Adapter\Driver\Oci8\Result;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
-
-#[CoversMethod(Connection::class, 'getCurrentSchema')]
-#[CoversMethod(Connection::class, 'setResource')]
-#[CoversMethod(Connection::class, 'getResource')]
-#[CoversMethod(Connection::class, 'connect')]
-#[CoversMethod(Connection::class, 'isConnected')]
-#[CoversMethod(Connection::class, 'disconnect')]
-#[CoversMethod(Connection::class, 'beginTransaction')]
-#[CoversMethod(Connection::class, 'commit')]
-#[CoversMethod(Connection::class, 'rollback')]
-#[CoversMethod(Connection::class, 'execute')]
-#[CoversMethod(Connection::class, 'getLastGeneratedValue')]
-#[Group('integration')]
-#[Group('integration-oracle')]
-final class ConnectionIntegrationTest extends AbstractIntegrationTestCase
+
+/**
+ * @group integration
+ * @group integration-oracle
+ */
+class ConnectionIntegrationTest extends AbstractIntegrationTest
{
- public function testGetCurrentSchema(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::getCurrentSchema
+ */
+ public function testGetCurrentSchema()
{
$connection = new Connection($this->variables);
self::assertInternalType('string', $connection->getCurrentSchema());
}
- public function testSetResource(): never
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::setResource
+ */
+ public function testSetResource()
{
$this->markTestIncomplete('edit this');
- /*
$resource = oci_connect(
$this->variables['username'],
$this->variables['password'],
@@ -45,10 +39,12 @@ public function testSetResource(): never
$connection->disconnect();
unset($connection);
unset($resource);
- */
}
- public function testGetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::getResource
+ */
+ public function testGetResource()
{
$connection = new Connection($this->variables);
$connection->connect();
@@ -58,7 +54,10 @@ public function testGetResource(): void
unset($connection);
}
- public function testConnect(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::connect
+ */
+ public function testConnect()
{
$connection = new Connection($this->variables);
self::assertSame($connection, $connection->connect());
@@ -68,7 +67,10 @@ public function testConnect(): void
unset($connection);
}
- public function testIsConnected(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::isConnected
+ */
+ public function testIsConnected()
{
$connection = new Connection($this->variables);
self::assertFalse($connection->isConnected());
@@ -79,7 +81,10 @@ public function testIsConnected(): void
unset($connection);
}
- public function testDisconnect(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::disconnect
+ */
+ public function testDisconnect()
{
$connection = new Connection($this->variables);
$connection->connect();
@@ -89,9 +94,10 @@ public function testDisconnect(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::beginTransaction
* @todo Implement testBeginTransaction().
*/
- public function testBeginTransaction(): never
+ public function testBeginTransaction()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -100,9 +106,10 @@ public function testBeginTransaction(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::commit
* @todo Implement testCommit().
*/
- public function testCommit(): never
+ public function testCommit()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -111,9 +118,10 @@ public function testCommit(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::rollback
* @todo Implement testRollback().
*/
- public function testRollback(): never
+ public function testRollback()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -121,7 +129,10 @@ public function testRollback(): never
);
}
- public function testExecute(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::execute
+ */
+ public function testExecute()
{
$oci8 = new Oci8($this->variables);
$connection = $oci8->getConnection();
@@ -130,20 +141,22 @@ public function testExecute(): void
self::assertInstanceOf(Result::class, $result);
}
- public function testGetLastGeneratedValue(): never
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::getLastGeneratedValue
+ */
+ public function testGetLastGeneratedValue()
{
$this->markTestIncomplete('Need to create a temporary sequence.');
- /*
$connection = new Connection($this->variables);
$connection->getLastGeneratedValue();
- */
}
- #[Group('laminas3469')]
- public function testConnectReturnsConnectionWhenResourceSet(): never
+ /**
+ * @group laminas3469
+ */
+ public function testConnectReturnsConnectionWhenResourceSet()
{
$this->markTestIncomplete('edit this');
- /*
$resource = oci_connect(
$this->variables['username'],
$this->variables['password'],
@@ -157,6 +170,5 @@ public function testConnectReturnsConnectionWhenResourceSet(): never
$connection->disconnect();
unset($connection);
unset($resource);
- */
}
}
diff --git a/test/unit/Adapter/Driver/Oci8/ConnectionTest.php b/test/unit/Adapter/Driver/Oci8/ConnectionTest.php
index f91c1b75f..5d6777b3f 100644
--- a/test/unit/Adapter/Driver/Oci8/ConnectionTest.php
+++ b/test/unit/Adapter/Driver/Oci8/ConnectionTest.php
@@ -4,22 +4,17 @@
use Laminas\Db\Adapter\Driver\Oci8\Connection;
use Laminas\Db\Adapter\Driver\Oci8\Oci8;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Connection::class, 'setDriver')]
-#[CoversMethod(Connection::class, 'setConnectionParameters')]
-#[CoversMethod(Connection::class, 'getConnectionParameters')]
-final class ConnectionTest extends TestCase
+class ConnectionTest extends TestCase
{
- protected Connection $connection;
+ /** @var Connection */
+ protected $connection;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->connection = new Connection([]);
@@ -33,17 +28,26 @@ protected function tearDown(): void
{
}
- public function testSetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::setDriver
+ */
+ public function testSetDriver()
{
self::assertEquals($this->connection, $this->connection->setDriver(new Oci8([])));
}
- public function testSetConnectionParameters(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::setConnectionParameters
+ */
+ public function testSetConnectionParameters()
{
self::assertEquals($this->connection, $this->connection->setConnectionParameters([]));
}
- public function testGetConnectionParameters(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::getConnectionParameters
+ */
+ public function testGetConnectionParameters()
{
$this->connection->setConnectionParameters(['foo' => 'bar']);
self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters());
diff --git a/test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php b/test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php
index 3f10994e1..d79912bc1 100644
--- a/test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php
+++ b/test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php
@@ -6,33 +6,32 @@
use Laminas\Db\Adapter\Driver\ConnectionInterface;
use Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter;
use Laminas\Db\Adapter\Driver\Oci8\Oci8;
-use Laminas\Db\Adapter\Driver\Oci8\Result;
use Laminas\Db\Adapter\Driver\Oci8\Statement;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(RowCounter::class, 'getName')]
-#[CoversMethod(RowCounter::class, 'getCountForStatement')]
-#[CoversMethod(RowCounter::class, 'getCountForSql')]
-#[CoversMethod(RowCounter::class, 'getRowCountClosure')]
-final class RowCounterTest extends TestCase
+class RowCounterTest extends TestCase
{
- protected RowCounter $rowCounter;
+ /** @var RowCounter */
+ protected $rowCounter;
- #[Override]
protected function setUp(): void
{
$this->rowCounter = new RowCounter();
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter::getName
+ */
+ public function testGetName()
{
self::assertEquals('RowCounter', $this->rowCounter->getName());
}
- public function testGetCountForStatement(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter::getCountForStatement
+ */
+ public function testGetCountForStatement()
{
$statement = $this->getMockStatement('SELECT XXX', 5);
$statement->expects($this->once())
@@ -42,14 +41,20 @@ public function testGetCountForStatement(): void
self::assertEquals(5, $count);
}
- public function testGetCountForSql(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter::getCountForSql
+ */
+ public function testGetCountForSql()
{
$this->rowCounter->setDriver($this->getMockDriver(5));
$count = $this->rowCounter->getCountForSql('SELECT XXX');
self::assertEquals(5, $count);
}
- public function testGetRowCountClosure(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter::getRowCountClosure
+ */
+ public function testGetRowCountClosure()
{
$stmt = $this->getMockStatement('SELECT XXX', 5);
/** @var Closure $closure */
@@ -59,53 +64,55 @@ public function testGetRowCountClosure(): void
}
/**
- * @psalm-param 5 $returnValue
+ * @param string $sql
+ * @param mixed $returnValue
+ * @return Statement&MockObject
*/
- protected function getMockStatement(string $sql, int $returnValue): MockObject&Statement
+ protected function getMockStatement($sql, $returnValue)
{
$statement = $this->getMockBuilder(Statement::class)
- ->onlyMethods(['prepare', 'execute'])
+ ->setMethods(['prepare', 'execute'])
->disableOriginalConstructor()
->getMock();
// mock the result
- $result = $this->getMockBuilder(Result::class)
- ->onlyMethods(['current'])
+ $result = $this->getMockBuilder('stdClass')
+ ->setMethods(['current'])
->getMock();
- $result->expects($this->any())
+ $result->expects($this->once())
->method('current')
- ->willReturn(['count' => $returnValue]);
-
+ ->will($this->returnValue(['count' => $returnValue]));
$statement->setSql($sql);
- $statement->expects($this->any())
+ $statement->expects($this->once())
->method('execute')
- ->willReturn($result);
+ ->will($this->returnValue($result));
return $statement;
}
/**
- * @psalm-param 5 $returnValue
+ * @param mixed $returnValue
+ * @return Oci8&MockObject
*/
- protected function getMockDriver(int $returnValue): Oci8&MockObject
+ protected function getMockDriver($returnValue)
{
- $oci8Statement = $this->getMockBuilder(Result::class)
- ->onlyMethods(['current'])
+ $oci8Statement = $this->getMockBuilder('stdClass')
+ ->setMethods(['current'])
->disableOriginalConstructor()
->getMock(); // stdClass can be used here
$oci8Statement->expects($this->once())
->method('current')
- ->willReturn(['count' => $returnValue]);
+ ->will($this->returnValue(['count' => $returnValue]));
$connection = $this->getMockBuilder(ConnectionInterface::class)->getMock();
$connection->expects($this->once())
->method('execute')
- ->willReturn($oci8Statement);
+ ->will($this->returnValue($oci8Statement));
$driver = $this->getMockBuilder(Oci8::class)
- ->onlyMethods(['getConnection'])
+ ->setMethods(['getConnection'])
->disableOriginalConstructor()
->getMock();
$driver->expects($this->once())
->method('getConnection')
- ->willReturn($connection);
+ ->will($this->returnValue($connection));
return $driver;
}
}
diff --git a/test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php b/test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php
index 82d0bcd33..4e9377387 100644
--- a/test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php
+++ b/test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php
@@ -5,23 +5,25 @@
use Laminas\Db\Adapter\Driver\Oci8\Oci8;
use Laminas\Db\Adapter\Driver\Oci8\Statement;
use Laminas\Db\Adapter\Exception\InvalidArgumentException;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use stdClass;
-#[CoversMethod(Oci8::class, 'checkEnvironment')]
-#[Group('integration')]
-#[Group('integration-oracle')]
-class Oci8IntegrationTest extends AbstractIntegrationTestCase
+/**
+ * @group integration
+ * @group integration-oracle
+ */
+class Oci8IntegrationTest extends AbstractIntegrationTest
{
- #[Group('integration-oci8')]
- public function testCheckEnvironment(): void
+ /**
+ * @group integration-oci8
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::checkEnvironment
+ */
+ public function testCheckEnvironment()
{
$sqlserver = new Oci8([]);
self::assertNull($sqlserver->checkEnvironment());
}
- public function testCreateStatement(): void
+ public function testCreateStatement()
{
$driver = new Oci8([]);
$resource = oci_connect(
diff --git a/test/unit/Adapter/Driver/Oci8/Oci8Test.php b/test/unit/Adapter/Driver/Oci8/Oci8Test.php
index 4182dd97c..2465ec60f 100644
--- a/test/unit/Adapter/Driver/Oci8/Oci8Test.php
+++ b/test/unit/Adapter/Driver/Oci8/Oci8Test.php
@@ -6,76 +6,92 @@
use Laminas\Db\Adapter\Driver\Oci8\Oci8;
use Laminas\Db\Adapter\Driver\Oci8\Result;
use Laminas\Db\Adapter\Driver\Oci8\Statement;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Depends;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Oci8::class, 'registerConnection')]
-#[CoversMethod(Oci8::class, 'registerStatementPrototype')]
-#[CoversMethod(Oci8::class, 'registerResultPrototype')]
-#[CoversMethod(Oci8::class, 'getDatabasePlatformName')]
-#[CoversMethod(Oci8::class, 'getConnection')]
-#[CoversMethod(Oci8::class, 'createStatement')]
-#[CoversMethod(Oci8::class, 'createResult')]
-#[CoversMethod(Oci8::class, 'getPrepareType')]
-#[CoversMethod(Oci8::class, 'formatParameterName')]
-#[CoversMethod(Oci8::class, 'getLastGeneratedValue')]
-final class Oci8Test extends TestCase
+class Oci8Test extends TestCase
{
- protected Oci8 $oci8;
+ /** @var Oci8 */
+ protected $oci8;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->oci8 = new Oci8([]);
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::registerConnection
*/
- public function testRegisterConnection(): void
+ public function testRegisterConnection()
{
- $mockConnection = $this->getMockBuilder(Connection::class)->setConstructorArgs([[]])->onlyMethods(['setDriver'])->getMock();
+ $mockConnection = $this->getMockForAbstractClass(
+ Connection::class,
+ [[]],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
$mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->oci8));
self::assertSame($this->oci8, $this->oci8->registerConnection($mockConnection));
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::registerStatementPrototype
*/
- public function testRegisterStatementPrototype(): void
+ public function testRegisterStatementPrototype()
{
$this->oci8 = new Oci8([]);
- $mockStatement = $this->getMockBuilder(Statement::class)->setConstructorArgs([])->onlyMethods(['setDriver'])->getMock();
+ $mockStatement = $this->getMockForAbstractClass(
+ Statement::class,
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
$mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->oci8));
self::assertSame($this->oci8, $this->oci8->registerStatementPrototype($mockStatement));
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::registerResultPrototype
*/
- public function testRegisterResultPrototype(): void
+ public function testRegisterResultPrototype()
{
$this->oci8 = new Oci8([]);
- $mockStatement = $this->getMockBuilder(Result::class)->setConstructorArgs([])->onlyMethods([])->getMock();
+ $mockStatement = $this->getMockForAbstractClass(
+ Result::class,
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
self::assertSame($this->oci8, $this->oci8->registerResultPrototype($mockStatement));
}
- public function testGetDatabasePlatformName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::getDatabasePlatformName
+ */
+ public function testGetDatabasePlatformName()
{
$this->oci8 = new Oci8([]);
self::assertEquals('Oracle', $this->oci8->getDatabasePlatformName());
self::assertEquals('Oracle', $this->oci8->getDatabasePlatformName(Oci8::NAME_FORMAT_NATURAL));
}
- #[Depends('testRegisterConnection')]
- public function testGetConnection(): void
+ /**
+ * @depends testRegisterConnection
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::getConnection
+ */
+ public function testGetConnection()
{
$conn = new Connection([]);
$this->oci8->registerConnection($conn);
@@ -83,9 +99,10 @@ public function testGetConnection(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::createStatement
* @todo Implement testGetPrepareType().
*/
- public function testCreateStatement(): never
+ public function testCreateStatement()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -94,9 +111,10 @@ public function testCreateStatement(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::createResult
* @todo Implement testGetPrepareType().
*/
- public function testCreateResult(): never
+ public function testCreateResult()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -105,9 +123,10 @@ public function testCreateResult(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::getPrepareType
* @todo Implement testGetPrepareType().
*/
- public function testGetPrepareType(): never
+ public function testGetPrepareType()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -116,9 +135,10 @@ public function testGetPrepareType(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::formatParameterName
* @todo Implement testFormatParameterName().
*/
- public function testFormatParameterName(): never
+ public function testFormatParameterName()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -127,9 +147,10 @@ public function testFormatParameterName(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::getLastGeneratedValue
* @todo Implement testGetLastGeneratedValue().
*/
- public function testGetLastGeneratedValue(): never
+ public function testGetLastGeneratedValue()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
diff --git a/test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php b/test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php
index a169bf99b..ff3283bb2 100644
--- a/test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php
@@ -3,35 +3,21 @@
namespace LaminasTest\Db\Adapter\Driver\Oci8;
use Laminas\Db\Adapter\Driver\Oci8\Result;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Result::class, 'initialize')]
-#[CoversMethod(Result::class, 'buffer')]
-#[CoversMethod(Result::class, 'getResource')]
-#[CoversMethod(Result::class, 'current')]
-#[CoversMethod(Result::class, 'next')]
-#[CoversMethod(Result::class, 'key')]
-#[CoversMethod(Result::class, 'rewind')]
-#[CoversMethod(Result::class, 'valid')]
-#[CoversMethod(Result::class, 'count')]
-#[CoversMethod(Result::class, 'getFieldCount')]
-#[CoversMethod(Result::class, 'isQueryResult')]
-#[CoversMethod(Result::class, 'getAffectedRows')]
-#[CoversMethod(Result::class, 'getGeneratedValue')]
-#[Group('integration')]
-#[Group('integration-oracle')]
-final class ResultIntegrationTest extends TestCase
+/**
+ * @group integration
+ * @group integration-oracle
+ */
+class ResultIntegrationTest extends TestCase
{
- protected Result $object;
+ /** @var Result */
+ protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->object = new Result();
@@ -46,9 +32,10 @@ protected function tearDown(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::initialize
* @todo Implement testInitialize().
*/
- public function testInitialize(): never
+ public function testInitialize()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -57,9 +44,10 @@ public function testInitialize(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::buffer
* @todo Implement testBuffer().
*/
- public function testBuffer(): never
+ public function testBuffer()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -68,9 +56,10 @@ public function testBuffer(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getResource
* @todo Implement testGetResource().
*/
- public function testGetResource(): never
+ public function testGetResource()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -79,9 +68,10 @@ public function testGetResource(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::current
* @todo Implement testCurrent().
*/
- public function testCurrent(): never
+ public function testCurrent()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -90,9 +80,10 @@ public function testCurrent(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::next
* @todo Implement testNext().
*/
- public function testNext(): never
+ public function testNext()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -101,9 +92,10 @@ public function testNext(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::key
* @todo Implement testKey().
*/
- public function testKey(): never
+ public function testKey()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -112,9 +104,10 @@ public function testKey(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::rewind
* @todo Implement testRewind().
*/
- public function testRewind(): never
+ public function testRewind()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -123,9 +116,10 @@ public function testRewind(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::valid
* @todo Implement testValid().
*/
- public function testValid(): never
+ public function testValid()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -134,9 +128,10 @@ public function testValid(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::count
* @todo Implement testCount().
*/
- public function testCount(): never
+ public function testCount()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -145,9 +140,10 @@ public function testCount(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getFieldCount
* @todo Implement testGetFieldCount().
*/
- public function testGetFieldCount(): never
+ public function testGetFieldCount()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -156,9 +152,10 @@ public function testGetFieldCount(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::isQueryResult
* @todo Implement testIsQueryResult().
*/
- public function testIsQueryResult(): never
+ public function testIsQueryResult()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -167,9 +164,10 @@ public function testIsQueryResult(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getAffectedRows
* @todo Implement testGetAffectedRows().
*/
- public function testGetAffectedRows(): never
+ public function testGetAffectedRows()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -178,9 +176,10 @@ public function testGetAffectedRows(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getGeneratedValue
* @todo Implement testGetGeneratedValue().
*/
- public function testGetGeneratedValue(): never
+ public function testGetGeneratedValue()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
diff --git a/test/unit/Adapter/Driver/Oci8/ResultTest.php b/test/unit/Adapter/Driver/Oci8/ResultTest.php
index fc085d276..6d0c8226a 100644
--- a/test/unit/Adapter/Driver/Oci8/ResultTest.php
+++ b/test/unit/Adapter/Driver/Oci8/ResultTest.php
@@ -3,54 +3,65 @@
namespace LaminasTest\Db\Adapter\Driver\Oci8;
use Laminas\Db\Adapter\Driver\Oci8\Result;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Result::class, 'getResource')]
-#[CoversMethod(Result::class, 'buffer')]
-#[CoversMethod(Result::class, 'isBuffered')]
-#[CoversMethod(Result::class, 'getGeneratedValue')]
-#[CoversMethod(Result::class, 'key')]
-#[CoversMethod(Result::class, 'next')]
-#[CoversMethod(Result::class, 'rewind')]
-#[Group('result-oci8')]
-final class ResultTest extends TestCase
+/**
+ * @group result-oci8
+ */
+class ResultTest extends TestCase
{
- public function testGetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getResource
+ */
+ public function testGetResource()
{
$result = new Result();
self::assertNull($result->getResource());
}
- public function testBuffer(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::buffer
+ */
+ public function testBuffer()
{
$result = new Result();
self::assertNull($result->buffer());
}
- public function testIsBuffered(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::isBuffered
+ */
+ public function testIsBuffered()
{
$result = new Result();
self::assertFalse($result->isBuffered());
}
- public function testGetGeneratedValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getGeneratedValue
+ */
+ public function testGetGeneratedValue()
{
$result = new Result();
self::assertNull($result->getGeneratedValue());
}
- public function testKey(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::key
+ */
+ public function testKey()
{
$result = new Result();
self::assertEquals(0, $result->key());
}
- public function testNext(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::next
+ */
+ public function testNext()
{
$mockResult = $this->getMockBuilder(Result::class)
- ->onlyMethods(['loadData'])
+ ->setMethods(['loadData'])
->getMock();
$mockResult->expects($this->any())
->method('loadData')
@@ -58,7 +69,10 @@ public function testNext(): void
self::assertNull($mockResult->next());
}
- public function testRewind(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::rewind
+ */
+ public function testRewind()
{
$result = new Result();
self::assertNull($result->rewind());
diff --git a/test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php b/test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php
index bd4ee18f9..e5ebb44b3 100644
--- a/test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php
@@ -5,26 +5,20 @@
use Laminas\Db\Adapter\Driver\Oci8\Oci8;
use Laminas\Db\Adapter\Driver\Oci8\Result;
use Laminas\Db\Adapter\Driver\Oci8\Statement;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
use function get_resource_type;
use function getenv;
-#[CoversMethod(Statement::class, 'initialize')]
-#[CoversMethod(Statement::class, 'getResource')]
-#[CoversMethod(Statement::class, 'prepare')]
-#[CoversMethod(Statement::class, 'isPrepared')]
-#[CoversMethod(Statement::class, 'execute')]
-#[Group('integration')]
-#[Group('integration-oracle')]
-final class StatementIntegrationTest extends TestCase
+/**
+ * @group integration
+ * @group integration-oracle
+ */
+class StatementIntegrationTest extends TestCase
{
/** @var array */
- protected string|array|false $variables = [
+ protected $variables = [
'hostname' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_HOSTNAME',
'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_USERNAME',
'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_PASSWORD',
@@ -34,7 +28,6 @@ final class StatementIntegrationTest extends TestCase
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
foreach ($this->variables as $name => $value) {
@@ -51,7 +44,10 @@ protected function setUp(): void
}
}
- public function testInitialize(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::initialize
+ */
+ public function testInitialize()
{
$ociResource = oci_connect(
$this->variables['username'],
@@ -64,7 +60,10 @@ public function testInitialize(): void
unset($stmtResource, $ociResource);
}
- public function testGetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getResource
+ */
+ public function testGetResource()
{
$ociResource = oci_connect(
$this->variables['username'],
@@ -80,7 +79,11 @@ public function testGetResource(): void
unset($resource, $ociResource);
}
- public function testPrepare(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::prepare
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::isPrepared
+ */
+ public function testPrepare()
{
$ociResource = oci_connect(
$this->variables['username'],
@@ -96,7 +99,10 @@ public function testPrepare(): void
unset($resource, $ociResource);
}
- public function testExecute(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::execute
+ */
+ public function testExecute()
{
$oci8 = new Oci8($this->variables);
$statement = $oci8->createStatement('SELECT * FROM DUAL');
diff --git a/test/unit/Adapter/Driver/Oci8/StatementTest.php b/test/unit/Adapter/Driver/Oci8/StatementTest.php
index 493e98638..66a87dcd0 100644
--- a/test/unit/Adapter/Driver/Oci8/StatementTest.php
+++ b/test/unit/Adapter/Driver/Oci8/StatementTest.php
@@ -6,33 +6,20 @@
use Laminas\Db\Adapter\Driver\Oci8\Statement;
use Laminas\Db\Adapter\ParameterContainer;
use Laminas\Db\Adapter\Profiler\Profiler;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Statement::class, 'setDriver')]
-#[CoversMethod(Statement::class, 'setProfiler')]
-#[CoversMethod(Statement::class, 'getProfiler')]
-#[CoversMethod(Statement::class, 'initialize')]
-#[CoversMethod(Statement::class, 'setSql')]
-#[CoversMethod(Statement::class, 'setParameterContainer')]
-#[CoversMethod(Statement::class, 'getParameterContainer')]
-#[CoversMethod(Statement::class, 'getResource')]
-#[CoversMethod(Statement::class, 'getSql')]
-#[CoversMethod(Statement::class, 'prepare')]
-#[CoversMethod(Statement::class, 'isPrepared')]
-#[CoversMethod(Statement::class, 'execute')]
-#[Group('integrationOracle')]
-final class StatementTest extends TestCase
+/**
+ * @group integrationOracle
+ */
+class StatementTest extends TestCase
{
- protected Statement $statement;
+ /** @var Statement */
+ protected $statement;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->statement = new Statement();
@@ -46,44 +33,63 @@ protected function tearDown(): void
{
}
- public function testSetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::setDriver
+ */
+ public function testSetDriver()
{
self::assertEquals($this->statement, $this->statement->setDriver(new Oci8([])));
}
- public function testSetProfiler(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::setProfiler
+ */
+ public function testSetProfiler()
{
self::assertEquals($this->statement, $this->statement->setProfiler(new Profiler()));
}
- public function testGetProfiler(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getProfiler
+ */
+ public function testGetProfiler()
{
$profiler = new Profiler();
$this->statement->setProfiler($profiler);
self::assertEquals($profiler, $this->statement->getProfiler());
}
- public function testInitialize(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::initialize
+ */
+ public function testInitialize()
{
$oci8 = new Oci8([]);
self::assertEquals($this->statement, $this->statement->initialize($oci8));
}
- public function testSetSql(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::setSql
+ */
+ public function testSetSql()
{
self::assertEquals($this->statement, $this->statement->setSql('select * from table'));
self::assertEquals('select * from table', $this->statement->getSql());
}
- public function testSetParameterContainer(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::setParameterContainer
+ */
+ public function testSetParameterContainer()
{
self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer()));
}
/**
- * @todo Implement testGetParameterContainer().
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getParameterContainer
+ * @todo Implement testGetParameterContainer().
*/
- public function testGetParameterContainer(): void
+ public function testGetParameterContainer()
{
$container = new ParameterContainer();
$this->statement->setParameterContainer($container);
@@ -91,9 +97,10 @@ public function testGetParameterContainer(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getResource
* @todo Implement testGetResource().
*/
- public function testGetResource(): never
+ public function testGetResource()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -102,18 +109,20 @@ public function testGetResource(): never
}
/**
- * @todo Implement testGetSql().
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getSql
+ * @todo Implement testGetSql().
*/
- public function testGetSql(): void
+ public function testGetSql()
{
self::assertEquals($this->statement, $this->statement->setSql('select * from table'));
self::assertEquals('select * from table', $this->statement->getSql());
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::prepare
* @todo Implement testPrepare().
*/
- public function testPrepare(): never
+ public function testPrepare()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -121,15 +130,19 @@ public function testPrepare(): never
);
}
- public function testIsPrepared(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::isPrepared
+ */
+ public function testIsPrepared()
{
self::assertFalse($this->statement->isPrepared());
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::execute
* @todo Implement testExecute().
*/
- public function testExecute(): never
+ public function testExecute()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
diff --git a/test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php b/test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php
index b368bc189..f68bcbddd 100644
--- a/test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php
@@ -6,36 +6,30 @@
use Laminas\Db\Adapter\Driver\Pdo\Pdo;
use Laminas\Db\Adapter\Driver\Pdo\Result;
use Laminas\Db\Adapter\Driver\Pdo\Statement;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Connection::class, 'getCurrentSchema')]
-#[CoversMethod(Connection::class, 'setResource')]
-#[CoversMethod(Connection::class, 'getResource')]
-#[CoversMethod(Connection::class, 'connect')]
-#[CoversMethod(Connection::class, 'isConnected')]
-#[CoversMethod(Connection::class, 'disconnect')]
-#[CoversMethod(Connection::class, 'beginTransaction')]
-#[CoversMethod(Connection::class, 'commit')]
-#[CoversMethod(Connection::class, 'rollback')]
-#[CoversMethod(Connection::class, 'execute')]
-#[CoversMethod(Connection::class, 'prepare')]
-#[CoversMethod(Connection::class, 'getLastGeneratedValue')]
-#[Group('integration')]
-#[Group('integration-pdo')]
-final class ConnectionIntegrationTest extends TestCase
+/**
+ * @group integration
+ * @group integration-pdo
+ */
+class ConnectionIntegrationTest extends TestCase
{
/** @var array */
- protected array $variables = ['pdodriver' => 'sqlite', 'database' => ':memory:'];
+ protected $variables = ['pdodriver' => 'sqlite', 'database' => ':memory:'];
- public function testGetCurrentSchema(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getCurrentSchema
+ */
+ public function testGetCurrentSchema()
{
$connection = new Connection($this->variables);
self::assertIsString($connection->getCurrentSchema());
}
- public function testSetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::setResource
+ */
+ public function testSetResource()
{
$resource = new TestAsset\SqliteMemoryPdo();
$connection = new Connection([]);
@@ -46,7 +40,10 @@ public function testSetResource(): void
unset($resource);
}
- public function testGetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getResource
+ */
+ public function testGetResource()
{
$connection = new Connection($this->variables);
$connection->connect();
@@ -56,7 +53,10 @@ public function testGetResource(): void
unset($connection);
}
- public function testConnect(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::connect
+ */
+ public function testConnect()
{
$connection = new Connection($this->variables);
self::assertSame($connection, $connection->connect());
@@ -66,7 +66,10 @@ public function testConnect(): void
unset($connection);
}
- public function testIsConnected(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::isConnected
+ */
+ public function testIsConnected()
{
$connection = new Connection($this->variables);
self::assertFalse($connection->isConnected());
@@ -77,7 +80,10 @@ public function testIsConnected(): void
unset($connection);
}
- public function testDisconnect(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::disconnect
+ */
+ public function testDisconnect()
{
$connection = new Connection($this->variables);
$connection->connect();
@@ -87,9 +93,10 @@ public function testDisconnect(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction
* @todo Implement testBeginTransaction().
*/
- public function testBeginTransaction(): never
+ public function testBeginTransaction()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -98,9 +105,10 @@ public function testBeginTransaction(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit
* @todo Implement testCommit().
*/
- public function testCommit(): never
+ public function testCommit()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -109,9 +117,10 @@ public function testCommit(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback
* @todo Implement testRollback().
*/
- public function testRollback(): never
+ public function testRollback()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -119,7 +128,10 @@ public function testRollback(): never
);
}
- public function testExecute(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::execute
+ */
+ public function testExecute()
{
$sqlsrv = new Pdo($this->variables);
$connection = $sqlsrv->getConnection();
@@ -128,7 +140,10 @@ public function testExecute(): void
self::assertInstanceOf(Result::class, $result);
}
- public function testPrepare(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::prepare
+ */
+ public function testPrepare()
{
$sqlsrv = new Pdo($this->variables);
$connection = $sqlsrv->getConnection();
@@ -137,15 +152,20 @@ public function testPrepare(): void
self::assertInstanceOf(Statement::class, $statement);
}
- public function testGetLastGeneratedValue(): never
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getLastGeneratedValue
+ */
+ public function testGetLastGeneratedValue()
{
$this->markTestIncomplete('Need to create a temporary sequence.');
- //$connection = new Connection($this->variables);
- //$connection->getLastGeneratedValue();
+ $connection = new Connection($this->variables);
+ $connection->getLastGeneratedValue();
}
- #[Group('laminas3469')]
- public function testConnectReturnsConnectionWhenResourceSet(): void
+ /**
+ * @group laminas3469
+ */
+ public function testConnectReturnsConnectionWhenResourceSet()
{
$resource = new TestAsset\SqliteMemoryPdo();
$connection = new Connection([]);
diff --git a/test/unit/Adapter/Driver/Pdo/ConnectionTest.php b/test/unit/Adapter/Driver/Pdo/ConnectionTest.php
index 9fb41fe12..248610474 100644
--- a/test/unit/Adapter/Driver/Pdo/ConnectionTest.php
+++ b/test/unit/Adapter/Driver/Pdo/ConnectionTest.php
@@ -5,22 +5,17 @@
use Exception;
use Laminas\Db\Adapter\Driver\Pdo\Connection;
use Laminas\Db\Adapter\Exception\InvalidConnectionParametersException;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Connection::class, 'getResource')]
-#[CoversMethod(Connection::class, 'getDsn')]
-final class ConnectionTest extends TestCase
+class ConnectionTest extends TestCase
{
- protected Connection $connection;
+ /** @var Connection */
+ protected $connection;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->connection = new Connection();
@@ -28,8 +23,10 @@ protected function setUp(): void
/**
* Test getResource method tries to connect to the database, it should never return null
+ *
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getResource
*/
- public function testResource(): void
+ public function testResource()
{
$this->expectException(InvalidConnectionParametersException::class);
$this->connection->getResource();
@@ -37,22 +34,26 @@ public function testResource(): void
/**
* Test getConnectedDsn returns a DSN string if it has been set
+ *
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getDsn
*/
- public function testGetDsn(): void
+ public function testGetDsn()
{
$dsn = "sqlite::memory:";
$this->connection->setConnectionParameters(['dsn' => $dsn]);
try {
$this->connection->connect();
- } catch (Exception) {
+ } catch (Exception $e) {
}
$responseString = $this->connection->getDsn();
self::assertEquals($dsn, $responseString);
}
- #[Group('2622')]
- public function testArrayOfConnectionParametersCreatesCorrectDsn(): void
+ /**
+ * @group 2622
+ */
+ public function testArrayOfConnectionParametersCreatesCorrectDsn()
{
$this->connection->setConnectionParameters([
'driver' => 'pdo_mysql',
@@ -63,7 +64,7 @@ public function testArrayOfConnectionParametersCreatesCorrectDsn(): void
]);
try {
$this->connection->connect();
- } catch (Exception) {
+ } catch (Exception $e) {
}
$responseString = $this->connection->getDsn();
@@ -74,7 +75,7 @@ public function testArrayOfConnectionParametersCreatesCorrectDsn(): void
self::assertStringContainsString('unix_socket=/var/run/mysqld/mysqld.sock', $responseString);
}
- public function testHostnameAndUnixSocketThrowsInvalidConnectionParametersException(): void
+ public function testHostnameAndUnixSocketThrowsInvalidConnectionParametersException()
{
$this->expectException(InvalidConnectionParametersException::class);
$this->expectExceptionMessage(
@@ -91,7 +92,7 @@ public function testHostnameAndUnixSocketThrowsInvalidConnectionParametersExcept
$this->connection->connect();
}
- public function testDblibArrayOfConnectionParametersCreatesCorrectDsn(): void
+ public function testDblibArrayOfConnectionParametersCreatesCorrectDsn()
{
$this->connection->setConnectionParameters([
'driver' => 'pdo_dblib',
@@ -102,7 +103,7 @@ public function testDblibArrayOfConnectionParametersCreatesCorrectDsn(): void
]);
try {
$this->connection->connect();
- } catch (Exception) {
+ } catch (Exception $e) {
}
$responseString = $this->connection->getDsn();
diff --git a/test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php b/test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php
index b6cfe14d9..eb572d97c 100644
--- a/test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php
+++ b/test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php
@@ -2,56 +2,62 @@
namespace LaminasTest\Db\Adapter\Driver\Pdo;
-use Laminas\Db\Adapter\Driver\AbstractConnection;
use Laminas\Db\Adapter\Driver\Pdo\Connection;
use Laminas\Db\Adapter\Exception\RuntimeException;
use LaminasTest\Db\TestAsset\ConnectionWrapper;
-use Override;
-use PHPUnit\Framework\Attributes\CoversClass;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
/**
* Tests for {@see \Laminas\Db\Adapter\Driver\Pdo\Connection} transaction support
+ *
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection
+ * @covers \Laminas\Db\Adapter\Driver\AbstractConnection
*/
-#[CoversClass(Connection::class)]
-#[CoversClass(AbstractConnection::class)]
-#[CoversMethod(Connection::class, 'beginTransaction()')]
-#[CoversMethod(Connection::class, 'inTransaction()')]
-#[CoversMethod(Connection::class, 'commit()')]
-#[CoversMethod(Connection::class, 'rollback()')]
-final class ConnectionTransactionsTest extends TestCase
+class ConnectionTransactionsTest extends TestCase
{
/** @var Wrapper */
- protected Wrapper|ConnectionWrapper $wrapper;
+ protected $wrapper;
/**
* {@inheritDoc}
*/
- #[Override]
protected function setUp(): void
{
$this->wrapper = new ConnectionWrapper();
}
- public function testBeginTransactionReturnsInstanceOfConnection(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction()
+ */
+ public function testBeginTransactionReturnsInstanceOfConnection()
{
self::assertInstanceOf(Connection::class, $this->wrapper->beginTransaction());
}
- public function testBeginTransactionSetsInTransactionAtTrue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction()
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction()
+ */
+ public function testBeginTransactionSetsInTransactionAtTrue()
{
$this->wrapper->beginTransaction();
self::assertTrue($this->wrapper->inTransaction());
}
- public function testCommitReturnsInstanceOfConnection(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit()
+ */
+ public function testCommitReturnsInstanceOfConnection()
{
$this->wrapper->beginTransaction();
self::assertInstanceOf(Connection::class, $this->wrapper->commit());
}
- public function testCommitSetsInTransactionAtFalse(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit()
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction()
+ */
+ public function testCommitSetsInTransactionAtFalse()
{
$this->wrapper->beginTransaction();
$this->wrapper->commit();
@@ -60,13 +66,20 @@ public function testCommitSetsInTransactionAtFalse(): void
/**
* Standalone commit after a SET autocommit=0;
+ *
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit()
*/
- public function testCommitWithoutBeginReturnsInstanceOfConnection(): void
+ public function testCommitWithoutBeginReturnsInstanceOfConnection()
{
self::assertInstanceOf(Connection::class, $this->wrapper->commit());
}
- public function testNestedTransactionsCommit(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction()
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction()
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit()
+ */
+ public function testNestedTransactionsCommit()
{
$nested = 0;
@@ -93,7 +106,12 @@ public function testNestedTransactionsCommit(): void
self::assertSame(--$nested, $this->wrapper->getNestedTransactionsCount());
}
- public function testNestedTransactionsRollback(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction()
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction()
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback()
+ */
+ public function testNestedTransactionsRollback()
{
$nested = 0;
@@ -115,7 +133,10 @@ public function testNestedTransactionsRollback(): void
self::assertSame(0, $this->wrapper->getNestedTransactionsCount());
}
- public function testRollbackDisconnectedThrowsException(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback()
+ */
+ public function testRollbackDisconnectedThrowsException()
{
$this->wrapper->disconnect();
@@ -124,20 +145,30 @@ public function testRollbackDisconnectedThrowsException(): void
$this->wrapper->rollback();
}
- public function testRollbackReturnsInstanceOfConnection(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback()
+ */
+ public function testRollbackReturnsInstanceOfConnection()
{
$this->wrapper->beginTransaction();
self::assertInstanceOf(Connection::class, $this->wrapper->rollback());
}
- public function testRollbackSetsInTransactionAtFalse(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback()
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction()
+ */
+ public function testRollbackSetsInTransactionAtFalse()
{
$this->wrapper->beginTransaction();
$this->wrapper->rollback();
self::assertFalse($this->wrapper->inTransaction());
}
- public function testRollbackWithoutBeginThrowsException(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback()
+ */
+ public function testRollbackWithoutBeginThrowsException()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Must call beginTransaction() before you can rollback');
@@ -146,8 +177,11 @@ public function testRollbackWithoutBeginThrowsException(): void
/**
* Standalone commit after a SET autocommit=0;
+ *
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction()
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit()
*/
- public function testStandaloneCommit(): void
+ public function testStandaloneCommit()
{
self::assertFalse($this->wrapper->inTransaction());
self::assertSame(0, $this->wrapper->getNestedTransactionsCount());
diff --git a/test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php b/test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php
index ab9a68eb9..921d2a529 100644
--- a/test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php
+++ b/test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php
@@ -2,38 +2,37 @@
namespace LaminasTest\Db\Adapter\Driver\Pdo\Feature;
+use Closure;
use Laminas\Db\Adapter\Driver\ConnectionInterface;
use Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter;
use Laminas\Db\Adapter\Driver\Pdo\Pdo;
use Laminas\Db\Adapter\Driver\Pdo\Statement;
use Laminas\Db\Adapter\Driver\ResultInterface;
-use Override;
-use PDO as PDOConnection;
-use PDOStatement;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(OracleRowCounter::class, 'getName')]
-#[CoversMethod(OracleRowCounter::class, 'getCountForStatement')]
-#[CoversMethod(OracleRowCounter::class, 'getCountForSql')]
-#[CoversMethod(OracleRowCounter::class, 'getRowCountClosure')]
-final class OracleRowCounterTest extends TestCase
+class OracleRowCounterTest extends TestCase
{
- protected OracleRowCounter $rowCounter;
+ /** @var OracleRowCounter */
+ protected $rowCounter;
- #[Override]
protected function setUp(): void
{
$this->rowCounter = new OracleRowCounter();
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getName
+ */
+ public function testGetName()
{
self::assertEquals('OracleRowCounter', $this->rowCounter->getName());
}
- public function testGetCountForStatement(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getCountForStatement
+ */
+ public function testGetCountForStatement()
{
$statement = $this->getMockStatement('SELECT XXX', 5);
$statement->expects($this->once())->method('prepare')
@@ -43,88 +42,96 @@ public function testGetCountForStatement(): void
self::assertEquals(5, $count);
}
- public function testGetCountForSql(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getCountForSql
+ */
+ public function testGetCountForSql()
{
$this->rowCounter->setDriver($this->getMockDriver(5));
$count = $this->rowCounter->getCountForSql('SELECT XXX');
self::assertEquals(5, $count);
}
- public function testGetRowCountClosure(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getRowCountClosure
+ */
+ public function testGetRowCountClosure()
{
$stmt = $this->getMockStatement('SELECT XXX', 5);
+ /** @var Closure $closure */
$closure = $this->rowCounter->getRowCountClosure($stmt);
self::assertInstanceOf('Closure', $closure);
self::assertEquals(5, $closure());
}
/**
- * @psalm-param 5 $returnValue
+ * @param mixed $returnValue
+ * @return Statement&MockObject
*/
- protected function getMockStatement(string $sql, int $returnValue): MockObject&Statement
+ protected function getMockStatement(string $sql, $returnValue)
{
/** @var Statement|MockObject $statement */
$statement = $this->getMockBuilder(Statement::class)
- ->onlyMethods(['prepare', 'execute'])
+ ->setMethods(['prepare', 'execute'])
->disableOriginalConstructor()
->getMock();
// mock PDOStatement with stdClass
- $resource = $this->getMockBuilder(PDOStatement::class)
- ->onlyMethods(['fetch'])
+ $resource = $this->getMockBuilder('stdClass')
+ ->setMethods(['fetch'])
->getMock();
- $resource->expects($this->any())
+ $resource->expects($this->once())
->method('fetch')
- ->willReturn(['count' => $returnValue]);
+ ->will($this->returnValue(['count' => $returnValue]));
// mock the result
$result = $this->getMockBuilder(ResultInterface::class)->getMock();
$result->expects($this->once())
->method('getResource')
- ->willReturn($resource);
+ ->will($this->returnValue($resource));
$statement->setSql($sql);
$statement->expects($this->once())
->method('execute')
- ->willReturn($result);
+ ->will($this->returnValue($result));
return $statement;
}
/**
- * @psalm-param 5 $returnValue
+ * @param mixed $returnValue
+ * @return Pdo&MockObject
*/
- protected function getMockDriver(int $returnValue): MockObject&Pdo
+ protected function getMockDriver($returnValue)
{
- $pdoStatement = $this->getMockBuilder(PDOStatement::class)
- ->onlyMethods(['fetch'])
+ $pdoStatement = $this->getMockBuilder('stdClass')
+ ->setMethods(['fetch'])
->disableOriginalConstructor()
->getMock(); // stdClass can be used here
$pdoStatement->expects($this->once())
->method('fetch')
- ->willReturn(['count' => $returnValue]);
+ ->will($this->returnValue(['count' => $returnValue]));
- $pdoConnection = $this->getMockBuilder(PDOConnection::class)
- ->onlyMethods(['query'])
- ->disableOriginalConstructor()
+ $pdoConnection = $this->getMockBuilder('stdClass')
+ ->setMethods(['query'])
->getMock();
- $pdoConnection->expects($this->any())
+ $pdoConnection->expects($this->once())
->method('query')
- ->willReturn($pdoStatement);
+ ->will($this->returnValue($pdoStatement));
$connection = $this->getMockBuilder(ConnectionInterface::class)->getMock();
$connection->expects($this->once())
->method('getResource')
- ->willReturn($pdoConnection);
+ ->will($this->returnValue($pdoConnection));
$driver = $this->getMockBuilder(Pdo::class)
- ->onlyMethods(['getConnection'])
+ ->setMethods(['getConnection'])
->disableOriginalConstructor()
->getMock();
$driver->expects($this->once())
->method('getConnection')
- ->willReturn($connection);
+ ->will($this->returnValue($connection));
return $driver;
}
diff --git a/test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php b/test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php
index ec918d4c6..796929137 100644
--- a/test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php
+++ b/test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php
@@ -2,38 +2,37 @@
namespace LaminasTest\Db\Adapter\Driver\Pdo\Feature;
+use Closure;
use Laminas\Db\Adapter\Driver\ConnectionInterface;
use Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter;
use Laminas\Db\Adapter\Driver\Pdo\Pdo;
use Laminas\Db\Adapter\Driver\Pdo\Statement;
use Laminas\Db\Adapter\Driver\ResultInterface;
-use Override;
-use PDO as PDOConnection;
-use PDOStatement;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(SqliteRowCounter::class, 'getName')]
-#[CoversMethod(SqliteRowCounter::class, 'getCountForStatement')]
-#[CoversMethod(SqliteRowCounter::class, 'getCountForSql')]
-#[CoversMethod(SqliteRowCounter::class, 'getRowCountClosure')]
-final class SqliteRowCounterTest extends TestCase
+class SqliteRowCounterTest extends TestCase
{
- protected SqliteRowCounter $rowCounter;
+ /** @var SqliteRowCounter */
+ protected $rowCounter;
- #[Override]
protected function setUp(): void
{
$this->rowCounter = new SqliteRowCounter();
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getName
+ */
+ public function testGetName()
{
self::assertEquals('SqliteRowCounter', $this->rowCounter->getName());
}
- public function testGetCountForStatement(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getCountForStatement
+ */
+ public function testGetCountForStatement()
{
$statement = $this->getMockStatement('SELECT XXX', 5);
$statement->expects($this->once())->method('prepare')
@@ -43,88 +42,97 @@ public function testGetCountForStatement(): void
self::assertEquals(5, $count);
}
- public function testGetCountForSql(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getCountForSql
+ */
+ public function testGetCountForSql()
{
$this->rowCounter->setDriver($this->getMockDriver(5));
$count = $this->rowCounter->getCountForSql('SELECT XXX');
self::assertEquals(5, $count);
}
- public function testGetRowCountClosure(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getRowCountClosure
+ */
+ public function testGetRowCountClosure()
{
$stmt = $this->getMockStatement('SELECT XXX', 5);
+ /** @var Closure $closure */
$closure = $this->rowCounter->getRowCountClosure($stmt);
self::assertInstanceOf('Closure', $closure);
self::assertEquals(5, $closure());
}
/**
- * @psalm-param 5 $returnValue
+ * @param string $sql
+ * @param mixed $returnValue
+ * @return Statement&MockObject
*/
- protected function getMockStatement(string $sql, int $returnValue): MockObject&Statement
+ protected function getMockStatement($sql, $returnValue)
{
/** @var Statement|MockObject $statement */
$statement = $this->getMockBuilder(Statement::class)
- ->onlyMethods(['prepare', 'execute'])
+ ->setMethods(['prepare', 'execute'])
->disableOriginalConstructor()
->getMock();
// mock PDOStatement with stdClass
- $resource = $this->getMockBuilder(PDOStatement::class)
- ->onlyMethods(['fetch'])
+ $resource = $this->getMockBuilder('stdClass')
+ ->setMethods(['fetch'])
->getMock();
$resource->expects($this->once())
->method('fetch')
- ->willReturn(['count' => $returnValue]);
+ ->will($this->returnValue(['count' => $returnValue]));
// mock the result
$result = $this->getMockBuilder(ResultInterface::class)->getMock();
$result->expects($this->once())
->method('getResource')
- ->willReturn($resource);
+ ->will($this->returnValue($resource));
$statement->setSql($sql);
$statement->expects($this->once())
->method('execute')
- ->willReturn($result);
+ ->will($this->returnValue($result));
return $statement;
}
/**
- * @psalm-param 5 $returnValue
+ * @param mixed $returnValue
+ * @return Pdo&MockObject
*/
- protected function getMockDriver(int $returnValue): MockObject&Pdo
+ protected function getMockDriver($returnValue)
{
- $pdoStatement = $this->getMockBuilder(PDOStatement::class)
- ->onlyMethods(['fetch'])
+ $pdoStatement = $this->getMockBuilder('stdClass')
+ ->setMethods(['fetch'])
->disableOriginalConstructor()
->getMock(); // stdClass can be used here
$pdoStatement->expects($this->once())
->method('fetch')
- ->willReturn(['count' => $returnValue]);
+ ->will($this->returnValue(['count' => $returnValue]));
- $pdoConnection = $this->getMockBuilder(PDOConnection::class)
- ->onlyMethods(['query'])
- ->disableOriginalConstructor()
+ $pdoConnection = $this->getMockBuilder('stdClass')
+ ->setMethods(['query'])
->getMock();
$pdoConnection->expects($this->once())
->method('query')
- ->willReturn($pdoStatement);
+ ->will($this->returnValue($pdoStatement));
$connection = $this->getMockBuilder(ConnectionInterface::class)->getMock();
$connection->expects($this->once())
->method('getResource')
- ->willReturn($pdoConnection);
+ ->will($this->returnValue($pdoConnection));
$driver = $this->getMockBuilder(Pdo::class)
- ->onlyMethods(['getConnection'])
+ ->setMethods(['getConnection'])
->disableOriginalConstructor()
->getMock();
$driver->expects($this->once())
->method('getConnection')
- ->willReturn($connection);
+ ->will($this->returnValue($connection));
return $driver;
}
diff --git a/test/unit/Adapter/Driver/Pdo/PdoTest.php b/test/unit/Adapter/Driver/Pdo/PdoTest.php
index dd52440a1..dcc0610fa 100644
--- a/test/unit/Adapter/Driver/Pdo/PdoTest.php
+++ b/test/unit/Adapter/Driver/Pdo/PdoTest.php
@@ -6,28 +6,26 @@
use Laminas\Db\Adapter\Driver\Pdo\Pdo;
use Laminas\Db\Adapter\Driver\Pdo\Result;
use Laminas\Db\Exception\RuntimeException;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Pdo::class, 'getDatabasePlatformName')]
-#[CoversMethod(Pdo::class, 'getResultPrototype')]
-final class PdoTest extends TestCase
+class PdoTest extends TestCase
{
- protected Pdo $pdo;
+ /** @var Pdo */
+ protected $pdo;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->pdo = new Pdo([]);
}
- public function testGetDatabasePlatformName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Pdo::getDatabasePlatformName
+ */
+ public function testGetDatabasePlatformName()
{
// Test platform name for SqlServer
$this->pdo->getConnection()->setConnectionParameters(['pdodriver' => 'sqlsrv']);
@@ -36,7 +34,7 @@ public function testGetDatabasePlatformName(): void
}
/** @psalm-return array */
- public static function getParamsAndType(): array
+ public function getParamsAndType(): array
{
return [
['foo', null, ':foo'],
@@ -53,15 +51,18 @@ public static function getParamsAndType(): array
];
}
- #[DataProvider('getParamsAndType')]
- public function testFormatParameterName(int|string $name, ?string $type, string $expected): void
+ /**
+ * @dataProvider getParamsAndType
+ * @param int|string $name
+ */
+ public function testFormatParameterName($name, ?string $type, string $expected)
{
$result = $this->pdo->formatParameterName($name, $type);
$this->assertEquals($expected, $result);
}
/** @psalm-return array */
- public static function getInvalidParamName(): array
+ public function getInvalidParamName(): array
{
return [
['foo%'],
@@ -71,14 +72,19 @@ public static function getInvalidParamName(): array
];
}
- #[DataProvider('getInvalidParamName')]
- public function testFormatParameterNameWithInvalidCharacters(string $name): void
+ /**
+ * @dataProvider getInvalidParamName
+ */
+ public function testFormatParameterNameWithInvalidCharacters(string $name)
{
$this->expectException(RuntimeException::class);
$this->pdo->formatParameterName($name);
}
- public function testGetResultPrototype(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Pdo::getResultPrototype
+ */
+ public function testGetResultPrototype()
{
$resultPrototype = $this->pdo->getResultPrototype();
diff --git a/test/unit/Adapter/Driver/Pdo/ResultTest.php b/test/unit/Adapter/Driver/Pdo/ResultTest.php
index a7fdd25e0..510147364 100644
--- a/test/unit/Adapter/Driver/Pdo/ResultTest.php
+++ b/test/unit/Adapter/Driver/Pdo/ResultTest.php
@@ -6,27 +6,30 @@
use Laminas\Db\Adapter\Exception\InvalidArgumentException;
use PDO;
use PDOStatement;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use stdClass;
use function assert;
use function uniqid;
-#[CoversMethod(Result::class, 'current')]
-#[Group('result-pdo')]
-final class ResultTest extends TestCase
+/**
+ * @group result-pdo
+ */
+class ResultTest extends TestCase
{
/**
* Tests current method returns same data on consecutive calls.
+ *
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Result::current
*/
- public function testCurrent(): void
+ public function testCurrent()
{
$stub = $this->getMockBuilder('PDOStatement')->getMock();
$stub->expects($this->any())
->method('fetch')
- ->willReturnCallback(fn() => uniqid());
+ ->will($this->returnCallback(function () {
+ return uniqid();
+ }));
$result = new Result();
$result->initialize($stub, null);
@@ -34,7 +37,7 @@ public function testCurrent(): void
self::assertEquals($result->current(), $result->current());
}
- public function testFetchModeException(): void
+ public function testFetchModeException()
{
$result = new Result();
@@ -45,12 +48,14 @@ public function testFetchModeException(): void
/**
* Tests whether the fetch mode was set properly and
*/
- public function testFetchModeAnonymousObject(): void
+ public function testFetchModeAnonymousObject()
{
$stub = $this->getMockBuilder('PDOStatement')->getMock();
$stub->expects($this->any())
->method('fetch')
- ->willReturnCallback(fn() => new stdClass());
+ ->will($this->returnCallback(function () {
+ return new stdClass();
+ }));
$result = new Result();
$result->initialize($stub, null);
@@ -63,12 +68,14 @@ public function testFetchModeAnonymousObject(): void
/**
* Tests whether the fetch mode has a broader range
*/
- public function testFetchModeRange(): void
+ public function testFetchModeRange()
{
$stub = $this->getMockBuilder('PDOStatement')->getMock();
$stub->expects($this->any())
->method('fetch')
- ->willReturnCallback(fn() => new stdClass());
+ ->will($this->returnCallback(function () {
+ return new stdClass();
+ }));
$result = new Result();
$result->initialize($stub, null);
$result->setFetchMode(PDO::FETCH_NAMED);
@@ -76,7 +83,7 @@ public function testFetchModeRange(): void
self::assertInstanceOf('stdClass', $result->current());
}
- public function testMultipleRewind(): void
+ public function testMultipleRewind()
{
$data = [
['test' => 1],
@@ -88,9 +95,9 @@ public function testMultipleRewind(): void
assert($stub instanceof PDOStatement); // to suppress IDE type warnings
$stub->expects($this->any())
->method('fetch')
- ->willReturnCallback(function () use ($data, &$position) {
+ ->will($this->returnCallback(function () use ($data, &$position) {
return $data[$position++];
- });
+ }));
$result = new Result();
$result->initialize($stub, null);
diff --git a/test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php b/test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php
index 37170c74e..02aabcae1 100644
--- a/test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php
@@ -3,28 +3,26 @@
namespace LaminasTest\Db\Adapter\Driver\Pdo;
use Laminas\Db\Adapter\Driver\Pdo\Statement;
-use Override;
use PDO;
-use PDOStatement;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-final class StatementIntegrationTest extends TestCase
+class StatementIntegrationTest extends TestCase
{
- protected Statement $statement;
+ /** @var Statement */
+ protected $statement;
/** @var MockObject */
- protected PDOStatement|MockObject $pdoStatementMock;
+ protected $pdoStatementMock;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$driver = $this->getMockBuilder(\Laminas\Db\Adapter\Driver\Pdo\Pdo::class)
- ->onlyMethods(['createResult'])
+ ->setMethods(['createResult'])
->disableOriginalConstructor()
->getMock();
@@ -32,7 +30,7 @@ protected function setUp(): void
$this->statement->setDriver($driver);
$this->statement->initialize(new TestAsset\CtorlessPdo(
$this->pdoStatementMock = $this->getMockBuilder('PDOStatement')
- ->onlyMethods(['execute', 'bindParam'])
+ ->setMethods(['execute', 'bindParam'])
->getMock()
));
}
@@ -45,8 +43,9 @@ protected function tearDown(): void
{
}
- public function testStatementExecuteWillConvertPhpBoolToPdoBoolWhenBinding(): void
+ public function testStatementExecuteWillConvertPhpBoolToPdoBoolWhenBinding()
{
+ $this->expectNotToPerformAssertions();
$this->pdoStatementMock->expects($this->any())->method('bindParam')->with(
$this->equalTo(':foo'),
$this->equalTo(false),
@@ -55,8 +54,9 @@ public function testStatementExecuteWillConvertPhpBoolToPdoBoolWhenBinding(): vo
$this->statement->execute(['foo' => false]);
}
- public function testStatementExecuteWillUsePdoStrByDefaultWhenBinding(): void
+ public function testStatementExecuteWillUsePdoStrByDefaultWhenBinding()
{
+ $this->expectNotToPerformAssertions();
$this->pdoStatementMock->expects($this->any())->method('bindParam')->with(
$this->equalTo(':foo'),
$this->equalTo('bar'),
@@ -65,8 +65,9 @@ public function testStatementExecuteWillUsePdoStrByDefaultWhenBinding(): void
$this->statement->execute(['foo' => 'bar']);
}
- public function testStatementExecuteWillUsePdoStrForStringIntegerWhenBinding(): void
+ public function testStatementExecuteWillUsePdoStrForStringIntegerWhenBinding()
{
+ $this->expectNotToPerformAssertions();
$this->pdoStatementMock->expects($this->any())->method('bindParam')->with(
$this->equalTo(':foo'),
$this->equalTo('123'),
@@ -75,8 +76,9 @@ public function testStatementExecuteWillUsePdoStrForStringIntegerWhenBinding():
$this->statement->execute(['foo' => '123']);
}
- public function testStatementExecuteWillUsePdoIntForIntWhenBinding(): void
+ public function testStatementExecuteWillUsePdoIntForIntWhenBinding()
{
+ $this->expectNotToPerformAssertions();
$this->pdoStatementMock->expects($this->any())->method('bindParam')->with(
$this->equalTo(':foo'),
$this->equalTo(123),
diff --git a/test/unit/Adapter/Driver/Pdo/StatementTest.php b/test/unit/Adapter/Driver/Pdo/StatementTest.php
index b7ea62df4..2b89a01b4 100644
--- a/test/unit/Adapter/Driver/Pdo/StatementTest.php
+++ b/test/unit/Adapter/Driver/Pdo/StatementTest.php
@@ -7,28 +7,17 @@
use Laminas\Db\Adapter\Driver\Pdo\Result;
use Laminas\Db\Adapter\Driver\Pdo\Statement;
use Laminas\Db\Adapter\ParameterContainer;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Statement::class, 'setDriver')]
-#[CoversMethod(Statement::class, 'setParameterContainer')]
-#[CoversMethod(Statement::class, 'getParameterContainer')]
-#[CoversMethod(Statement::class, 'getResource')]
-#[CoversMethod(Statement::class, 'setSql')]
-#[CoversMethod(Statement::class, 'getSql')]
-#[CoversMethod(Statement::class, 'prepare')]
-#[CoversMethod(Statement::class, 'isPrepared')]
-#[CoversMethod(Statement::class, 'execute')]
-final class StatementTest extends TestCase
+class StatementTest extends TestCase
{
- protected Statement $statement;
+ /** @var Statement */
+ protected $statement;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->statement = new Statement();
@@ -42,27 +31,37 @@ protected function tearDown(): void
{
}
- public function testSetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::setDriver
+ */
+ public function testSetDriver()
{
self::assertEquals($this->statement, $this->statement->setDriver(new Pdo([])));
}
- public function testSetParameterContainer(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::setParameterContainer
+ */
+ public function testSetParameterContainer()
{
self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer()));
}
/**
- * @todo Implement testGetParameterContainer().
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::getParameterContainer
+ * @todo Implement testGetParameterContainer().
*/
- public function testGetParameterContainer(): void
+ public function testGetParameterContainer()
{
$container = new ParameterContainer();
$this->statement->setParameterContainer($container);
self::assertSame($container, $this->statement->getParameterContainer());
}
- public function testGetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::getResource
+ */
+ public function testGetResource()
{
$pdo = new TestAsset\SqliteMemoryPdo();
$stmt = $pdo->prepare('SELECT 1');
@@ -71,28 +70,38 @@ public function testGetResource(): void
self::assertSame($stmt, $this->statement->getResource());
}
- public function testSetSql(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::setSql
+ */
+ public function testSetSql()
{
$this->statement->setSql('SELECT 1');
self::assertEquals('SELECT 1', $this->statement->getSql());
}
- public function testGetSql(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::getSql
+ */
+ public function testGetSql()
{
$this->statement->setSql('SELECT 1');
self::assertEquals('SELECT 1', $this->statement->getSql());
}
/**
- * @todo Implement testPrepare().
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::prepare
+ * @todo Implement testPrepare().
*/
- public function testPrepare(): void
+ public function testPrepare()
{
$this->statement->initialize(new TestAsset\SqliteMemoryPdo());
self::assertNull($this->statement->prepare('SELECT 1'));
}
- public function testIsPrepared(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::isPrepared
+ */
+ public function testIsPrepared()
{
self::assertFalse($this->statement->isPrepared());
$this->statement->initialize(new TestAsset\SqliteMemoryPdo());
@@ -100,7 +109,10 @@ public function testIsPrepared(): void
self::assertTrue($this->statement->isPrepared());
}
- public function testExecute(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::execute
+ */
+ public function testExecute()
{
$this->statement->setDriver(new Pdo(new Connection($pdo = new TestAsset\SqliteMemoryPdo())));
$this->statement->initialize($pdo);
diff --git a/test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php b/test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php
index 98af326a2..5b71a73d1 100644
--- a/test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php
+++ b/test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php
@@ -2,22 +2,36 @@
namespace LaminasTest\Db\Adapter\Driver\Pdo\TestAsset;
-use Override;
use PDO;
use PDOStatement;
use PHPUnit\Framework\MockObject\MockObject;
+// phpcs:ignore SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse
+use ReturnTypeWillChange;
-final class CtorlessPdo extends PDO
+class CtorlessPdo extends PDO
{
- public function __construct(protected PDOStatement&MockObject $mockStatement)
+ /**
+ * @var PDOStatement
+ * @psalm-var PDOStatement&MockObject
+ */
+ protected $mockStatement;
+
+ /**
+ * @param PDOStatement $mockStatement
+ * @psalm-param PDOStatement&MockObject $mockStatement
+ */
+ public function __construct($mockStatement)
{
+ $this->mockStatement = $mockStatement;
}
/**
- * @param array $options
+ * @param string $sql
+ * @param null|array $options
+ * @return PDOStatement|false
*/
- #[Override]
- public function prepare(string $query, $options = null): PDOStatement
+ #[ReturnTypeWillChange]
+ public function prepare($sql, $options = null): PDOStatement
{
return $this->mockStatement;
}
diff --git a/test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php b/test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php
index 73c6c3a33..bba81fc9c 100644
--- a/test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php
+++ b/test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php
@@ -10,14 +10,12 @@
use function implode;
use function sprintf;
-final class SqliteMemoryPdo extends PDO
+class SqliteMemoryPdo extends PDO
{
- protected MockObject&PDOStatement $mockStatement;
+ /** @var PDOStatement&MockObject */
+ protected $mockStatement;
- /**
- * @param null $sql
- * @throws Exception
- */
+ /** @param null|string $sql */
public function __construct($sql = null)
{
parent::__construct('sqlite::memory:');
diff --git a/test/unit/Adapter/Driver/Pgsql/ConnectionTest.php b/test/unit/Adapter/Driver/Pgsql/ConnectionTest.php
index 055d67532..efebd814f 100644
--- a/test/unit/Adapter/Driver/Pgsql/ConnectionTest.php
+++ b/test/unit/Adapter/Driver/Pgsql/ConnectionTest.php
@@ -7,10 +7,6 @@
use Laminas\Db\Adapter\Exception\InvalidArgumentException;
use Laminas\Db\Adapter\Exception\RuntimeException;
use LaminasTest\Db\DeprecatedAssertionsTrait;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
-use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
@@ -19,18 +15,17 @@
use const PGSQL_CONNECT_FORCE_NEW;
-#[CoversMethod(Connection::class, 'getResource')]
-final class ConnectionTest extends TestCase
+class ConnectionTest extends TestCase
{
use DeprecatedAssertionsTrait;
- protected Connection $connection;
+ /** @var Connection */
+ protected $connection;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->connection = new Connection();
@@ -39,7 +34,7 @@ protected function setUp(): void
/**
* Test getResource method if it tries to connect to the database.
*
- * @return void
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Connection::getResource
*/
public function testResourceInvalid()
{
@@ -50,7 +45,7 @@ public function testResourceInvalid()
// invalid port should lead to the custom error handler throwing
$conn = new Connection(['socket' => '127.0.0.1', 'port' => 65112]);
try {
- $conn->getResource();
+ $resource = $conn->getResource();
$this->fail('should throw');
} catch (AdapterException\RuntimeException $exc) {
$this->assertSame(
@@ -63,7 +58,7 @@ public function testResourceInvalid()
/**
* Test getResource method if it tries to connect to the database.
*
- * @return void
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Connection::getResource
*/
public function testResource()
{
@@ -85,15 +80,17 @@ public function testResource()
/**
* Test disconnect method to return instance of ConnectionInterface
*/
- public function testDisconnect(): void
+ public function testDisconnect()
{
include_once 'pgsqlMockFunctions.php';
self::assertSame($this->connection, $this->connection->disconnect());
}
- #[Group('6760')]
- #[Group('6787')]
- public function testGetConnectionStringEncodeSpecialSymbol(): void
+ /**
+ * @group 6760
+ * @group 6787
+ */
+ public function testGetConnectionStringEncodeSpecialSymbol()
{
$connectionParameters = [
'driver' => 'pgsql',
@@ -111,7 +108,6 @@ public function testGetConnectionStringEncodeSpecialSymbol(): void
'getConnectionString'
);
- /** @psalm-suppress UnusedMethodCall */
$getConnectionString->setAccessible(true);
self::assertEquals(
@@ -120,9 +116,6 @@ public function testGetConnectionStringEncodeSpecialSymbol(): void
);
}
- /**
- * @return void
- */
public function testSetConnectionTypeException()
{
if (! extension_loaded('pgsql')) {
@@ -135,8 +128,6 @@ public function testSetConnectionTypeException()
/**
* Test the connection type setter
- *
- * @return void
*/
public function testSetConnectionType()
{
@@ -149,9 +140,8 @@ public function testSetConnectionType()
}
/**
- * @return void
+ * @runInSeparateProcess
*/
- #[RunInSeparateProcess]
public function testSetCharset()
{
if (! extension_loaded('pgsql')) {
@@ -170,7 +160,7 @@ public function testSetCharset()
try {
$this->connection->connect();
- } catch (AdapterException\RuntimeException) {
+ } catch (AdapterException\RuntimeException $e) {
$this->markTestSkipped('Skipping pgsql charset test due to inability to connecto to database');
}
@@ -178,9 +168,8 @@ public function testSetCharset()
}
/**
- * @return void
+ * @runInSeparateProcess
*/
- #[RunInSeparateProcess]
public function testSetInvalidCharset()
{
if (! extension_loaded('pgsql')) {
diff --git a/test/unit/Adapter/Driver/Pgsql/PgsqlTest.php b/test/unit/Adapter/Driver/Pgsql/PgsqlTest.php
index 444f56291..df9357e8a 100644
--- a/test/unit/Adapter/Driver/Pgsql/PgsqlTest.php
+++ b/test/unit/Adapter/Driver/Pgsql/PgsqlTest.php
@@ -7,41 +7,28 @@
use Laminas\Db\Adapter\Driver\Pgsql\Result;
use Laminas\Db\Adapter\Driver\Pgsql\Statement;
use Laminas\Db\Adapter\Exception\RuntimeException;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Depends;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
-#[CoversMethod(Pgsql::class, 'checkEnvironment')]
-#[CoversMethod(Pgsql::class, 'registerConnection')]
-#[CoversMethod(Pgsql::class, 'registerStatementPrototype')]
-#[CoversMethod(Pgsql::class, 'registerResultPrototype')]
-#[CoversMethod(Pgsql::class, 'getDatabasePlatformName')]
-#[CoversMethod(Pgsql::class, 'getConnection')]
-#[CoversMethod(Pgsql::class, 'createStatement')]
-#[CoversMethod(Pgsql::class, 'createResult')]
-#[CoversMethod(Pgsql::class, 'getPrepareType')]
-#[CoversMethod(Pgsql::class, 'formatParameterName')]
-#[CoversMethod(Pgsql::class, 'getLastGeneratedValue')]
-#[CoversMethod(Pgsql::class, 'getResultPrototype')]
-final class PgsqlTest extends TestCase
+class PgsqlTest extends TestCase
{
- protected Pgsql $pgsql;
+ /** @var Pgsql */
+ protected $pgsql;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->pgsql = new Pgsql([]);
}
- public function testCheckEnvironment(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::checkEnvironment
+ */
+ public function testCheckEnvironment()
{
if (! extension_loaded('pgsql')) {
$this->expectException(RuntimeException::class);
@@ -51,45 +38,75 @@ public function testCheckEnvironment(): void
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::registerConnection
*/
- public function testRegisterConnection(): void
+ public function testRegisterConnection()
{
- $mockConnection = $this->getMockBuilder(Connection::class)->setConstructorArgs([[]])->onlyMethods(['setDriver'])->getMock();
+ $mockConnection = $this->getMockForAbstractClass(
+ Connection::class,
+ [[]],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
$mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->pgsql));
self::assertSame($this->pgsql, $this->pgsql->registerConnection($mockConnection));
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::registerStatementPrototype
*/
- public function testRegisterStatementPrototype(): void
+ public function testRegisterStatementPrototype()
{
$this->pgsql = new Pgsql([]);
- $mockStatement = $this->getMockBuilder(Statement::class)->setConstructorArgs([])->onlyMethods(['setDriver'])->getMock();
+ $mockStatement = $this->getMockForAbstractClass(
+ Statement::class,
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
$mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->pgsql));
self::assertSame($this->pgsql, $this->pgsql->registerStatementPrototype($mockStatement));
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::registerResultPrototype
*/
- public function testRegisterResultPrototype(): void
+ public function testRegisterResultPrototype()
{
$this->pgsql = new Pgsql([]);
- $mockStatement = $this->getMockBuilder(Result::class)->setConstructorArgs([])->onlyMethods([])->getMock();
+ $mockStatement = $this->getMockForAbstractClass(
+ Result::class,
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
self::assertSame($this->pgsql, $this->pgsql->registerResultPrototype($mockStatement));
}
- public function testGetDatabasePlatformName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getDatabasePlatformName
+ */
+ public function testGetDatabasePlatformName()
{
$this->pgsql = new Pgsql([]);
self::assertEquals('Postgresql', $this->pgsql->getDatabasePlatformName());
self::assertEquals('PostgreSQL', $this->pgsql->getDatabasePlatformName(Pgsql::NAME_FORMAT_NATURAL));
}
- #[Depends('testRegisterConnection')]
- public function testGetConnection(): void
+ /**
+ * @depends testRegisterConnection
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getConnection
+ */
+ public function testGetConnection()
{
$conn = new Connection([]);
$this->pgsql->registerConnection($conn);
@@ -97,9 +114,10 @@ public function testGetConnection(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::createStatement
* @todo Implement testGetPrepareType().
*/
- public function testCreateStatement(): never
+ public function testCreateStatement()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -108,9 +126,10 @@ public function testCreateStatement(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::createResult
* @todo Implement testGetPrepareType().
*/
- public function testCreateResult(): never
+ public function testCreateResult()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -119,9 +138,10 @@ public function testCreateResult(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getPrepareType
* @todo Implement testGetPrepareType().
*/
- public function testGetPrepareType(): never
+ public function testGetPrepareType()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -130,9 +150,10 @@ public function testGetPrepareType(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::formatParameterName
* @todo Implement testFormatParameterName().
*/
- public function testFormatParameterName(): never
+ public function testFormatParameterName()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -141,9 +162,10 @@ public function testFormatParameterName(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getLastGeneratedValue
* @todo Implement testGetLastGeneratedValue().
*/
- public function testGetLastGeneratedValue(): never
+ public function testGetLastGeneratedValue()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -151,7 +173,10 @@ public function testGetLastGeneratedValue(): never
);
}
- public function testGetResultPrototype(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getResultPrototype
+ */
+ public function testGetResultPrototype()
{
$resultPrototype = $this->pgsql->getResultPrototype();
diff --git a/test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php b/test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php
index adc2b0bcb..03819e607 100644
--- a/test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php
+++ b/test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php
@@ -8,8 +8,9 @@
* @see http://php.net/manual/en/function.pg-close.php
*
* @param resource $connection
+ * @return bool
*/
-function pg_close($connection = null): bool
+function pg_close($connection = null)
{
return true;
}
diff --git a/test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTestCase.php b/test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTest.php
similarity index 90%
rename from test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTestCase.php
rename to test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTest.php
index d374db17a..3f2a19a0a 100644
--- a/test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTestCase.php
+++ b/test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTest.php
@@ -1,20 +1,17 @@
*/
- protected array $variables = [
+ protected $variables = [
'hostname' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_HOSTNAME',
'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_USERNAME',
'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD',
@@ -27,7 +24,6 @@ abstract class AbstractIntegrationTestCase extends TestCase
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV')) {
diff --git a/test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php b/test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php
index a11a1bd5f..6ef85bdf0 100644
--- a/test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php
@@ -6,34 +6,28 @@
use Laminas\Db\Adapter\Driver\Sqlsrv\Result;
use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv;
use Laminas\Db\Adapter\Driver\Sqlsrv\Statement;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use function sqlsrv_connect;
-#[CoversMethod(Connection::class, 'getCurrentSchema')]
-#[CoversMethod(Connection::class, 'setResource')]
-#[CoversMethod(Connection::class, 'getResource')]
-#[CoversMethod(Connection::class, 'connect')]
-#[CoversMethod(Connection::class, 'isConnected')]
-#[CoversMethod(Connection::class, 'disconnect')]
-#[CoversMethod(Connection::class, 'beginTransaction')]
-#[CoversMethod(Connection::class, 'commit')]
-#[CoversMethod(Connection::class, 'rollback')]
-#[CoversMethod(Connection::class, 'execute')]
-#[CoversMethod(Connection::class, 'prepare')]
-#[CoversMethod(Connection::class, 'getLastGeneratedValue')]
-#[Group('integration')]
-#[Group('integration-sqlserver')]
-final class ConnectionIntegrationTest extends AbstractIntegrationTestCase
+/**
+ * @group integration
+ * @group integration-sqlserver
+ */
+class ConnectionIntegrationTest extends AbstractIntegrationTest
{
- public function testGetCurrentSchema(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::getCurrentSchema
+ */
+ public function testGetCurrentSchema()
{
$connection = new Connection($this->variables);
self::assertIsString($connection->getCurrentSchema());
}
- public function testSetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::setResource
+ */
+ public function testSetResource()
{
$resource = sqlsrv_connect(
$this->variables['hostname'],
@@ -51,7 +45,10 @@ public function testSetResource(): void
unset($resource);
}
- public function testGetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::getResource
+ */
+ public function testGetResource()
{
$connection = new Connection($this->variables);
$connection->connect();
@@ -61,7 +58,10 @@ public function testGetResource(): void
unset($connection);
}
- public function testConnect(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::connect
+ */
+ public function testConnect()
{
$connection = new Connection($this->variables);
self::assertSame($connection, $connection->connect());
@@ -71,7 +71,10 @@ public function testConnect(): void
unset($connection);
}
- public function testIsConnected(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::isConnected
+ */
+ public function testIsConnected()
{
$connection = new Connection($this->variables);
self::assertFalse($connection->isConnected());
@@ -82,7 +85,10 @@ public function testIsConnected(): void
unset($connection);
}
- public function testDisconnect(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::disconnect
+ */
+ public function testDisconnect()
{
$connection = new Connection($this->variables);
$connection->connect();
@@ -92,9 +98,10 @@ public function testDisconnect(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::beginTransaction
* @todo Implement testBeginTransaction().
*/
- public function testBeginTransaction(): never
+ public function testBeginTransaction()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -103,9 +110,10 @@ public function testBeginTransaction(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::commit
* @todo Implement testCommit().
*/
- public function testCommit(): never
+ public function testCommit()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -114,9 +122,10 @@ public function testCommit(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::rollback
* @todo Implement testRollback().
*/
- public function testRollback(): never
+ public function testRollback()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -124,7 +133,10 @@ public function testRollback(): never
);
}
- public function testExecute(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::execute
+ */
+ public function testExecute()
{
$sqlsrv = new Sqlsrv($this->variables);
$connection = $sqlsrv->getConnection();
@@ -133,7 +145,10 @@ public function testExecute(): void
self::assertInstanceOf(Result::class, $result);
}
- public function testPrepare(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::prepare
+ */
+ public function testPrepare()
{
$sqlsrv = new Sqlsrv($this->variables);
$connection = $sqlsrv->getConnection();
@@ -142,17 +157,20 @@ public function testPrepare(): void
self::assertInstanceOf(Statement::class, $statement);
}
- public function testGetLastGeneratedValue(): never
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::getLastGeneratedValue
+ */
+ public function testGetLastGeneratedValue()
{
$this->markTestIncomplete('Need to create a temporary sequence.');
- /*
$connection = new Connection($this->variables);
$connection->getLastGeneratedValue();
- */
}
- #[Group('laminas3469')]
- public function testConnectReturnsConnectionWhenResourceSet(): void
+ /**
+ * @group laminas3469
+ */
+ public function testConnectReturnsConnectionWhenResourceSet()
{
$resource = sqlsrv_connect(
$this->variables['hostname'],
diff --git a/test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php b/test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php
index 14da2b25f..38a07f995 100644
--- a/test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php
+++ b/test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php
@@ -4,22 +4,17 @@
use Laminas\Db\Adapter\Driver\Sqlsrv\Connection;
use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Connection::class, 'setDriver')]
-#[CoversMethod(Connection::class, 'setConnectionParameters')]
-#[CoversMethod(Connection::class, 'getConnectionParameters')]
-final class ConnectionTest extends TestCase
+class ConnectionTest extends TestCase
{
- protected Connection $connection;
+ /** @var Connection */
+ protected $connection;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->connection = new Connection([]);
@@ -33,17 +28,26 @@ protected function tearDown(): void
{
}
- public function testSetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::setDriver
+ */
+ public function testSetDriver()
{
self::assertEquals($this->connection, $this->connection->setDriver(new Sqlsrv([])));
}
- public function testSetConnectionParameters(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::setConnectionParameters
+ */
+ public function testSetConnectionParameters()
{
self::assertEquals($this->connection, $this->connection->setConnectionParameters([]));
}
- public function testGetConnectionParameters(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::getConnectionParameters
+ */
+ public function testGetConnectionParameters()
{
$this->connection->setConnectionParameters(['foo' => 'bar']);
self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters());
diff --git a/test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php b/test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php
index f59a017ef..34a3d9c25 100644
--- a/test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php
@@ -3,15 +3,13 @@
namespace LaminasTest\Db\Adapter\Driver\Sqlsrv;
use Laminas\Db\Adapter\Driver\Pdo\Pdo;
-use PHPUnit\Framework\Attributes\Group;
-#[Group('integration')]
-#[Group('integration-sqlserver')]
-final class PdoSqlSrvIntegrationTest extends AbstractIntegrationTestCase
+/**
+ * @group integration
+ * @group integration-sqlserver
+ */
+class PdoSqlSrvIntegrationTest extends AbstractIntegrationTest
{
- /**
- * @return void
- */
public function testParameterizedQuery()
{
if (! isset($this->adapters['pdo_sqlsrv'])) {
diff --git a/test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php b/test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php
index eadd52a43..e35cdd12c 100644
--- a/test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php
@@ -3,35 +3,21 @@
namespace LaminasTest\Db\Adapter\Driver\Sqlsrv;
use Laminas\Db\Adapter\Driver\Sqlsrv\Result;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Result::class, 'initialize')]
-#[CoversMethod(Result::class, 'buffer')]
-#[CoversMethod(Result::class, 'getResource')]
-#[CoversMethod(Result::class, 'current')]
-#[CoversMethod(Result::class, 'next')]
-#[CoversMethod(Result::class, 'key')]
-#[CoversMethod(Result::class, 'rewind')]
-#[CoversMethod(Result::class, 'valid')]
-#[CoversMethod(Result::class, 'count')]
-#[CoversMethod(Result::class, 'getFieldCount')]
-#[CoversMethod(Result::class, 'isQueryResult')]
-#[CoversMethod(Result::class, 'getAffectedRows')]
-#[CoversMethod(Result::class, 'getGeneratedValue')]
-#[Group('integration')]
-#[Group('integration-sqlsrv')]
-final class ResultIntegrationTest extends TestCase
+/**
+ * @group integration
+ * @group integration-sqlsrv
+ */
+class ResultIntegrationTest extends TestCase
{
- protected Result $object;
+ /** @var Result */
+ protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->object = new Result();
@@ -46,9 +32,10 @@ protected function tearDown(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::initialize
* @todo Implement testInitialize().
*/
- public function testInitialize(): never
+ public function testInitialize()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -57,9 +44,10 @@ public function testInitialize(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::buffer
* @todo Implement testBuffer().
*/
- public function testBuffer(): never
+ public function testBuffer()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -68,9 +56,10 @@ public function testBuffer(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::getResource
* @todo Implement testGetResource().
*/
- public function testGetResource(): never
+ public function testGetResource()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -79,9 +68,10 @@ public function testGetResource(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::current
* @todo Implement testCurrent().
*/
- public function testCurrent(): never
+ public function testCurrent()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -90,9 +80,10 @@ public function testCurrent(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::next
* @todo Implement testNext().
*/
- public function testNext(): never
+ public function testNext()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -101,9 +92,10 @@ public function testNext(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::key
* @todo Implement testKey().
*/
- public function testKey(): never
+ public function testKey()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -112,9 +104,10 @@ public function testKey(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::rewind
* @todo Implement testRewind().
*/
- public function testRewind(): never
+ public function testRewind()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -123,9 +116,10 @@ public function testRewind(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::valid
* @todo Implement testValid().
*/
- public function testValid(): never
+ public function testValid()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -134,9 +128,10 @@ public function testValid(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::count
* @todo Implement testCount().
*/
- public function testCount(): never
+ public function testCount()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -145,9 +140,10 @@ public function testCount(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::getFieldCount
* @todo Implement testGetFieldCount().
*/
- public function testGetFieldCount(): never
+ public function testGetFieldCount()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -156,9 +152,10 @@ public function testGetFieldCount(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::isQueryResult
* @todo Implement testIsQueryResult().
*/
- public function testIsQueryResult(): never
+ public function testIsQueryResult()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -167,9 +164,10 @@ public function testIsQueryResult(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::getAffectedRows
* @todo Implement testGetAffectedRows().
*/
- public function testGetAffectedRows(): never
+ public function testGetAffectedRows()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -178,9 +176,10 @@ public function testGetAffectedRows(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::getGeneratedValue
* @todo Implement testGetGeneratedValue().
*/
- public function testGetGeneratedValue(): never
+ public function testGetGeneratedValue()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
diff --git a/test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php b/test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php
index dea9d4773..d9c9dfcca 100644
--- a/test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php
@@ -5,23 +5,20 @@
use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv;
use Laminas\Db\Adapter\Driver\Sqlsrv\Statement;
use Laminas\Db\Adapter\Exception\InvalidArgumentException;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use stdClass;
-#[CoversMethod(Sqlsrv::class, 'checkEnvironment')]
-#[Group('integration')]
-#[Group('integration-sqlserver')]
-final class SqlSrvIntegrationTest extends AbstractIntegrationTestCase
+/**
+ * @group integration
+ * @group integration-sqlserver
+ */
+class SqlSrvIntegrationTest extends AbstractIntegrationTest
{
/** @var Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv */
- private Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv|Sqlsrv $driver;
+ private $driver;
/** @var resource SQL Server Connection */
private $resource;
- #[Override]
protected function setUp(): void
{
parent::setUp();
@@ -29,14 +26,17 @@ protected function setUp(): void
$this->driver = new Sqlsrv($this->resource);
}
- #[Group('integration-sqlserver')]
- public function testCheckEnvironment(): void
+ /**
+ * @group integration-sqlserver
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::checkEnvironment
+ */
+ public function testCheckEnvironment()
{
$sqlserver = new Sqlsrv([]);
self::assertNull($sqlserver->checkEnvironment());
}
- public function testCreateStatement(): void
+ public function testCreateStatement()
{
$stmt = $this->driver->createStatement('SELECT 1');
$this->assertInstanceOf(Statement::class, $stmt);
@@ -50,7 +50,7 @@ public function testCreateStatement(): void
$this->driver->createStatement(new stdClass());
}
- public function testParameterizedQuery(): void
+ public function testParameterizedQuery()
{
$stmt = $this->driver->createStatement('SELECT ? as col_one');
$result = $stmt->execute(['a']);
diff --git a/test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php b/test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php
index c760a3bbc..142d953ef 100644
--- a/test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php
+++ b/test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php
@@ -6,77 +6,92 @@
use Laminas\Db\Adapter\Driver\Sqlsrv\Result;
use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv;
use Laminas\Db\Adapter\Driver\Sqlsrv\Statement;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Depends;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Sqlsrv::class, 'registerConnection')]
-#[CoversMethod(Sqlsrv::class, 'registerStatementPrototype')]
-#[CoversMethod(Sqlsrv::class, 'registerResultPrototype')]
-#[CoversMethod(Sqlsrv::class, 'getDatabasePlatformName')]
-#[CoversMethod(Sqlsrv::class, 'getConnection')]
-#[CoversMethod(Sqlsrv::class, 'createStatement')]
-#[CoversMethod(Sqlsrv::class, 'createResult')]
-#[CoversMethod(Sqlsrv::class, 'getPrepareType')]
-#[CoversMethod(Sqlsrv::class, 'formatParameterName')]
-#[CoversMethod(Sqlsrv::class, 'getLastGeneratedValue')]
-#[CoversMethod(Sqlsrv::class, 'getResultPrototype')]
-final class SqlsrvTest extends TestCase
+class SqlsrvTest extends TestCase
{
- protected Sqlsrv $sqlsrv;
+ /** @var Sqlsrv */
+ protected $sqlsrv;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->sqlsrv = new Sqlsrv([]);
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::registerConnection
*/
- public function testRegisterConnection(): void
+ public function testRegisterConnection()
{
- $mockConnection = $this->getMockBuilder(Connection::class)->setConstructorArgs([[]])->onlyMethods(['setDriver'])->getMock();
+ $mockConnection = $this->getMockForAbstractClass(
+ Connection::class,
+ [[]],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
$mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->sqlsrv));
self::assertSame($this->sqlsrv, $this->sqlsrv->registerConnection($mockConnection));
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::registerStatementPrototype
*/
- public function testRegisterStatementPrototype(): void
+ public function testRegisterStatementPrototype()
{
$this->sqlsrv = new Sqlsrv([]);
- $mockStatement = $this->getMockBuilder(Statement::class)->setConstructorArgs([])->onlyMethods(['setDriver'])->getMock();
+ $mockStatement = $this->getMockForAbstractClass(
+ Statement::class,
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
$mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->sqlsrv));
self::assertSame($this->sqlsrv, $this->sqlsrv->registerStatementPrototype($mockStatement));
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::registerResultPrototype
*/
- public function testRegisterResultPrototype(): void
+ public function testRegisterResultPrototype()
{
$this->sqlsrv = new Sqlsrv([]);
- $mockStatement = $this->getMockBuilder(Result::class)->setConstructorArgs([])->onlyMethods([])->getMock();
+ $mockStatement = $this->getMockForAbstractClass(
+ Result::class,
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['setDriver']
+ );
self::assertSame($this->sqlsrv, $this->sqlsrv->registerResultPrototype($mockStatement));
}
- public function testGetDatabasePlatformName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getDatabasePlatformName
+ */
+ public function testGetDatabasePlatformName()
{
$this->sqlsrv = new Sqlsrv([]);
self::assertEquals('SqlServer', $this->sqlsrv->getDatabasePlatformName());
self::assertEquals('SQLServer', $this->sqlsrv->getDatabasePlatformName(Sqlsrv::NAME_FORMAT_NATURAL));
}
- #[Depends('testRegisterConnection')]
- public function testGetConnection(): void
+ /**
+ * @depends testRegisterConnection
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getConnection
+ */
+ public function testGetConnection()
{
$conn = new Connection([]);
$this->sqlsrv->registerConnection($conn);
@@ -84,9 +99,10 @@ public function testGetConnection(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::createStatement
* @todo Implement testGetPrepareType().
*/
- public function testCreateStatement(): never
+ public function testCreateStatement()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -95,9 +111,10 @@ public function testCreateStatement(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::createResult
* @todo Implement testGetPrepareType().
*/
- public function testCreateResult(): never
+ public function testCreateResult()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -106,9 +123,10 @@ public function testCreateResult(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getPrepareType
* @todo Implement testGetPrepareType().
*/
- public function testGetPrepareType(): never
+ public function testGetPrepareType()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -117,9 +135,10 @@ public function testGetPrepareType(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::formatParameterName
* @todo Implement testFormatParameterName().
*/
- public function testFormatParameterName(): never
+ public function testFormatParameterName()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -128,9 +147,10 @@ public function testFormatParameterName(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getLastGeneratedValue
* @todo Implement testGetLastGeneratedValue().
*/
- public function testGetLastGeneratedValue(): never
+ public function testGetLastGeneratedValue()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -138,7 +158,10 @@ public function testGetLastGeneratedValue(): never
);
}
- public function testGetResultPrototype(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getResultPrototype
+ */
+ public function testGetResultPrototype()
{
$resultPrototype = $this->sqlsrv->getResultPrototype();
diff --git a/test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php b/test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php
index 3b2c74fa5..fd93705f5 100644
--- a/test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php
+++ b/test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php
@@ -5,22 +5,20 @@
use Laminas\Db\Adapter\Driver\Sqlsrv\Result;
use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv;
use Laminas\Db\Adapter\Driver\Sqlsrv\Statement;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use function get_resource_type;
use function sqlsrv_connect;
-#[CoversMethod(Statement::class, 'initialize')]
-#[CoversMethod(Statement::class, 'getResource')]
-#[CoversMethod(Statement::class, 'prepare')]
-#[CoversMethod(Statement::class, 'isPrepared')]
-#[CoversMethod(Statement::class, 'execute')]
-#[Group('integration')]
-#[Group('integration-sqlserver')]
-final class StatementIntegrationTest extends AbstractIntegrationTestCase
+/**
+ * @group integration
+ * @group integration-sqlserver
+ */
+class StatementIntegrationTest extends AbstractIntegrationTest
{
- public function testInitialize(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::initialize
+ */
+ public function testInitialize()
{
$sqlsrvResource = sqlsrv_connect(
$this->variables['hostname'],
@@ -36,7 +34,10 @@ public function testInitialize(): void
unset($stmtResource, $sqlsrvResource);
}
- public function testGetResource(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::getResource
+ */
+ public function testGetResource()
{
$sqlsrvResource = sqlsrv_connect(
$this->variables['hostname'],
@@ -55,7 +56,11 @@ public function testGetResource(): void
unset($resource, $sqlsrvResource);
}
- public function testPrepare(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::prepare
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::isPrepared
+ */
+ public function testPrepare()
{
$sqlsrvResource = sqlsrv_connect(
$this->variables['hostname'],
@@ -74,7 +79,10 @@ public function testPrepare(): void
unset($resource, $sqlsrvResource);
}
- public function testExecute(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::execute
+ */
+ public function testExecute()
{
$sqlsrv = new Sqlsrv($this->variables);
$statement = $sqlsrv->createStatement("SELECT 'foo'");
diff --git a/test/unit/Adapter/Driver/Sqlsrv/StatementTest.php b/test/unit/Adapter/Driver/Sqlsrv/StatementTest.php
index 24288ef62..3905c50ab 100644
--- a/test/unit/Adapter/Driver/Sqlsrv/StatementTest.php
+++ b/test/unit/Adapter/Driver/Sqlsrv/StatementTest.php
@@ -5,28 +5,17 @@
use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv;
use Laminas\Db\Adapter\Driver\Sqlsrv\Statement;
use Laminas\Db\Adapter\ParameterContainer;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Statement::class, 'setDriver')]
-#[CoversMethod(Statement::class, 'setParameterContainer')]
-#[CoversMethod(Statement::class, 'getParameterContainer')]
-#[CoversMethod(Statement::class, 'getResource')]
-#[CoversMethod(Statement::class, 'setSql')]
-#[CoversMethod(Statement::class, 'getSql')]
-#[CoversMethod(Statement::class, 'prepare')]
-#[CoversMethod(Statement::class, 'isPrepared')]
-#[CoversMethod(Statement::class, 'execute')]
-final class StatementTest extends TestCase
+class StatementTest extends TestCase
{
- protected Statement $statement;
+ /** @var Statement */
+ protected $statement;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->statement = new Statement();
@@ -40,17 +29,26 @@ protected function tearDown(): void
{
}
- public function testSetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::setDriver
+ */
+ public function testSetDriver()
{
self::assertEquals($this->statement, $this->statement->setDriver(new Sqlsrv([])));
}
- public function testSetParameterContainer(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::setParameterContainer
+ */
+ public function testSetParameterContainer()
{
self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer()));
}
- public function testGetParameterContainer(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::getParameterContainer
+ */
+ public function testGetParameterContainer()
{
$container = new ParameterContainer();
$this->statement->setParameterContainer($container);
@@ -58,9 +56,10 @@ public function testGetParameterContainer(): void
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::getResource
* @todo Implement testGetResource().
*/
- public function testGetResource(): never
+ public function testGetResource()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -69,9 +68,10 @@ public function testGetResource(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::setSql
* @todo Implement testSetSql().
*/
- public function testSetSql(): never
+ public function testSetSql()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -80,9 +80,10 @@ public function testSetSql(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::getSql
* @todo Implement testGetSql().
*/
- public function testGetSql(): never
+ public function testGetSql()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -91,9 +92,10 @@ public function testGetSql(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::prepare
* @todo Implement testPrepare().
*/
- public function testPrepare(): never
+ public function testPrepare()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -102,9 +104,10 @@ public function testPrepare(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::isPrepared
* @todo Implement testIsPrepared().
*/
- public function testIsPrepared(): never
+ public function testIsPrepared()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
@@ -113,9 +116,10 @@ public function testIsPrepared(): never
}
/**
+ * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::execute
* @todo Implement testExecute().
*/
- public function testExecute(): never
+ public function testExecute()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
diff --git a/test/unit/Adapter/Driver/TestAsset/PdoMock.php b/test/unit/Adapter/Driver/TestAsset/PdoMock.php
index 92ba65f08..6f5324352 100644
--- a/test/unit/Adapter/Driver/TestAsset/PdoMock.php
+++ b/test/unit/Adapter/Driver/TestAsset/PdoMock.php
@@ -8,7 +8,7 @@
/**
* Stub class
*/
-final class PdoMock extends PDO
+class PdoMock extends PDO
{
public function __construct()
{
diff --git a/test/unit/Adapter/ParameterContainerTest.php b/test/unit/Adapter/ParameterContainerTest.php
index 0c2b174fd..4af8499e2 100644
--- a/test/unit/Adapter/ParameterContainerTest.php
+++ b/test/unit/Adapter/ParameterContainerTest.php
@@ -3,49 +3,27 @@
namespace LaminasTest\Db\Adapter;
use Laminas\Db\Adapter\ParameterContainer;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(ParameterContainer::class, 'offsetExists')]
-#[CoversMethod(ParameterContainer::class, 'offsetGet')]
-#[CoversMethod(ParameterContainer::class, 'offsetSet')]
-#[CoversMethod(ParameterContainer::class, 'offsetUnset')]
-#[CoversMethod(ParameterContainer::class, 'setFromArray')]
-#[CoversMethod(ParameterContainer::class, 'offsetSetMaxLength')]
-#[CoversMethod(ParameterContainer::class, 'offsetGetMaxLength')]
-#[CoversMethod(ParameterContainer::class, 'offsetHasMaxLength')]
-#[CoversMethod(ParameterContainer::class, 'offsetUnsetMaxLength')]
-#[CoversMethod(ParameterContainer::class, 'getMaxLengthIterator')]
-#[CoversMethod(ParameterContainer::class, 'offsetSetErrata')]
-#[CoversMethod(ParameterContainer::class, 'offsetGetErrata')]
-#[CoversMethod(ParameterContainer::class, 'offsetHasErrata')]
-#[CoversMethod(ParameterContainer::class, 'offsetUnsetErrata')]
-#[CoversMethod(ParameterContainer::class, 'getErrataIterator')]
-#[CoversMethod(ParameterContainer::class, 'getNamedArray')]
-#[CoversMethod(ParameterContainer::class, 'count')]
-#[CoversMethod(ParameterContainer::class, 'current')]
-#[CoversMethod(ParameterContainer::class, 'next')]
-#[CoversMethod(ParameterContainer::class, 'key')]
-#[CoversMethod(ParameterContainer::class, 'valid')]
-#[CoversMethod(ParameterContainer::class, 'rewind')]
-final class ParameterContainerTest extends TestCase
+class ParameterContainerTest extends TestCase
{
- protected ParameterContainer $parameterContainer;
+ /** @var ParameterContainer */
+ protected $parameterContainer;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->parameterContainer = new ParameterContainer(['foo' => 'bar']);
}
- #[TestDox('unit test: Test offsetExists() returns proper values via method call and isset()')]
- public function testOffsetExists(): void
+ /**
+ * @testdox unit test: Test offsetExists() returns proper values via method call and isset()
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetExists
+ */
+ public function testOffsetExists()
{
self::assertTrue($this->parameterContainer->offsetExists('foo'));
self::assertTrue(isset($this->parameterContainer['foo']));
@@ -53,8 +31,11 @@ public function testOffsetExists(): void
self::assertFalse(isset($this->parameterContainer['bar']));
}
- #[TestDox('unit test: Test offsetGet() returns proper values via method call and array access')]
- public function testOffsetGet(): void
+ /**
+ * @testdox unit test: Test offsetGet() returns proper values via method call and array access
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetGet
+ */
+ public function testOffsetGet()
{
self::assertEquals('bar', $this->parameterContainer->offsetGet('foo'));
self::assertEquals('bar', $this->parameterContainer['foo']);
@@ -63,8 +44,11 @@ public function testOffsetGet(): void
// @todo determine what should come back here
}
- #[TestDox('unit test: Test offsetSet() works via method call and array access')]
- public function testOffsetSet(): void
+ /**
+ * @testdox unit test: Test offsetSet() works via method call and array access
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetSet
+ */
+ public function testOffsetSet()
{
$this->parameterContainer->offsetSet('boo', 'baz');
self::assertEquals('baz', $this->parameterContainer->offsetGet('boo'));
@@ -111,8 +95,11 @@ public function testOffsetSet(): void
);
}
- #[TestDox('unit test: Test offsetUnset() works via method call and array access')]
- public function testOffsetUnset(): void
+ /**
+ * @testdox unit test: Test offsetUnset() works via method call and array access
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetUnset
+ */
+ public function testOffsetUnset()
{
$this->parameterContainer->offsetSet('boo', 'baz');
self::assertTrue($this->parameterContainer->offsetExists('boo'));
@@ -121,8 +108,11 @@ public function testOffsetUnset(): void
self::assertFalse($this->parameterContainer->offsetExists('boo'));
}
- #[TestDox('unit test: Test setFromArray() will populate the container')]
- public function testSetFromArray(): void
+ /**
+ * @testdox unit test: Test setFromArray() will populate the container
+ * @covers \Laminas\Db\Adapter\ParameterContainer::setFromArray
+ */
+ public function testSetFromArray()
{
$this->parameterContainer->setFromArray(['bar' => 'baz']);
self::assertEquals('baz', $this->parameterContainer['bar']);
@@ -132,8 +122,10 @@ public function testSetFromArray(): void
* Handle statement parameters - https://github.com/laminas/laminas-db/issues/47
*
* @see Insert::procesInsert as example
+ *
+ * @covers \Laminas\Db\Adapter\ParameterContainer::setFromArray
*/
- public function testSetFromArrayNamed(): void
+ public function testSetFromArrayNamed()
{
$this->parameterContainer->offsetSet('c_0', ':myparam');
$this->parameterContainer->setFromArray([':myparam' => 'baz']);
@@ -141,120 +133,167 @@ public function testSetFromArrayNamed(): void
self::assertEquals('baz', $this->parameterContainer[':myparam']);
}
- #[TestDox('
- unit test: Test offsetSetMaxLength() will persist errata data
- unit test: Test offsetGetMaxLength() return persisted errata data, if it exists
- ')]
- public function testOffsetSetAndGetMaxLength(): void
+ /**
+ * @testdox unit test: Test offsetSetMaxLength() will persist errata data
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetSetMaxLength
+ * @testdox unit test: Test offsetGetMaxLength() return persisted errata data, if it exists
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetGetMaxLength
+ */
+ public function testOffsetSetAndGetMaxLength()
{
$this->parameterContainer->offsetSetMaxLength('foo', 100);
self::assertEquals(100, $this->parameterContainer->offsetGetMaxLength('foo'));
}
- #[TestDox('unit test: Test offsetHasMaxLength() will check if errata exists for a particular key')]
- public function testOffsetHasMaxLength(): void
+ /**
+ * @testdox unit test: Test offsetHasMaxLength() will check if errata exists for a particular key
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetHasMaxLength
+ */
+ public function testOffsetHasMaxLength()
{
$this->parameterContainer->offsetSetMaxLength('foo', 100);
self::assertTrue($this->parameterContainer->offsetHasMaxLength('foo'));
}
- #[TestDox('unit test: Test offsetUnsetMaxLength() will unset data for a particular key')]
- public function testOffsetUnsetMaxLength(): void
+ /**
+ * @testdox unit test: Test offsetUnsetMaxLength() will unset data for a particular key
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetUnsetMaxLength
+ */
+ public function testOffsetUnsetMaxLength()
{
$this->parameterContainer->offsetSetMaxLength('foo', 100);
$this->parameterContainer->offsetUnsetMaxLength('foo');
self::assertNull($this->parameterContainer->offsetGetMaxLength('foo'));
}
- #[TestDox('unit test: Test getMaxLengthIterator() will return an iterator for the errata data')]
- public function testGetMaxLengthIterator(): void
+ /**
+ * @testdox unit test: Test getMaxLengthIterator() will return an iterator for the errata data
+ * @covers \Laminas\Db\Adapter\ParameterContainer::getMaxLengthIterator
+ */
+ public function testGetMaxLengthIterator()
{
$this->parameterContainer->offsetSetMaxLength('foo', 100);
$data = $this->parameterContainer->getMaxLengthIterator();
self::assertInstanceOf('ArrayIterator', $data);
}
- #[TestDox('unit test: Test offsetSetErrata() will persist errata data')]
- public function testOffsetSetErrata(): void
+ /**
+ * @testdox unit test: Test offsetSetErrata() will persist errata data
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetSetErrata
+ */
+ public function testOffsetSetErrata()
{
$this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER);
self::assertEquals(ParameterContainer::TYPE_INTEGER, $this->parameterContainer->offsetGetErrata('foo'));
}
- #[TestDox('unit test: Test offsetGetErrata() return persisted errata data, if it exists')]
- public function testOffsetGetErrata(): void
+ /**
+ * @testdox unit test: Test offsetGetErrata() return persisted errata data, if it exists
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetGetErrata
+ */
+ public function testOffsetGetErrata()
{
$this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER);
self::assertEquals(ParameterContainer::TYPE_INTEGER, $this->parameterContainer->offsetGetErrata('foo'));
}
- #[TestDox('unit test: Test offsetHasErrata() will check if errata exists for a particular key')]
- public function testOffsetHasErrata(): void
+ /**
+ * @testdox unit test: Test offsetHasErrata() will check if errata exists for a particular key
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetHasErrata
+ */
+ public function testOffsetHasErrata()
{
$this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER);
self::assertTrue($this->parameterContainer->offsetHasErrata('foo'));
}
- #[TestDox('unit test: Test offsetUnsetErrata() will unset data for a particular key')]
- public function testOffsetUnsetErrata(): void
+ /**
+ * @testdox unit test: Test offsetUnsetErrata() will unset data for a particular key
+ * @covers \Laminas\Db\Adapter\ParameterContainer::offsetUnsetErrata
+ */
+ public function testOffsetUnsetErrata()
{
$this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER);
$this->parameterContainer->offsetUnsetErrata('foo');
self::assertNull($this->parameterContainer->offsetGetErrata('foo'));
}
- #[TestDox('unit test: Test getErrataIterator() will return an iterator for the errata data')]
- public function testGetErrataIterator(): void
+ /**
+ * @testdox unit test: Test getErrataIterator() will return an iterator for the errata data
+ * @covers \Laminas\Db\Adapter\ParameterContainer::getErrataIterator
+ */
+ public function testGetErrataIterator()
{
$this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER);
$data = $this->parameterContainer->getErrataIterator();
self::assertInstanceOf('ArrayIterator', $data);
}
- #[TestDox('unit test: Test getNamedArray()')]
- public function testGetNamedArray(): void
+ /**
+ * @testdox unit test: Test getNamedArray()
+ * @covers \Laminas\Db\Adapter\ParameterContainer::getNamedArray
+ */
+ public function testGetNamedArray()
{
$data = $this->parameterContainer->getNamedArray();
self::assertEquals(['foo' => 'bar'], $data);
}
- #[TestDox('unit test: Test count() returns the proper count')]
- public function testCount(): void
+ /**
+ * @testdox unit test: Test count() returns the proper count
+ * @covers \Laminas\Db\Adapter\ParameterContainer::count
+ */
+ public function testCount()
{
self::assertEquals(1, $this->parameterContainer->count());
}
- #[TestDox('unit test: Test current() returns the current element when used as an iterator')]
- public function testCurrent(): void
+ /**
+ * @testdox unit test: Test current() returns the current element when used as an iterator
+ * @covers \Laminas\Db\Adapter\ParameterContainer::current
+ */
+ public function testCurrent()
{
$value = $this->parameterContainer->current();
self::assertEquals('bar', $value);
}
- #[TestDox('unit test: Test next() increases the pointer when used as an iterator')]
- public function testNext(): void
+ /**
+ * @testdox unit test: Test next() increases the pointer when used as an iterator
+ * @covers \Laminas\Db\Adapter\ParameterContainer::next
+ */
+ public function testNext()
{
$this->parameterContainer['bar'] = 'baz';
$this->parameterContainer->next();
self::assertEquals('baz', $this->parameterContainer->current());
}
- #[TestDox("unit test: Test key() returns the name of the current item's name")]
- public function testKey(): void
+ /**
+ * @testdox unit test: Test key() returns the name of the current item's name
+ * @covers \Laminas\Db\Adapter\ParameterContainer::key
+ */
+ public function testKey()
{
self::assertEquals('foo', $this->parameterContainer->key());
}
- #[TestDox('unit test: Test valid() returns whether the iterators current position is valid')]
- public function testValid(): void
+ /**
+ * @testdox unit test: Test valid() returns whether the iterators current position is valid
+ * @covers \Laminas\Db\Adapter\ParameterContainer::valid
+ */
+ public function testValid()
{
self::assertTrue($this->parameterContainer->valid());
$this->parameterContainer->next();
self::assertFalse($this->parameterContainer->valid());
}
- #[TestDox('unit test: Test rewind() resets the iterators pointer')]
- public function testRewind(): void
+ /**
+ * @testdox unit test: Test rewind() resets the iterators pointer
+ * @covers \Laminas\Db\Adapter\ParameterContainer::rewind
+ */
+ public function testRewind()
{
$this->parameterContainer->offsetSet('bar', 'baz');
$this->parameterContainer->next();
diff --git a/test/unit/Adapter/Platform/IbmDb2Test.php b/test/unit/Adapter/Platform/IbmDb2Test.php
index 03d77f355..3496872b9 100644
--- a/test/unit/Adapter/Platform/IbmDb2Test.php
+++ b/test/unit/Adapter/Platform/IbmDb2Test.php
@@ -3,46 +3,44 @@
namespace LaminasTest\Db\Adapter\Platform;
use Laminas\Db\Adapter\Platform\IbmDb2;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\RequiresFunction;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(IbmDb2::class, 'getName')]
-#[CoversMethod(IbmDb2::class, 'getQuoteIdentifierSymbol')]
-#[CoversMethod(IbmDb2::class, 'quoteIdentifier')]
-#[CoversMethod(IbmDb2::class, 'quoteIdentifierChain')]
-#[CoversMethod(IbmDb2::class, 'getQuoteValueSymbol')]
-#[CoversMethod(IbmDb2::class, 'quoteValue')]
-#[CoversMethod(IbmDb2::class, 'quoteTrustedValue')]
-#[CoversMethod(IbmDb2::class, 'quoteValueList')]
-#[CoversMethod(IbmDb2::class, 'getIdentifierSeparator')]
-#[CoversMethod(IbmDb2::class, 'quoteIdentifierInFragment')]
-final class IbmDb2Test extends TestCase
+use function function_exists;
+
+class IbmDb2Test extends TestCase
{
- protected IbmDb2 $platform;
+ /** @var IbmDb2 */
+ protected $platform;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->platform = new IbmDb2();
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::getName
+ */
+ public function testGetName()
{
self::assertEquals('IBM DB2', $this->platform->getName());
}
- public function testGetQuoteIdentifierSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::getQuoteIdentifierSymbol
+ */
+ public function testGetQuoteIdentifierSymbol()
{
self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol());
}
- public function testQuoteIdentifier(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteIdentifier
+ */
+ public function testQuoteIdentifier()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier'));
@@ -50,7 +48,10 @@ public function testQuoteIdentifier(): void
self::assertEquals('identifier', $platform->quoteIdentifier('identifier'));
}
- public function testQuoteIdentifierChain(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteIdentifierChain
+ */
+ public function testQuoteIdentifierChain()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier'));
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier']));
@@ -65,28 +66,33 @@ public function testQuoteIdentifierChain(): void
self::assertEquals('"schema"\"identifier"', $platform->quoteIdentifierChain(['schema', 'identifier']));
}
- public function testGetQuoteValueSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::getQuoteValueSymbol
+ */
+ public function testGetQuoteValueSymbol()
{
self::assertEquals("'", $this->platform->getQuoteValueSymbol());
}
- public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteValue
+ */
+ public function testQuoteValueRaisesNoticeWithoutPlatformSupport()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //if (! function_exists('db2_escape_string')) {
- //$this->expectNotice();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\IbmDb2 without extension/driver'
- // . ' support can introduce security vulnerabilities in a production environment'
- //);
- //}
- $this->expectNotToPerformAssertions();
+ if (! function_exists('db2_escape_string')) {
+ $this->expectNotice();
+ $this->expectNoticeMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\IbmDb2 without extension/driver'
+ . ' support can introduce security vulnerabilities in a production environment'
+ );
+ }
$this->platform->quoteValue('value');
}
- public function testQuoteValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteValue
+ */
+ public function testQuoteValue()
{
self::assertEquals("'value'", @$this->platform->quoteValue('value'));
self::assertEquals("'Foo O''Bar'", @$this->platform->quoteValue("Foo O'Bar"));
@@ -100,7 +106,10 @@ public function testQuoteValue(): void
);
}
- public function testQuoteTrustedValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteTrustedValue
+ */
+ public function testQuoteTrustedValue()
{
self::assertEquals("'value'", $this->platform->quoteTrustedValue('value'));
self::assertEquals("'Foo O''Bar'", $this->platform->quoteTrustedValue("Foo O'Bar"));
@@ -114,13 +123,25 @@ public function testQuoteTrustedValue(): void
);
}
- #[RequiresFunction('db2_escape_string')]
- public function testQuoteValueList(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteValueList
+ */
+ public function testQuoteValueList()
{
+ if (! function_exists('db2_escape_string')) {
+ $this->expectError();
+ $this->expectErrorMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\IbmDb2 without extension/driver'
+ . ' support can introduce security vulnerabilities in a production environment'
+ );
+ }
self::assertEquals("'Foo O''Bar'", $this->platform->quoteValueList("Foo O'Bar"));
}
- public function testGetIdentifierSeparator(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::getIdentifierSeparator
+ */
+ public function testGetIdentifierSeparator()
{
self::assertEquals('.', $this->platform->getIdentifierSeparator());
@@ -128,7 +149,10 @@ public function testGetIdentifierSeparator(): void
self::assertEquals('\\', $platform->getIdentifierSeparator());
}
- public function testQuoteIdentifierInFragment(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteIdentifierInFragment
+ */
+ public function testQuoteIdentifierInFragment()
{
self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar'));
self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar'));
diff --git a/test/unit/Adapter/Platform/MysqlTest.php b/test/unit/Adapter/Platform/MysqlTest.php
index 0833dcfe8..a6b1ba887 100644
--- a/test/unit/Adapter/Platform/MysqlTest.php
+++ b/test/unit/Adapter/Platform/MysqlTest.php
@@ -3,52 +3,52 @@
namespace LaminasTest\Db\Adapter\Platform;
use Laminas\Db\Adapter\Platform\Mysql;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Mysql::class, 'getName')]
-#[CoversMethod(Mysql::class, 'getQuoteIdentifierSymbol')]
-#[CoversMethod(Mysql::class, 'quoteIdentifier')]
-#[CoversMethod(Mysql::class, 'quoteIdentifierChain')]
-#[CoversMethod(Mysql::class, 'getQuoteValueSymbol')]
-#[CoversMethod(Mysql::class, 'quoteValue')]
-#[CoversMethod(Mysql::class, 'quoteTrustedValue')]
-#[CoversMethod(Mysql::class, 'quoteValueList')]
-#[CoversMethod(Mysql::class, 'getIdentifierSeparator')]
-#[CoversMethod(Mysql::class, 'quoteIdentifierInFragment')]
-final class MysqlTest extends TestCase
+class MysqlTest extends TestCase
{
- protected Mysql $platform;
+ /** @var Mysql */
+ protected $platform;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->platform = new Mysql();
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::getName
+ */
+ public function testGetName()
{
self::assertEquals('MySQL', $this->platform->getName());
}
- public function testGetQuoteIdentifierSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::getQuoteIdentifierSymbol
+ */
+ public function testGetQuoteIdentifierSymbol()
{
self::assertEquals('`', $this->platform->getQuoteIdentifierSymbol());
}
- public function testQuoteIdentifier(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteIdentifier
+ */
+ public function testQuoteIdentifier()
{
self::assertEquals('`identifier`', $this->platform->quoteIdentifier('identifier'));
self::assertEquals('`ident``ifier`', $this->platform->quoteIdentifier('ident`ifier'));
self::assertEquals('`namespace:$identifier`', $this->platform->quoteIdentifier('namespace:$identifier'));
}
- public function testQuoteIdentifierChain(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteIdentifierChain
+ */
+ public function testQuoteIdentifierChain()
{
self::assertEquals('`identifier`', $this->platform->quoteIdentifierChain('identifier'));
self::assertEquals('`identifier`', $this->platform->quoteIdentifierChain(['identifier']));
@@ -62,26 +62,31 @@ public function testQuoteIdentifierChain(): void
);
}
- public function testGetQuoteValueSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::getQuoteValueSymbol
+ */
+ public function testGetQuoteValueSymbol()
{
self::assertEquals("'", $this->platform->getQuoteValueSymbol());
}
- public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteValue
+ */
+ public function testQuoteValueRaisesNoticeWithoutPlatformSupport()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectNotice();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Mysql without extension/driver support can '
- // . 'introduce security vulnerabilities in a production environment'
- //);
- $this->expectNotToPerformAssertions();
+ $this->expectNotice();
+ $this->expectNoticeMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Mysql without extension/driver support can '
+ . 'introduce security vulnerabilities in a production environment'
+ );
$this->platform->quoteValue('value');
}
- public function testQuoteValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteValue
+ */
+ public function testQuoteValue()
{
self::assertEquals("'value'", @$this->platform->quoteValue('value'));
self::assertEquals("'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar"));
@@ -95,7 +100,10 @@ public function testQuoteValue(): void
);
}
- public function testQuoteTrustedValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteTrustedValue
+ */
+ public function testQuoteTrustedValue()
{
self::assertEquals("'value'", $this->platform->quoteTrustedValue('value'));
self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar"));
@@ -111,25 +119,31 @@ public function testQuoteTrustedValue(): void
);
}
- public function testQuoteValueList(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteValueList
+ */
+ public function testQuoteValueList()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectError();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Mysql without extension/driver support can '
- // . 'introduce security vulnerabilities in a production environment'
- //);
+ $this->expectError();
+ $this->expectErrorMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Mysql without extension/driver support can '
+ . 'introduce security vulnerabilities in a production environment'
+ );
self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar"));
}
- public function testGetIdentifierSeparator(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::getIdentifierSeparator
+ */
+ public function testGetIdentifierSeparator()
{
self::assertEquals('.', $this->platform->getIdentifierSeparator());
}
- public function testQuoteIdentifierInFragment(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteIdentifierInFragment
+ */
+ public function testQuoteIdentifierInFragment()
{
self::assertEquals('`foo`.`bar`', $this->platform->quoteIdentifierInFragment('foo.bar'));
self::assertEquals('`foo` as `bar`', $this->platform->quoteIdentifierInFragment('foo as bar'));
diff --git a/test/unit/Adapter/Platform/OracleTest.php b/test/unit/Adapter/Platform/OracleTest.php
index 7e10d7c0a..c30b253db 100644
--- a/test/unit/Adapter/Platform/OracleTest.php
+++ b/test/unit/Adapter/Platform/OracleTest.php
@@ -5,39 +5,26 @@
use Laminas\Db\Adapter\Driver\Oci8\Oci8;
use Laminas\Db\Adapter\Exception\InvalidArgumentException;
use Laminas\Db\Adapter\Platform\Oracle;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Oracle::class, '__construct')]
-#[CoversMethod(Oracle::class, 'setDriver')]
-#[CoversMethod(Oracle::class, 'getDriver')]
-#[CoversMethod(Oracle::class, 'getName')]
-#[CoversMethod(Oracle::class, 'getQuoteIdentifierSymbol')]
-#[CoversMethod(Oracle::class, 'quoteIdentifier')]
-#[CoversMethod(Oracle::class, 'quoteIdentifierChain')]
-#[CoversMethod(Oracle::class, 'getQuoteValueSymbol')]
-#[CoversMethod(Oracle::class, 'quoteValue')]
-#[CoversMethod(Oracle::class, 'quoteTrustedValue')]
-#[CoversMethod(Oracle::class, 'quoteValueList')]
-#[CoversMethod(Oracle::class, 'getIdentifierSeparator')]
-#[CoversMethod(Oracle::class, 'quoteIdentifierInFragment')]
-final class OracleTest extends TestCase
+class OracleTest extends TestCase
{
- protected Oracle $platform;
+ /** @var Oracle */
+ protected $platform;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->platform = new Oracle();
}
- public function testContructWithOptions(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::__construct
+ */
+ public function testContructWithOptions()
{
self::assertEquals('"\'test\'.\'test\'"', $this->platform->quoteIdentifier('"test"."test"'));
$plataform1 = new Oracle(['quote_identifiers' => false]);
@@ -47,51 +34,81 @@ public function testContructWithOptions(): void
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::__construct
*/
- public function testContructWithDriver(): void
- {
- $mockDriver = $this->getMockBuilder(Oci8::class)->setConstructorArgs([[]])->onlyMethods([])->getMock();
+ public function testContructWithDriver()
+ {
+ $mockDriver = $this->getMockForAbstractClass(
+ Oci8::class,
+ [[]],
+ '',
+ true,
+ true,
+ true,
+ []
+ );
$platform = new Oracle([], $mockDriver);
self::assertEquals($mockDriver, $platform->getDriver());
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::setDriver
*/
- public function testSetDriver(): void
- {
- $mockDriver = $this->getMockBuilder(Oci8::class)->setConstructorArgs([[]])->onlyMethods([])->getMock();
+ public function testSetDriver()
+ {
+ $mockDriver = $this->getMockForAbstractClass(
+ Oci8::class,
+ [[]],
+ '',
+ true,
+ true,
+ true,
+ []
+ );
$platform = $this->platform->setDriver($mockDriver);
self::assertEquals($mockDriver, $platform->getDriver());
}
- public function testSetDriverInvalid(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::setDriver
+ */
+ public function testSetDriverInvalid()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
'$driver must be a Oci8 or Oracle PDO Laminas\Db\Adapter\Driver, Oci8 instance, or Oci PDO instance'
);
- /** @psalm-suppress NullArgument - ensure an exception is thrown */
$this->platform->setDriver(null);
}
- public function testGetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::getDriver
+ */
+ public function testGetDriver()
{
self::assertNull($this->platform->getDriver());
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::getName
+ */
+ public function testGetName()
{
self::assertEquals('Oracle', $this->platform->getName());
}
- public function testGetQuoteIdentifierSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::getQuoteIdentifierSymbol
+ */
+ public function testGetQuoteIdentifierSymbol()
{
self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol());
}
- public function testQuoteIdentifier(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteIdentifier
+ */
+ public function testQuoteIdentifier()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier'));
@@ -99,7 +116,10 @@ public function testQuoteIdentifier(): void
self::assertEquals('identifier', $platform->quoteIdentifier('identifier'));
}
- public function testQuoteIdentifierChain(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteIdentifierChain
+ */
+ public function testQuoteIdentifierChain()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier'));
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier']));
@@ -111,26 +131,31 @@ public function testQuoteIdentifierChain(): void
self::assertEquals('schema.identifier', $platform->quoteIdentifierChain(['schema', 'identifier']));
}
- public function testGetQuoteValueSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::getQuoteValueSymbol
+ */
+ public function testGetQuoteValueSymbol()
{
self::assertEquals("'", $this->platform->getQuoteValueSymbol());
}
- public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteValue
+ */
+ public function testQuoteValueRaisesNoticeWithoutPlatformSupport()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectNotice();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Oracle without '
- // . 'extension/driver support can introduce security vulnerabilities in a production environment'
- //);
- $this->expectNotToPerformAssertions();
+ $this->expectNotice();
+ $this->expectNoticeMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Oracle without '
+ . 'extension/driver support can introduce security vulnerabilities in a production environment'
+ );
$this->platform->quoteValue('value');
}
- public function testQuoteValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteValue
+ */
+ public function testQuoteValue()
{
self::assertEquals("'value'", @$this->platform->quoteValue('value'));
self::assertEquals("'Foo O''Bar'", @$this->platform->quoteValue("Foo O'Bar"));
@@ -144,7 +169,10 @@ public function testQuoteValue(): void
);
}
- public function testQuoteTrustedValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteTrustedValue
+ */
+ public function testQuoteTrustedValue()
{
self::assertEquals("'value'", $this->platform->quoteTrustedValue('value'));
self::assertEquals("'Foo O''Bar'", $this->platform->quoteTrustedValue("Foo O'Bar"));
@@ -160,25 +188,31 @@ public function testQuoteTrustedValue(): void
);
}
- public function testQuoteValueList(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteValueList
+ */
+ public function testQuoteValueList()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectError();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Oracle without '
- // . 'extension/driver support can introduce security vulnerabilities in a production environment'
- //);
+ $this->expectError();
+ $this->expectErrorMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Oracle without '
+ . 'extension/driver support can introduce security vulnerabilities in a production environment'
+ );
self::assertEquals("'Foo O''Bar'", $this->platform->quoteValueList("Foo O'Bar"));
}
- public function testGetIdentifierSeparator(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::getIdentifierSeparator
+ */
+ public function testGetIdentifierSeparator()
{
self::assertEquals('.', $this->platform->getIdentifierSeparator());
}
- public function testQuoteIdentifierInFragment(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteIdentifierInFragment
+ */
+ public function testQuoteIdentifierInFragment()
{
self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar'));
self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar'));
diff --git a/test/unit/Adapter/Platform/PostgresqlTest.php b/test/unit/Adapter/Platform/PostgresqlTest.php
index b50bce013..9922a8339 100644
--- a/test/unit/Adapter/Platform/PostgresqlTest.php
+++ b/test/unit/Adapter/Platform/PostgresqlTest.php
@@ -3,45 +3,42 @@
namespace LaminasTest\Db\Adapter\Platform;
use Laminas\Db\Adapter\Platform\Postgresql;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Postgresql::class, 'getName')]
-#[CoversMethod(Postgresql::class, 'getQuoteIdentifierSymbol')]
-#[CoversMethod(Postgresql::class, 'quoteIdentifier')]
-#[CoversMethod(Postgresql::class, 'quoteIdentifierChain')]
-#[CoversMethod(Postgresql::class, 'getQuoteValueSymbol')]
-#[CoversMethod(Postgresql::class, 'quoteValue')]
-#[CoversMethod(Postgresql::class, 'quoteTrustedValue')]
-#[CoversMethod(Postgresql::class, 'quoteValueList')]
-#[CoversMethod(Postgresql::class, 'getIdentifierSeparator')]
-#[CoversMethod(Postgresql::class, 'quoteIdentifierInFragment')]
-final class PostgresqlTest extends TestCase
+class PostgresqlTest extends TestCase
{
- protected Postgresql $platform;
+ /** @var Postgresql */
+ protected $platform;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->platform = new Postgresql();
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::getName
+ */
+ public function testGetName()
{
self::assertEquals('PostgreSQL', $this->platform->getName());
}
- public function testGetQuoteIdentifierSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::getQuoteIdentifierSymbol
+ */
+ public function testGetQuoteIdentifierSymbol()
{
self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol());
}
- public function testQuoteIdentifier(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteIdentifier
+ */
+ public function testQuoteIdentifier()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier'));
self::assertEquals(
@@ -50,7 +47,10 @@ public function testQuoteIdentifier(): void
);
}
- public function testQuoteIdentifierChain(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteIdentifierChain
+ */
+ public function testQuoteIdentifierChain()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier'));
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier']));
@@ -61,26 +61,31 @@ public function testQuoteIdentifierChain(): void
);
}
- public function testGetQuoteValueSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::getQuoteValueSymbol
+ */
+ public function testGetQuoteValueSymbol()
{
self::assertEquals("'", $this->platform->getQuoteValueSymbol());
}
- public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteValue
+ */
+ public function testQuoteValueRaisesNoticeWithoutPlatformSupport()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectNotice();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Postgresql without extension/driver'
- // . ' support can introduce security vulnerabilities in a production environment'
- //);
- $this->expectNotToPerformAssertions();
+ $this->expectNotice();
+ $this->expectNoticeMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Postgresql without extension/driver'
+ . ' support can introduce security vulnerabilities in a production environment'
+ );
$this->platform->quoteValue('value');
}
- public function testQuoteValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteValue
+ */
+ public function testQuoteValue()
{
self::assertEquals("E'value'", @$this->platform->quoteValue('value'));
self::assertEquals("E'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar"));
@@ -94,7 +99,10 @@ public function testQuoteValue(): void
);
}
- public function testQuoteTrustedValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteTrustedValue
+ */
+ public function testQuoteTrustedValue()
{
self::assertEquals("E'value'", $this->platform->quoteTrustedValue('value'));
self::assertEquals("E'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar"));
@@ -110,26 +118,31 @@ public function testQuoteTrustedValue(): void
);
}
- public function testQuoteValueList(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteValueList
+ */
+ public function testQuoteValueList()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectError();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Postgresql without extension/driver'
- // . ' support can introduce security vulnerabilities in a production environment'
- //);
- $fooOBar = $this->platform->quoteTrustedValue("Foo O'Bar");
- self::assertEquals($fooOBar, $this->platform->quoteValueList("Foo O'Bar"));
+ $this->expectError();
+ $this->expectErrorMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Postgresql without extension/driver'
+ . ' support can introduce security vulnerabilities in a production environment'
+ );
+ self::assertEquals("'Foo O\'\'Bar'", $this->platform->quoteValueList("Foo O'Bar"));
}
- public function testGetIdentifierSeparator(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::getIdentifierSeparator
+ */
+ public function testGetIdentifierSeparator()
{
self::assertEquals('.', $this->platform->getIdentifierSeparator());
}
- public function testQuoteIdentifierInFragment(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteIdentifierInFragment
+ */
+ public function testQuoteIdentifierInFragment()
{
self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar'));
self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar'));
diff --git a/test/unit/Adapter/Platform/Sql92Test.php b/test/unit/Adapter/Platform/Sql92Test.php
index 7bd2649d4..bea3ef1f1 100644
--- a/test/unit/Adapter/Platform/Sql92Test.php
+++ b/test/unit/Adapter/Platform/Sql92Test.php
@@ -3,76 +3,81 @@
namespace LaminasTest\Db\Adapter\Platform;
use Laminas\Db\Adapter\Platform\Sql92;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Sql92::class, 'getName')]
-#[CoversMethod(Sql92::class, 'getQuoteIdentifierSymbol')]
-#[CoversMethod(Sql92::class, 'quoteIdentifier')]
-#[CoversMethod(Sql92::class, 'quoteIdentifierChain')]
-#[CoversMethod(Sql92::class, 'getQuoteValueSymbol')]
-#[CoversMethod(Sql92::class, 'quoteValue')]
-#[CoversMethod(Sql92::class, 'quoteTrustedValue')]
-#[CoversMethod(Sql92::class, 'quoteValueList')]
-#[CoversMethod(Sql92::class, 'getIdentifierSeparator')]
-#[CoversMethod(Sql92::class, 'quoteIdentifierInFragment')]
-final class Sql92Test extends TestCase
+class Sql92Test extends TestCase
{
- protected Sql92 $platform;
+ /** @var Sql92 */
+ protected $platform;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->platform = new Sql92();
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::getName
+ */
+ public function testGetName()
{
self::assertEquals('SQL92', $this->platform->getName());
}
- public function testGetQuoteIdentifierSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::getQuoteIdentifierSymbol
+ */
+ public function testGetQuoteIdentifierSymbol()
{
self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol());
}
- public function testQuoteIdentifier(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteIdentifier
+ */
+ public function testQuoteIdentifier()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier'));
}
- public function testQuoteIdentifierChain(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteIdentifierChain
+ */
+ public function testQuoteIdentifierChain()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier'));
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier']));
self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier']));
}
- public function testGetQuoteValueSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::getQuoteValueSymbol
+ */
+ public function testGetQuoteValueSymbol()
{
self::assertEquals("'", $this->platform->getQuoteValueSymbol());
}
- public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteValue
+ */
+ public function testQuoteValueRaisesNoticeWithoutPlatformSupport()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectNotice();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value without specific driver level support can introduce security vulnerabilities '
- // . 'in a production environment.'
- //);
- $this->expectNotToPerformAssertions();
+ $this->expectNotice();
+ $this->expectNoticeMessage(
+ 'Attempting to quote a value without specific driver level support can introduce security vulnerabilities '
+ . 'in a production environment.'
+ );
$this->platform->quoteValue('value');
}
- public function testQuoteValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteValue
+ */
+ public function testQuoteValue()
{
self::assertEquals("'value'", @$this->platform->quoteValue('value'));
self::assertEquals("'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar"));
@@ -86,7 +91,10 @@ public function testQuoteValue(): void
);
}
- public function testQuoteTrustedValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteTrustedValue
+ */
+ public function testQuoteTrustedValue()
{
self::assertEquals("'value'", $this->platform->quoteTrustedValue('value'));
self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar"));
@@ -102,25 +110,31 @@ public function testQuoteTrustedValue(): void
);
}
- public function testQuoteValueList(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteValueList
+ */
+ public function testQuoteValueList()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectError();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value without specific driver level support can introduce security vulnerabilities '
- // . 'in a production environment.'
- //);
+ $this->expectError();
+ $this->expectErrorMessage(
+ 'Attempting to quote a value without specific driver level support can introduce security vulnerabilities '
+ . 'in a production environment.'
+ );
self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar"));
}
- public function testGetIdentifierSeparator(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::getIdentifierSeparator
+ */
+ public function testGetIdentifierSeparator()
{
self::assertEquals('.', $this->platform->getIdentifierSeparator());
}
- public function testQuoteIdentifierInFragment(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteIdentifierInFragment
+ */
+ public function testQuoteIdentifierInFragment()
{
self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar'));
self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar'));
diff --git a/test/unit/Adapter/Platform/SqlServerTest.php b/test/unit/Adapter/Platform/SqlServerTest.php
index bbf4655d6..e4db83f56 100644
--- a/test/unit/Adapter/Platform/SqlServerTest.php
+++ b/test/unit/Adapter/Platform/SqlServerTest.php
@@ -4,80 +4,84 @@
use Laminas\Db\Adapter\Driver\Pdo\Pdo;
use Laminas\Db\Adapter\Platform\SqlServer;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
use function restore_error_handler;
use function set_error_handler;
-#[CoversMethod(SqlServer::class, 'getName')]
-#[CoversMethod(SqlServer::class, 'getQuoteIdentifierSymbol')]
-#[CoversMethod(SqlServer::class, 'quoteIdentifier')]
-#[CoversMethod(SqlServer::class, 'quoteIdentifierChain')]
-#[CoversMethod(SqlServer::class, 'getQuoteValueSymbol')]
-#[CoversMethod(SqlServer::class, 'quoteValue')]
-#[CoversMethod(SqlServer::class, 'quoteTrustedValue')]
-#[CoversMethod(SqlServer::class, 'quoteValueList')]
-#[CoversMethod(SqlServer::class, 'getIdentifierSeparator')]
-#[CoversMethod(SqlServer::class, 'quoteIdentifierInFragment')]
-#[CoversMethod(SqlServer::class, 'setDriver')]
-final class SqlServerTest extends TestCase
+class SqlServerTest extends TestCase
{
- protected SqlServer $platform;
+ /** @var SqlServer */
+ protected $platform;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->platform = new SqlServer();
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::getName
+ */
+ public function testGetName()
{
self::assertEquals('SQLServer', $this->platform->getName());
}
- public function testGetQuoteIdentifierSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::getQuoteIdentifierSymbol
+ */
+ public function testGetQuoteIdentifierSymbol()
{
self::assertEquals(['[', ']'], $this->platform->getQuoteIdentifierSymbol());
}
- public function testQuoteIdentifier(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteIdentifier
+ */
+ public function testQuoteIdentifier()
{
self::assertEquals('[identifier]', $this->platform->quoteIdentifier('identifier'));
}
- public function testQuoteIdentifierChain(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteIdentifierChain
+ */
+ public function testQuoteIdentifierChain()
{
self::assertEquals('[identifier]', $this->platform->quoteIdentifierChain('identifier'));
self::assertEquals('[identifier]', $this->platform->quoteIdentifierChain(['identifier']));
self::assertEquals('[schema].[identifier]', $this->platform->quoteIdentifierChain(['schema', 'identifier']));
}
- public function testGetQuoteValueSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::getQuoteValueSymbol
+ */
+ public function testGetQuoteValueSymbol()
{
self::assertEquals("'", $this->platform->getQuoteValueSymbol());
}
- public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteValue
+ */
+ public function testQuoteValueRaisesNoticeWithoutPlatformSupport()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectNotice();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\SqlServer without extension/driver support can '
- // . 'introduce security vulnerabilities in a production environment'
- //);
- $this->expectNotToPerformAssertions();
+ $this->expectNotice();
+ $this->expectNoticeMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\SqlServer without extension/driver support can '
+ . 'introduce security vulnerabilities in a production environment'
+ );
$this->platform->quoteValue('value');
}
- public function testQuoteValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteValue
+ */
+ public function testQuoteValue()
{
self::assertEquals("'value'", @$this->platform->quoteValue('value'));
self::assertEquals("'Foo O''Bar'", @$this->platform->quoteValue("Foo O'Bar"));
@@ -91,7 +95,10 @@ public function testQuoteValue(): void
);
}
- public function testQuoteTrustedValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteTrustedValue
+ */
+ public function testQuoteTrustedValue()
{
self::assertEquals("'value'", $this->platform->quoteTrustedValue('value'));
self::assertEquals("'Foo O''Bar'", $this->platform->quoteTrustedValue("Foo O'Bar"));
@@ -105,25 +112,31 @@ public function testQuoteTrustedValue(): void
);
}
- public function testQuoteValueList(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteValueList
+ */
+ public function testQuoteValueList()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectError();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\SqlServer without extension/driver support can '
- // . 'introduce security vulnerabilities in a production environment'
- //);
+ $this->expectError();
+ $this->expectErrorMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\SqlServer without extension/driver support can '
+ . 'introduce security vulnerabilities in a production environment'
+ );
self::assertEquals("'Foo O''Bar'", $this->platform->quoteValueList("Foo O'Bar"));
}
- public function testGetIdentifierSeparator(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::getIdentifierSeparator
+ */
+ public function testGetIdentifierSeparator()
{
self::assertEquals('.', $this->platform->getIdentifierSeparator());
}
- public function testQuoteIdentifierInFragment(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteIdentifierInFragment
+ */
+ public function testQuoteIdentifierInFragment()
{
self::assertEquals('[foo].[bar]', $this->platform->quoteIdentifierInFragment('foo.bar'));
self::assertEquals('[foo] as [bar]', $this->platform->quoteIdentifierInFragment('foo as bar'));
@@ -153,16 +166,19 @@ public function testQuoteIdentifierInFragment(): void
);
}
- public function testSetDriver(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\SqlServer::setDriver
+ */
+ public function testSetDriver()
{
$this->expectNotToPerformAssertions();
$driver = new Pdo(['pdodriver' => 'sqlsrv']);
$this->platform->setDriver($driver);
}
- public function testPlatformQuotesNullByteCharacter(): void
+ public function testPlatformQuotesNullByteCharacter()
{
- set_error_handler(function (): void {
+ set_error_handler(function () {
});
$string = "1\0";
$value = $this->platform->quoteValue($string);
diff --git a/test/unit/Adapter/Platform/SqliteTest.php b/test/unit/Adapter/Platform/SqliteTest.php
index d61807915..fa14f5b42 100644
--- a/test/unit/Adapter/Platform/SqliteTest.php
+++ b/test/unit/Adapter/Platform/SqliteTest.php
@@ -4,8 +4,6 @@
use Laminas\Db\Adapter\Driver\Pdo\Pdo;
use Laminas\Db\Adapter\Platform\Sqlite;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
use function file_exists;
@@ -13,72 +11,79 @@
use function touch;
use function unlink;
-#[CoversMethod(Sqlite::class, 'getName')]
-#[CoversMethod(Sqlite::class, 'getQuoteIdentifierSymbol')]
-#[CoversMethod(Sqlite::class, 'quoteIdentifier')]
-#[CoversMethod(Sqlite::class, 'quoteIdentifierChain')]
-#[CoversMethod(Sqlite::class, 'getQuoteValueSymbol')]
-#[CoversMethod(Sqlite::class, 'quoteValue')]
-#[CoversMethod(Sqlite::class, 'quoteTrustedValue')]
-#[CoversMethod(Sqlite::class, 'quoteValueList')]
-#[CoversMethod(Sqlite::class, 'getIdentifierSeparator')]
-#[CoversMethod(Sqlite::class, 'quoteIdentifierInFragment')]
-final class SqliteTest extends TestCase
+class SqliteTest extends TestCase
{
- protected Sqlite $platform;
+ /** @var Sqlite */
+ protected $platform;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->platform = new Sqlite();
}
- public function testGetName(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::getName
+ */
+ public function testGetName()
{
self::assertEquals('SQLite', $this->platform->getName());
}
- public function testGetQuoteIdentifierSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::getQuoteIdentifierSymbol
+ */
+ public function testGetQuoteIdentifierSymbol()
{
self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol());
}
- public function testQuoteIdentifier(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteIdentifier
+ */
+ public function testQuoteIdentifier()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier'));
}
- public function testQuoteIdentifierChain(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteIdentifierChain
+ */
+ public function testQuoteIdentifierChain()
{
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier'));
self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier']));
self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier']));
}
- public function testGetQuoteValueSymbol(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::getQuoteValueSymbol
+ */
+ public function testGetQuoteValueSymbol()
{
self::assertEquals("'", $this->platform->getQuoteValueSymbol());
}
- public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteValue
+ */
+ public function testQuoteValueRaisesNoticeWithoutPlatformSupport()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectNotice();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Sqlite without extension/driver support can '
- // . 'introduce security vulnerabilities in a production environment'
- //);
- $this->expectNotToPerformAssertions();
+ $this->expectNotice();
+ $this->expectNoticeMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Sqlite without extension/driver support can '
+ . 'introduce security vulnerabilities in a production environment'
+ );
$this->platform->quoteValue('value');
}
- public function testQuoteValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteValue
+ */
+ public function testQuoteValue()
{
self::assertEquals("'value'", @$this->platform->quoteValue('value'));
self::assertEquals("'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar"));
@@ -92,7 +97,10 @@ public function testQuoteValue(): void
);
}
- public function testQuoteTrustedValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteTrustedValue
+ */
+ public function testQuoteTrustedValue()
{
self::assertEquals("'value'", $this->platform->quoteTrustedValue('value'));
self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar"));
@@ -108,25 +116,31 @@ public function testQuoteTrustedValue(): void
);
}
- public function testQuoteValueList(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteValueList
+ */
+ public function testQuoteValueList()
{
- /**
- * @todo Determine if vulnerability warning is required during unit testing
- */
- //$this->expectError();
- //$this->expectExceptionMessage(
- // 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Sqlite without extension/driver support can '
- // . 'introduce security vulnerabilities in a production environment'
- //);
+ $this->expectError();
+ $this->expectErrorMessage(
+ 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Sqlite without extension/driver support can '
+ . 'introduce security vulnerabilities in a production environment'
+ );
self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar"));
}
- public function testGetIdentifierSeparator(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::getIdentifierSeparator
+ */
+ public function testGetIdentifierSeparator()
{
self::assertEquals('.', $this->platform->getIdentifierSeparator());
}
- public function testQuoteIdentifierInFragment(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteIdentifierInFragment
+ */
+ public function testQuoteIdentifierInFragment()
{
self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar'));
self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar'));
@@ -156,7 +170,11 @@ public function testQuoteIdentifierInFragment(): void
);
}
- public function testCanCloseConnectionAfterQuoteValue(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteValue
+ * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteTrustedValue
+ */
+ public function testCanCloseConnectionAfterQuoteValue()
{
// Creating the SQLite database file
$filePath = realpath(__DIR__) . "/_files/sqlite.db";
diff --git a/test/unit/Adapter/Profiler/ProfilerTest.php b/test/unit/Adapter/Profiler/ProfilerTest.php
index ba6245673..8a343c6b5 100644
--- a/test/unit/Adapter/Profiler/ProfilerTest.php
+++ b/test/unit/Adapter/Profiler/ProfilerTest.php
@@ -6,29 +6,26 @@
use Laminas\Db\Adapter\Exception\RuntimeException;
use Laminas\Db\Adapter\Profiler\Profiler;
use Laminas\Db\Adapter\StatementContainer;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Profiler::class, 'profilerStart')]
-#[CoversMethod(Profiler::class, 'profilerFinish')]
-#[CoversMethod(Profiler::class, 'getLastProfile')]
-#[CoversMethod(Profiler::class, 'getProfiles')]
-final class ProfilerTest extends TestCase
+class ProfilerTest extends TestCase
{
- protected Profiler $profiler;
+ /** @var Profiler */
+ protected $profiler;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->profiler = new Profiler();
}
- public function testProfilerStart(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Profiler\Profiler::profilerStart
+ */
+ public function testProfilerStart()
{
$ret = $this->profiler->profilerStart('SELECT * FROM FOO');
self::assertSame($this->profiler, $ret);
@@ -40,7 +37,10 @@ public function testProfilerStart(): void
$this->profiler->profilerStart(5);
}
- public function testProfilerFinish(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Profiler\Profiler::profilerFinish
+ */
+ public function testProfilerFinish()
{
$this->profiler->profilerStart('SELECT * FROM FOO');
$ret = $this->profiler->profilerFinish();
@@ -52,7 +52,10 @@ public function testProfilerFinish(): void
$profiler->profilerFinish();
}
- public function testGetLastProfile(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Profiler\Profiler::getLastProfile
+ */
+ public function testGetLastProfile()
{
$this->profiler->profilerStart('SELECT * FROM FOO');
$this->profiler->profilerFinish();
@@ -64,7 +67,10 @@ public function testGetLastProfile(): void
self::assertIsFloat($profile['elapse']);
}
- public function testGetProfiles(): void
+ /**
+ * @covers \Laminas\Db\Adapter\Profiler\Profiler::getProfiles
+ */
+ public function testGetProfiles()
{
$this->profiler->profilerStart('SELECT * FROM FOO1');
$this->profiler->profilerFinish();
diff --git a/test/unit/Adapter/TestAsset/ConcreteAdapterAwareObject.php b/test/unit/Adapter/TestAsset/ConcreteAdapterAwareObject.php
index a264c4c1a..4d98dfacb 100644
--- a/test/unit/Adapter/TestAsset/ConcreteAdapterAwareObject.php
+++ b/test/unit/Adapter/TestAsset/ConcreteAdapterAwareObject.php
@@ -10,8 +10,12 @@ class ConcreteAdapterAwareObject implements AdapterAwareInterface
{
use AdapterAwareTrait;
- public function __construct(private readonly array $options = [])
+ /** @var array */
+ private $options;
+
+ public function __construct(array $options = [])
{
+ $this->options = $options;
}
public function getAdapter(): ?AdapterInterface
diff --git a/test/unit/ConfigProviderTest.php b/test/unit/ConfigProviderTest.php
index 2596d1e75..622a849b7 100644
--- a/test/unit/ConfigProviderTest.php
+++ b/test/unit/ConfigProviderTest.php
@@ -4,13 +4,13 @@
use Laminas\Db\Adapter;
use Laminas\Db\ConfigProvider;
-use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;
+use Zend\Db\Adapter\AdapterInterface;
-final class ConfigProviderTest extends TestCase
+class ConfigProviderTest extends TestCase
{
/** @var array> */
- private array $config = [
+ private $config = [
'abstract_factories' => [
Adapter\AdapterAbstractServiceFactory::class,
],
@@ -18,7 +18,9 @@ final class ConfigProviderTest extends TestCase
Adapter\AdapterInterface::class => Adapter\AdapterServiceFactory::class,
],
'aliases' => [
- Adapter\Adapter::class => Adapter\AdapterInterface::class,
+ Adapter\Adapter::class => Adapter\AdapterInterface::class,
+ AdapterInterface::class => Adapter\AdapterInterface::class,
+ \Zend\Db\Adapter\Adapter::class => Adapter\Adapter::class,
],
];
@@ -29,8 +31,10 @@ public function testProvidesExpectedConfiguration(): ConfigProvider
return $provider;
}
- #[Depends('testProvidesExpectedConfiguration')]
- public function testInvocationProvidesDependencyConfiguration(ConfigProvider $provider): void
+ /**
+ * @depends testProvidesExpectedConfiguration
+ */
+ public function testInvocationProvidesDependencyConfiguration(ConfigProvider $provider)
{
self::assertEquals(['dependencies' => $provider->getDependencyConfig()], $provider());
}
diff --git a/test/unit/DeprecatedAssertionsTrait.php b/test/unit/DeprecatedAssertionsTrait.php
index 07d8850fd..d55e916a1 100644
--- a/test/unit/DeprecatedAssertionsTrait.php
+++ b/test/unit/DeprecatedAssertionsTrait.php
@@ -3,33 +3,30 @@
namespace LaminasTest\Db;
use PHPUnit\Framework\Assert;
-use ReflectionException;
use ReflectionProperty;
trait DeprecatedAssertionsTrait
{
/**
- * @throws ReflectionException
+ * @param mixed $expected
*/
public static function assertAttributeEquals(
- mixed $expected,
+ $expected,
string $attribute,
object $instance,
string $message = ''
): void {
$r = new ReflectionProperty($instance, $attribute);
- /** @psalm-suppress UnusedMethodCall */
$r->setAccessible(true);
Assert::assertEquals($expected, $r->getValue($instance), $message);
}
/**
- * @throws ReflectionException
+ * @return mixed
*/
- public function readAttribute(object $instance, string $attribute): mixed
+ public function readAttribute(object $instance, string $attribute)
{
$r = new ReflectionProperty($instance, $attribute);
- /** @psalm-suppress UnusedMethodCall */
$r->setAccessible(true);
return $r->getValue($instance);
}
diff --git a/test/unit/Metadata/Source/AbstractSourceTest.php b/test/unit/Metadata/Source/AbstractSourceTest.php
index 3cf4632f5..156d565db 100644
--- a/test/unit/Metadata/Source/AbstractSourceTest.php
+++ b/test/unit/Metadata/Source/AbstractSourceTest.php
@@ -4,34 +4,27 @@
use Laminas\Db\Metadata\Object\ConstraintKeyObject;
use Laminas\Db\Metadata\Source\AbstractSource;
-use Override;
-use PHPUnit\Framework\MockObject\Exception;
-use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
use ReflectionProperty;
-final class AbstractSourceTest extends TestCase
+class AbstractSourceTest extends TestCase
{
/** @var AbstractSource */
- protected MockObject|AbstractSource $abstractSourceMock;
+ protected $abstractSourceMock;
- /**
- * @throws Exception
- */
- #[Override]
protected function setUp(): void
{
- $this->abstractSourceMock = $this->getMockBuilder(AbstractSource::class)->setConstructorArgs([])->onlyMethods([])->disableOriginalConstructor()->getMock();
+ $this->abstractSourceMock = $this->getMockForAbstractClass(
+ AbstractSource::class,
+ [],
+ '',
+ false
+ );
}
- /**
- * @throws ReflectionException
- */
- public function testGetConstraintKeys(): void
+ public function testGetConstraintKeys()
{
$refProp = new ReflectionProperty($this->abstractSourceMock, 'data');
- /** @psalm-suppress UnusedMethodCall */
$refProp->setAccessible(true);
// internal data
@@ -63,6 +56,9 @@ public function testGetConstraintKeys(): void
$constraints = $this->abstractSourceMock->getConstraintKeys('bam_constraint', 'bar_table', 'foo_schema');
self::assertCount(1, $constraints);
+ /**
+ * @var ConstraintKeyObject $constraintKeyObj
+ */
$constraintKeyObj = $constraints[0];
self::assertInstanceOf(ConstraintKeyObject::class, $constraintKeyObj);
diff --git a/test/unit/Metadata/Source/FactoryTest.php b/test/unit/Metadata/Source/FactoryTest.php
index 9130edaeb..813ed455e 100644
--- a/test/unit/Metadata/Source/FactoryTest.php
+++ b/test/unit/Metadata/Source/FactoryTest.php
@@ -11,23 +11,28 @@
use Laminas\Db\Metadata\Source\PostgresqlMetadata;
use Laminas\Db\Metadata\Source\SqliteMetadata;
use Laminas\Db\Metadata\Source\SqlServerMetadata;
-use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-final class FactoryTest extends TestCase
+class FactoryTest extends TestCase
{
/**
- * @param class-string $expectedReturnClass
+ * @dataProvider validAdapterProvider
+ * @param string $expectedReturnClass
*/
- #[DataProvider('validAdapterProvider')]
- public function testCreateSourceFromAdapter(string $adapterName, string $expectedReturnClass): void
+ public function testCreateSourceFromAdapter(Adapter $adapter, $expectedReturnClass)
{
- /**
- * @param string $platformName
- * @return Adapter&MockObject
- */
- $createAdapterForPlatform = function (string $platformName): Adapter&MockObject {
+ $source = Factory::createSourceFromAdapter($adapter);
+
+ self::assertInstanceOf(MetadataInterface::class, $source);
+ self::assertInstanceOf($expectedReturnClass, $source);
+ }
+
+ /** @psalm-return array */
+ public function validAdapterProvider(): array
+ {
+ /** @return Adapter&MockObject */
+ $createAdapterForPlatform = function (string $platformName) {
$platform = $this->getMockBuilder(PlatformInterface::class)->getMock();
$platform
->expects($this->any())
@@ -46,22 +51,13 @@ public function testCreateSourceFromAdapter(string $adapterName, string $expecte
return $adapter;
};
- $adapter = $createAdapterForPlatform($adapterName);
- $source = Factory::createSourceFromAdapter($adapter);
-
- self::assertInstanceOf(MetadataInterface::class, $source);
- self::assertInstanceOf($expectedReturnClass, $source);
- }
-
- public static function validAdapterProvider(): array
- {
return [
- // Description => [adapterName, expected return class]
- 'MySQL' => ['MySQL', MysqlMetadata::class],
- 'SQLServer' => ['SQLServer', SqlServerMetadata::class],
- 'SQLite' => ['SQLite', SqliteMetadata::class],
- 'PostgreSQL' => ['PostgreSQL', PostgresqlMetadata::class],
- 'Oracle' => ['Oracle', OracleMetadata::class],
+ // Description => [adapter, expected return class]
+ 'MySQL' => [$createAdapterForPlatform('MySQL'), MysqlMetadata::class],
+ 'SQLServer' => [$createAdapterForPlatform('SQLServer'), SqlServerMetadata::class],
+ 'SQLite' => [$createAdapterForPlatform('SQLite'), SqliteMetadata::class],
+ 'PostgreSQL' => [$createAdapterForPlatform('PostgreSQL'), PostgresqlMetadata::class],
+ 'Oracle' => [$createAdapterForPlatform('Oracle'), OracleMetadata::class],
];
}
}
diff --git a/test/unit/Metadata/Source/OracleMetadataTestCase.php b/test/unit/Metadata/Source/OracleMetadataTest.php
similarity index 84%
rename from test/unit/Metadata/Source/OracleMetadataTestCase.php
rename to test/unit/Metadata/Source/OracleMetadataTest.php
index 14a7a17b8..138a935ec 100644
--- a/test/unit/Metadata/Source/OracleMetadataTestCase.php
+++ b/test/unit/Metadata/Source/OracleMetadataTest.php
@@ -6,27 +6,27 @@
use Laminas\Db\Adapter\Driver\Oci8\Statement;
use Laminas\Db\Metadata\Object\ConstraintObject;
use Laminas\Db\Metadata\Source\OracleMetadata;
-use LaminasTest\Db\Adapter\Driver\Oci8\AbstractIntegrationTestCase;
-use Override;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\RequiresPhpExtension;
+use LaminasTest\Db\Adapter\Driver\Oci8\AbstractIntegrationTest;
use PHPUnit\Framework\MockObject\MockObject;
use function count;
use function extension_loaded;
-#[RequiresPhpExtension('oci8')]
-final class OracleMetadataTestCase extends AbstractIntegrationTestCase
+/**
+ * @requires extension oci8
+ */
+class OracleMetadataTest extends AbstractIntegrationTest
{
- protected OracleMetadata $metadata;
+ /** @var OracleMetadata */
+ protected $metadata;
- protected Adapter $adapter;
+ /** @var Adapter */
+ protected $adapter;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
if (! extension_loaded('oci8')) {
@@ -38,8 +38,10 @@ protected function setUp(): void
$this->metadata = new OracleMetadata($this->adapter);
}
- #[DataProvider('constraintDataProvider')]
- public function testGetConstraints(array $constraintData): void
+ /**
+ * @dataProvider constraintDataProvider
+ */
+ public function testGetConstraints(array $constraintData)
{
$statement = $this->getMockBuilder(Statement::class)
->getMock();
@@ -67,7 +69,10 @@ public function testGetConstraints(array $constraintData): void
);
}
- public static function constraintDataProvider(): array
+ /**
+ * @return array
+ */
+ public function constraintDataProvider()
{
return [
[
diff --git a/test/unit/Metadata/Source/SqliteMetadataTest.php b/test/unit/Metadata/Source/SqliteMetadataTest.php
index 1767ab994..0fa2ddcc0 100644
--- a/test/unit/Metadata/Source/SqliteMetadataTest.php
+++ b/test/unit/Metadata/Source/SqliteMetadataTest.php
@@ -2,31 +2,30 @@
namespace LaminasTest\Db\Metadata\Source;
-use Exception;
use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Metadata\Object\ConstraintKeyObject;
use Laminas\Db\Metadata\Object\ConstraintObject;
use Laminas\Db\Metadata\Object\TriggerObject;
use Laminas\Db\Metadata\Source\SqliteMetadata;
-use Override;
-use PHPUnit\Framework\Attributes\Group;
-use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\TestCase;
use function extension_loaded;
-#[RequiresPhpExtension('pdo_sqlite')]
-final class SqliteMetadataTest extends TestCase
+/**
+ * @requires extension pdo_sqlite
+ */
+class SqliteMetadataTest extends TestCase
{
- protected SqliteMetadata $metadata;
+ /** @var SqliteMetadata */
+ protected $metadata;
- protected Adapter $adapter;
+ /** @var Adapter */
+ protected $adapter;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
if (! extension_loaded('pdo_sqlite')) {
@@ -39,29 +38,26 @@ protected function setUp(): void
$this->metadata = new SqliteMetadata($this->adapter);
}
- public function testGetSchemas(): void
+ public function testGetSchemas()
{
$schemas = $this->metadata->getSchemas();
self::assertContains('main', $schemas);
self::assertCount(1, $schemas);
}
- public function testGetTableNames(): void
+ public function testGetTableNames()
{
$tables = $this->metadata->getTableNames('main');
self::assertCount(0, $tables);
}
- /**
- * @throws Exception
- */
- public function testGetColumnNames(): void
+ public function testGetColumnNames()
{
$columns = $this->metadata->getColumnNames(null, 'main');
self::assertCount(0, $columns);
}
- public function testGetConstraints(): void
+ public function testGetConstraints()
{
$constraints = $this->metadata->getConstraints(null, 'main');
self::assertCount(0, $constraints);
@@ -71,8 +67,10 @@ public function testGetConstraints(): void
);
}
- #[Group('Laminas-3719')]
- public function testGetConstraintKeys(): void
+ /**
+ * @group Laminas-3719
+ */
+ public function testGetConstraintKeys()
{
$keys = $this->metadata->getConstraintKeys(
null,
@@ -86,7 +84,7 @@ public function testGetConstraintKeys(): void
);
}
- public function testGetTriggers(): void
+ public function testGetTriggers()
{
$triggers = $this->metadata->getTriggers('main');
self::assertCount(0, $triggers);
diff --git a/test/unit/ResultSet/AbstractResultSetIntegrationTest.php b/test/unit/ResultSet/AbstractResultSetIntegrationTest.php
index 0fac85541..1199faf4d 100644
--- a/test/unit/ResultSet/AbstractResultSetIntegrationTest.php
+++ b/test/unit/ResultSet/AbstractResultSetIntegrationTest.php
@@ -4,46 +4,46 @@
use Laminas\Db\Adapter\Driver\ResultInterface;
use Laminas\Db\ResultSet\AbstractResultSet;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(AbstractResultSet::class, 'current')]
-final class AbstractResultSetIntegrationTest extends TestCase
+class AbstractResultSetIntegrationTest extends TestCase
{
- protected AbstractResultSet|MockObject $resultSet;
+ /** @var AbstractResultSet|MockObject */
+ protected $resultSet;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
- *
- * @throws Exception
*/
- #[Override]
protected function setUp(): void
{
- $this->resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $this->resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
}
- public function testCurrentCallsDataSourceCurrentAsManyTimesWithoutBuffer(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::current
+ */
+ public function testCurrentCallsDataSourceCurrentAsManyTimesWithoutBuffer()
{
$result = $this->getMockBuilder(ResultInterface::class)->getMock();
$this->resultSet->initialize($result);
- $result->expects($this->exactly(3))->method('current')->willReturn(['foo' => 'bar']);
+ $result->expects($this->exactly(3))->method('current')->will($this->returnValue(['foo' => 'bar']));
$value1 = $this->resultSet->current();
$value2 = $this->resultSet->current();
$this->resultSet->current();
self::assertEquals($value1, $value2);
}
- public function testCurrentCallsDataSourceCurrentOnceWithBuffer(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::current
+ */
+ public function testCurrentCallsDataSourceCurrentOnceWithBuffer()
{
$result = $this->getMockBuilder(ResultInterface::class)->getMock();
$this->resultSet->buffer();
$this->resultSet->initialize($result);
- $result->expects($this->once())->method('current')->willReturn(['foo' => 'bar']);
+ $result->expects($this->once())->method('current')->will($this->returnValue(['foo' => 'bar']));
$value1 = $this->resultSet->current();
$value2 = $this->resultSet->current();
$this->resultSet->current();
diff --git a/test/unit/ResultSet/AbstractResultSetTest.php b/test/unit/ResultSet/AbstractResultSetTest.php
index a7b224ede..8366cc1c7 100644
--- a/test/unit/ResultSet/AbstractResultSetTest.php
+++ b/test/unit/ResultSet/AbstractResultSetTest.php
@@ -8,45 +8,32 @@
use Laminas\Db\ResultSet\AbstractResultSet;
use Laminas\Db\ResultSet\Exception\InvalidArgumentException;
use Laminas\Db\ResultSet\Exception\RuntimeException;
-use Override;
use PDOStatement;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function assert;
-#[CoversMethod(AbstractResultSet::class, 'initialize')]
-#[CoversMethod(AbstractResultSet::class, 'buffer')]
-#[CoversMethod(AbstractResultSet::class, 'isBuffered')]
-#[CoversMethod(AbstractResultSet::class, 'getDataSource')]
-#[CoversMethod(AbstractResultSet::class, 'getFieldCount')]
-#[CoversMethod(AbstractResultSet::class, 'next')]
-#[CoversMethod(AbstractResultSet::class, 'key')]
-#[CoversMethod(AbstractResultSet::class, 'current')]
-#[CoversMethod(AbstractResultSet::class, 'valid')]
-#[CoversMethod(AbstractResultSet::class, 'rewind')]
-#[CoversMethod(AbstractResultSet::class, 'count')]
-#[CoversMethod(AbstractResultSet::class, 'toArray')]
-final class AbstractResultSetTest extends TestCase
+class AbstractResultSetTest extends TestCase
{
/** @var MockObject */
- protected AbstractResultSet|MockObject $resultSet;
+ protected $resultSet;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
- $this->resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $this->resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
}
- public function testInitialize(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::initialize
+ */
+ public function testInitialize()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
self::assertSame($resultSet, $resultSet->initialize([
['id' => 1, 'name' => 'one'],
@@ -61,26 +48,35 @@ public function testInitialize(): void
$resultSet->initialize('foo');
}
- public function testInitializeDoesNotCallCount(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::initialize
+ */
+ public function testInitializeDoesNotCallCount()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
- $result = $this->getMockBuilder(ResultInterface::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
+ $result = $this->getMockForAbstractClass(ResultInterface::class);
$result->expects($this->never())->method('count');
$resultSet->initialize($result);
}
- public function testInitializeWithEmptyArray(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::initialize
+ */
+ public function testInitializeWithEmptyArray()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
self::assertSame($resultSet, $resultSet->initialize([]));
}
- public function testBuffer(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::buffer
+ */
+ public function testBuffer()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
self::assertSame($resultSet, $resultSet->buffer());
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -92,17 +88,23 @@ public function testBuffer(): void
$resultSet->buffer();
}
- public function testIsBuffered(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::isBuffered
+ */
+ public function testIsBuffered()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
self::assertFalse($resultSet->isBuffered());
$resultSet->buffer();
self::assertTrue($resultSet->isBuffered());
}
- public function testGetDataSource(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::getDataSource
+ */
+ public function testGetDataSource()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -111,18 +113,24 @@ public function testGetDataSource(): void
self::assertInstanceOf(ArrayIterator::class, $resultSet->getDataSource());
}
- public function testGetFieldCount(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::getFieldCount
+ */
+ public function testGetFieldCount()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
]));
self::assertEquals(2, $resultSet->getFieldCount());
}
- public function testNext(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::next
+ */
+ public function testNext()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -131,9 +139,12 @@ public function testNext(): void
self::assertNull($resultSet->next());
}
- public function testKey(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::key
+ */
+ public function testKey()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -147,9 +158,12 @@ public function testKey(): void
self::assertEquals(3, $resultSet->key());
}
- public function testCurrent(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::current
+ */
+ public function testCurrent()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -158,9 +172,12 @@ public function testCurrent(): void
self::assertEquals(['id' => 1, 'name' => 'one'], $resultSet->current());
}
- public function testValid(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::valid
+ */
+ public function testValid()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -173,9 +190,12 @@ public function testValid(): void
self::assertFalse($resultSet->valid());
}
- public function testRewind(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::rewind
+ */
+ public function testRewind()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -184,9 +204,12 @@ public function testRewind(): void
self::assertNull($resultSet->rewind());
}
- public function testCount(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::count
+ */
+ public function testCount()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -195,9 +218,12 @@ public function testCount(): void
self::assertEquals(3, $resultSet->count());
}
- public function testToArray(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::toArray
+ */
+ public function testToArray()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -215,11 +241,12 @@ public function testToArray(): void
/**
* Test multiple iterations with buffer
+ *
+ * @group issue-6845
*/
- #[Group('issue-6845')]
- public function testBufferIterations(): void
+ public function testBufferIterations()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$resultSet->initialize(new ArrayIterator([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
@@ -246,11 +273,12 @@ public function testBufferIterations(): void
/**
* Test multiple iterations with buffer with multiple rewind() calls
+ *
+ * @group issue-6845
*/
- #[Group('issue-6845')]
- public function testMultipleRewindBufferIterations(): void
+ public function testMultipleRewindBufferIterations()
{
- $resultSet = $this->getMockBuilder(AbstractResultSet::class)->onlyMethods([])->getMock();
+ $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class);
$result = new Result();
$stub = $this->getMockBuilder(PDOStatement::class)->getMock();
$data = new ArrayIterator([
@@ -261,11 +289,11 @@ public function testMultipleRewindBufferIterations(): void
assert($stub instanceof PDOStatement); // to suppress IDE type warnings
$stub->expects($this->any())
->method('fetch')
- ->willReturnCallback(function () use ($data) {
+ ->will($this->returnCallback(function () use ($data) {
$r = $data->current();
$data->next();
return $r;
- });
+ }));
$result->initialize($stub, null);
$result->rewind();
$result->rewind();
diff --git a/test/unit/ResultSet/HydratingResultSetIntegrationTest.php b/test/unit/ResultSet/HydratingResultSetIntegrationTest.php
index 5aee3b38c..fe44364cd 100644
--- a/test/unit/ResultSet/HydratingResultSetIntegrationTest.php
+++ b/test/unit/ResultSet/HydratingResultSetIntegrationTest.php
@@ -4,13 +4,14 @@
use ArrayIterator;
use Laminas\Db\ResultSet\HydratingResultSet;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(HydratingResultSet::class, 'current')]
-final class HydratingResultSetIntegrationTest extends TestCase
+class HydratingResultSetIntegrationTest extends TestCase
{
- public function testCurrentWillReturnBufferedRow(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\HydratingResultSet::current
+ */
+ public function testCurrentWillReturnBufferedRow()
{
$hydratingRs = new HydratingResultSet();
$hydratingRs->initialize(new ArrayIterator([
diff --git a/test/unit/ResultSet/HydratingResultSetTest.php b/test/unit/ResultSet/HydratingResultSetTest.php
index 9df6fe865..cd3d38fd0 100644
--- a/test/unit/ResultSet/HydratingResultSetTest.php
+++ b/test/unit/ResultSet/HydratingResultSetTest.php
@@ -7,26 +7,19 @@
use Laminas\Hydrator\ArraySerializableHydrator;
use Laminas\Hydrator\ClassMethods;
use Laminas\Hydrator\ClassMethodsHydrator;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
use stdClass;
use function class_exists;
-#[CoversMethod(HydratingResultSet::class, 'setObjectPrototype')]
-#[CoversMethod(HydratingResultSet::class, 'getObjectPrototype')]
-#[CoversMethod(HydratingResultSet::class, 'setHydrator')]
-#[CoversMethod(HydratingResultSet::class, 'getHydrator')]
-#[CoversMethod(HydratingResultSet::class, 'current')]
-#[CoversMethod(HydratingResultSet::class, 'toArray')]
-final class HydratingResultSetTest extends TestCase
+class HydratingResultSetTest extends TestCase
{
- private string $arraySerializableHydratorClass;
+ /** @var string */
+ private $arraySerializableHydratorClass;
- private string $classMethodsHydratorClass;
+ /** @var string */
+ private $classMethodsHydratorClass;
- #[Override]
protected function setUp(): void
{
$this->arraySerializableHydratorClass = class_exists(ArraySerializableHydrator::class)
@@ -38,33 +31,48 @@ protected function setUp(): void
: ClassMethods::class;
}
- public function testSetObjectPrototype(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\HydratingResultSet::setObjectPrototype
+ */
+ public function testSetObjectPrototype()
{
$prototype = new stdClass();
$hydratingRs = new HydratingResultSet();
self::assertSame($hydratingRs, $hydratingRs->setObjectPrototype($prototype));
}
- public function testGetObjectPrototype(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\HydratingResultSet::getObjectPrototype
+ */
+ public function testGetObjectPrototype()
{
$hydratingRs = new HydratingResultSet();
self::assertInstanceOf('ArrayObject', $hydratingRs->getObjectPrototype());
}
- public function testSetHydrator(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\HydratingResultSet::setHydrator
+ */
+ public function testSetHydrator()
{
$hydratingRs = new HydratingResultSet();
$hydratorClass = $this->classMethodsHydratorClass;
self::assertSame($hydratingRs, $hydratingRs->setHydrator(new $hydratorClass()));
}
- public function testGetHydrator(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\HydratingResultSet::getHydrator
+ */
+ public function testGetHydrator()
{
$hydratingRs = new HydratingResultSet();
self::assertInstanceOf($this->arraySerializableHydratorClass, $hydratingRs->getHydrator());
}
- public function testCurrentHasData(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\HydratingResultSet::current
+ */
+ public function testCurrentHasData()
{
$hydratingRs = new HydratingResultSet();
$hydratingRs->initialize([
@@ -74,7 +82,10 @@ public function testCurrentHasData(): void
self::assertInstanceOf('ArrayObject', $obj);
}
- public function testCurrentDoesnotHasData(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\HydratingResultSet::current
+ */
+ public function testCurrentDoesnotHasData()
{
$hydratingRs = new HydratingResultSet();
$hydratingRs->initialize([]);
@@ -83,9 +94,10 @@ public function testCurrentDoesnotHasData(): void
}
/**
- * @todo Implement testToArray().
+ * @covers \Laminas\Db\ResultSet\HydratingResultSet::toArray
+ * @todo Implement testToArray().
*/
- public function testToArray(): void
+ public function testToArray()
{
$hydratingRs = new HydratingResultSet();
$hydratingRs->initialize([
diff --git a/test/unit/ResultSet/ResultSetIntegrationTest.php b/test/unit/ResultSet/ResultSetIntegrationTest.php
index 078f5d9c1..46e88edb1 100644
--- a/test/unit/ResultSet/ResultSetIntegrationTest.php
+++ b/test/unit/ResultSet/ResultSetIntegrationTest.php
@@ -5,66 +5,58 @@
use ArrayIterator;
use ArrayObject;
use Laminas\Db\Adapter\Driver\ResultInterface;
-use Laminas\Db\ResultSet\AbstractResultSet;
use Laminas\Db\ResultSet\Exception\InvalidArgumentException;
use Laminas\Db\ResultSet\Exception\RuntimeException;
use Laminas\Db\ResultSet\ResultSet;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-use Random\RandomException;
use SplStack;
use stdClass;
use function is_array;
-use function random_int;
+use function rand;
use function var_export;
-#[CoversMethod(AbstractResultSet::class, 'current')]
-#[CoversMethod(AbstractResultSet::class, 'buffer')]
-final class ResultSetIntegrationTest extends TestCase
+class ResultSetIntegrationTest extends TestCase
{
- protected ResultSet $resultSet;
+ /** @var ResultSet */
+ protected $resultSet;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->resultSet = new ResultSet();
}
- public function testRowObjectPrototypeIsPopulatedByRowObjectByDefault(): void
+ public function testRowObjectPrototypeIsPopulatedByRowObjectByDefault()
{
$row = $this->resultSet->getArrayObjectPrototype();
self::assertInstanceOf('ArrayObject', $row);
}
- public function testRowObjectPrototypeIsMutable(): void
+ public function testRowObjectPrototypeIsMutable()
{
$row = new ArrayObject();
$this->resultSet->setArrayObjectPrototype($row);
self::assertSame($row, $this->resultSet->getArrayObjectPrototype());
}
- public function testRowObjectPrototypeMayBePassedToConstructor(): void
+ public function testRowObjectPrototypeMayBePassedToConstructor()
{
$row = new ArrayObject();
$resultSet = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, $row);
self::assertSame($row, $resultSet->getArrayObjectPrototype());
}
- public function testReturnTypeIsObjectByDefault(): void
+ public function testReturnTypeIsObjectByDefault()
{
self::assertEquals(ResultSet::TYPE_ARRAYOBJECT, $this->resultSet->getReturnType());
}
/** @psalm-return array */
- public static function invalidReturnTypes(): array
+ public function invalidReturnTypes(): array
{
return [
[1],
@@ -76,26 +68,29 @@ public static function invalidReturnTypes(): array
];
}
- #[DataProvider('invalidReturnTypes')]
- public function testSettingInvalidReturnTypeRaisesException(mixed $type): void
+ /**
+ * @dataProvider invalidReturnTypes
+ * @param mixed $type
+ */
+ public function testSettingInvalidReturnTypeRaisesException($type)
{
$this->expectException(InvalidArgumentException::class);
new ResultSet(ResultSet::TYPE_ARRAYOBJECT, $type);
}
- public function testDataSourceIsNullByDefault(): void
+ public function testDataSourceIsNullByDefault()
{
self::assertNull($this->resultSet->getDataSource());
}
- public function testCanProvideIteratorAsDataSource(): void
+ public function testCanProvideIteratorAsDataSource()
{
$it = new SplStack();
$this->resultSet->initialize($it);
self::assertSame($it, $this->resultSet->getDataSource());
}
- public function testCanProvideArrayAsDataSource(): void
+ public function testCanProvideArrayAsDataSource()
{
$dataSource = [['foo']];
$this->resultSet->initialize($dataSource);
@@ -109,24 +104,21 @@ public function testCanProvideArrayAsDataSource(): void
$this->assertContains($dataSource[0], $this->resultSet);
}
- /**
- * @throws \Exception
- */
- public function testCanProvideIteratorAggregateAsDataSource(): void
+ public function testCanProvideIteratorAggregateAsDataSource()
{
$iteratorAggregate = $this->getMockBuilder('IteratorAggregate')
- ->onlyMethods(['getIterator'])
+ ->setMethods(['getIterator'])
->getMock();
- $iteratorAggregate->expects($this->any())->method('getIterator')->willReturn($iteratorAggregate);
+ $iteratorAggregate->expects($this->any())->method('getIterator')->will($this->returnValue($iteratorAggregate));
$this->resultSet->initialize($iteratorAggregate);
self::assertSame($iteratorAggregate->getIterator(), $this->resultSet->getDataSource());
}
/**
- * @return void
+ * @dataProvider invalidReturnTypes
+ * @param mixed $dataSource
*/
- #[DataProvider('invalidReturnTypes')]
- public function testInvalidDataSourceRaisesException(mixed $dataSource)
+ public function testInvalidDataSourceRaisesException($dataSource)
{
if (is_array($dataSource)) {
$this->expectNotToPerformAssertions();
@@ -137,7 +129,7 @@ public function testInvalidDataSourceRaisesException(mixed $dataSource)
$this->resultSet->initialize($dataSource);
}
- public function testFieldCountIsZeroWithNoDataSourcePresent(): void
+ public function testFieldCountIsZeroWithNoDataSourcePresent()
{
self::assertEquals(0, $this->resultSet->getFieldCount());
}
@@ -154,7 +146,7 @@ public function getArrayDataSource(int $count): ArrayIterator
return new ArrayIterator($array);
}
- public function testFieldCountRepresentsNumberOfFieldsInARowOfData(): void
+ public function testFieldCountRepresentsNumberOfFieldsInARowOfData()
{
$resultSet = new ResultSet(ResultSet::TYPE_ARRAY);
$dataSource = $this->getArrayDataSource(10);
@@ -162,7 +154,7 @@ public function testFieldCountRepresentsNumberOfFieldsInARowOfData(): void
self::assertEquals(2, $resultSet->getFieldCount());
}
- public function testWhenReturnTypeIsArrayThenIterationReturnsArrays(): void
+ public function testWhenReturnTypeIsArrayThenIterationReturnsArrays()
{
$resultSet = new ResultSet(ResultSet::TYPE_ARRAY);
$dataSource = $this->getArrayDataSource(10);
@@ -172,7 +164,7 @@ public function testWhenReturnTypeIsArrayThenIterationReturnsArrays(): void
}
}
- public function testWhenReturnTypeIsObjectThenIterationReturnsRowObjects(): void
+ public function testWhenReturnTypeIsObjectThenIterationReturnsRowObjects()
{
$dataSource = $this->getArrayDataSource(10);
$this->resultSet->initialize($dataSource);
@@ -182,23 +174,17 @@ public function testWhenReturnTypeIsObjectThenIterationReturnsRowObjects(): void
}
}
- /**
- * @throws RandomException
- */
- public function testCountReturnsCountOfRows(): void
+ public function testCountReturnsCountOfRows()
{
- $count = random_int(3, 75);
+ $count = rand(3, 75);
$dataSource = $this->getArrayDataSource($count);
$this->resultSet->initialize($dataSource);
self::assertEquals($count, $this->resultSet->count());
}
- /**
- * @throws RandomException
- */
- public function testToArrayRaisesExceptionForRowsThatAreNotArraysOrArrayCastable(): void
+ public function testToArrayRaisesExceptionForRowsThatAreNotArraysOrArrayCastable()
{
- $count = random_int(3, 75);
+ $count = rand(3, 75);
$dataSource = $this->getArrayDataSource($count);
foreach ($dataSource as $index => $row) {
$dataSource[$index] = (object) $row;
@@ -208,22 +194,23 @@ public function testToArrayRaisesExceptionForRowsThatAreNotArraysOrArrayCastable
$this->resultSet->toArray();
}
- /**
- * @throws RandomException
- */
- public function testToArrayCreatesArrayOfArraysRepresentingRows(): void
+ public function testToArrayCreatesArrayOfArraysRepresentingRows()
{
- $count = random_int(3, 75);
+ $count = rand(3, 75);
$dataSource = $this->getArrayDataSource($count);
$this->resultSet->initialize($dataSource);
$test = $this->resultSet->toArray();
- self::assertEquals($dataSource->getArrayCopy(), $test, var_export($test, true));
+ self::assertEquals($dataSource->getArrayCopy(), $test, var_export($test, 1));
}
- public function testCurrentWithBufferingCallsDataSourceCurrentOnce(): void
+ /**
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::current
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::buffer
+ */
+ public function testCurrentWithBufferingCallsDataSourceCurrentOnce()
{
$mockResult = $this->getMockBuilder(ResultInterface::class)->getMock();
- $mockResult->expects($this->once())->method('current')->willReturn(['foo' => 'bar']);
+ $mockResult->expects($this->once())->method('current')->will($this->returnValue(['foo' => 'bar']));
$this->resultSet->initialize($mockResult);
$this->resultSet->buffer();
@@ -234,9 +221,10 @@ public function testCurrentWithBufferingCallsDataSourceCurrentOnce(): void
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::current
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::buffer
*/
- public function testBufferCalledAfterIterationThrowsException(): void
+ public function testBufferCalledAfterIterationThrowsException()
{
$this->resultSet->initialize($this->createMock(ResultInterface::class));
$this->resultSet->current();
@@ -247,12 +235,12 @@ public function testBufferCalledAfterIterationThrowsException(): void
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\ResultSet\AbstractResultSet::current
*/
- public function testCurrentReturnsNullForNonExistingValues(): void
+ public function testCurrentReturnsNullForNonExistingValues()
{
$mockResult = $this->createMock(ResultInterface::class);
- $mockResult->expects($this->once())->method('current')->willReturn("Not an Array");
+ $mockResult->expects($this->once())->method('current')->will($this->returnValue("Not an Array"));
$this->resultSet->initialize($mockResult);
$this->resultSet->buffer();
diff --git a/test/unit/RowGateway/AbstractRowGatewayTest.php b/test/unit/RowGateway/AbstractRowGatewayTest.php
index 354b6f91a..24c8fbd75 100644
--- a/test/unit/RowGateway/AbstractRowGatewayTest.php
+++ b/test/unit/RowGateway/AbstractRowGatewayTest.php
@@ -12,65 +12,41 @@
use Laminas\Db\RowGateway\RowGateway;
use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Sql;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
use ReflectionObject;
-#[CoversMethod(RowGateway::class, 'offsetSet')]
-#[CoversMethod(RowGateway::class, '__set')]
-#[CoversMethod(RowGateway::class, '__isset')]
-#[CoversMethod(RowGateway::class, 'offsetExists')]
-#[CoversMethod(RowGateway::class, '__unset')]
-#[CoversMethod(RowGateway::class, 'offsetUnset')]
-#[CoversMethod(RowGateway::class, 'offsetGet')]
-#[CoversMethod(RowGateway::class, '__get')]
-#[CoversMethod(RowGateway::class, 'save')]
-#[CoversMethod(RowGateway::class, 'delete')]
-#[CoversMethod(RowGateway::class, 'populate')]
-#[CoversMethod(RowGateway::class, 'rowExistsInDatabase')]
-#[CoversMethod(RowGateway::class, 'processPrimaryKeyData')]
-#[CoversMethod(RowGateway::class, 'count')]
-#[CoversMethod(RowGateway::class, 'toArray')]
-final class AbstractRowGatewayTest extends TestCase
+class AbstractRowGatewayTest extends TestCase
{
/** @var Adapter&MockObject */
- protected Adapter|MockObject $mockAdapter;
+ protected $mockAdapter;
/** @var RowGateway */
- protected RowGateway|AbstractRowGateway|MockObject $rowGateway;
+ protected $rowGateway;
/** @var ResultInterface&MockObject */
- protected ResultInterface|MockObject $mockResult;
+ protected $mockResult;
- /**
- * @throws ReflectionException
- * @throws Exception
- */
- #[Override]
protected function setUp(): void
{
// mock the adapter, driver, and parts
$mockResult = $this->getMockBuilder(ResultInterface::class)->getMock();
- $mockResult->expects($this->any())->method('getAffectedRows')->willReturn(1);
+ $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(1));
$this->mockResult = $mockResult;
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
- $mockStatement->expects($this->any())->method('execute')->willReturn($mockResult);
+ $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
$mockConnection = $this->getMockBuilder(ConnectionInterface::class)->getMock();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement);
- $mockDriver->expects($this->any())->method('getConnection')->willReturn($mockConnection);
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
+ $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
// setup mock adapter
$this->mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
- $this->rowGateway = $this->getMockBuilder(AbstractRowGateway::class)->onlyMethods([])->getMock();
+ $this->rowGateway = $this->getMockForAbstractClass(AbstractRowGateway::class);
$rgPropertyValues = [
'primaryKeyColumn' => 'id',
@@ -80,7 +56,10 @@ protected function setUp(): void
$this->setRowGatewayState($rgPropertyValues);
}
- public function testOffsetSet(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::offsetSet
+ */
+ public function testOffsetSet()
{
// If we set with an index, both getters should retrieve the same value:
$this->rowGateway['testColumn'] = 'test';
@@ -88,8 +67,11 @@ public function testOffsetSet(): void
self::assertEquals('test', $this->rowGateway['testColumn']);
}
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::__set
+ */
// @codingStandardsIgnoreStart
- public function test__set(): void
+ public function test__set()
{
// @codingStandardsIgnoreEnd
// If we set with a property, both getters should retrieve the same value:
@@ -98,8 +80,11 @@ public function test__set(): void
self::assertEquals('test', $this->rowGateway['testColumn']);
}
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::__isset
+ */
// @codingStandardsIgnoreStart
- public function test__isset(): void
+ public function test__isset()
{
// @codingStandardsIgnoreEnd
// Test isset before and after assigning to a property:
@@ -108,7 +93,10 @@ public function test__isset(): void
self::assertTrue(isset($this->rowGateway->foo));
}
- public function testOffsetExists(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::offsetExists
+ */
+ public function testOffsetExists()
{
// Test isset before and after assigning to an index:
self::assertFalse(isset($this->rowGateway['foo']));
@@ -116,8 +104,11 @@ public function testOffsetExists(): void
self::assertTrue(isset($this->rowGateway['foo']));
}
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::__unset
+ */
// @codingStandardsIgnoreStart
- public function test__unset(): void
+ public function test__unset()
{
// @codingStandardsIgnoreEnd
$this->rowGateway->foo = 'bar';
@@ -127,7 +118,10 @@ public function test__unset(): void
self::assertEmpty($this->rowGateway['foo']);
}
- public function testOffsetUnset(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::offsetUnset
+ */
+ public function testOffsetUnset()
{
$this->rowGateway['foo'] = 'bar';
self::assertEquals('bar', $this->rowGateway['foo']);
@@ -136,7 +130,10 @@ public function testOffsetUnset(): void
self::assertEmpty($this->rowGateway['foo']);
}
- public function testOffsetGet(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::offsetGet
+ */
+ public function testOffsetGet()
{
// If we set with an index, both getters should retrieve the same value:
$this->rowGateway['testColumn'] = 'test';
@@ -144,8 +141,11 @@ public function testOffsetGet(): void
self::assertEquals('test', $this->rowGateway['testColumn']);
}
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::__get
+ */
// @codingStandardsIgnoreStart
- public function test__get(): void
+ public function test__get()
{
// @codingStandardsIgnoreEnd
// If we set with a property, both getters should retrieve the same value:
@@ -154,12 +154,15 @@ public function test__get(): void
self::assertEquals('test', $this->rowGateway['testColumn']);
}
- public function testSaveInsert(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::save
+ */
+ public function testSaveInsert()
{
// test insert
$this->mockResult->expects($this->any())->method('current')
- ->willReturn(['id' => 5, 'name' => 'foo']);
- $this->mockResult->expects($this->any())->method('getGeneratedValue')->willReturn(5);
+ ->will($this->returnValue(['id' => 5, 'name' => 'foo']));
+ $this->mockResult->expects($this->any())->method('getGeneratedValue')->will($this->returnValue(5));
$this->rowGateway->populate(['name' => 'foo']);
$this->rowGateway->save();
self::assertEquals(5, $this->rowGateway->id);
@@ -167,14 +170,13 @@ public function testSaveInsert(): void
}
/**
- * @throws ReflectionException
- * @throws Exception
+ * @covers \Laminas\Db\RowGateway\RowGateway::save
*/
- public function testSaveInsertMultiKey(): void
+ public function testSaveInsertMultiKey()
{
- $this->rowGateway = $this->getMockBuilder(AbstractRowGateway::class)->onlyMethods([])->getMock();
+ $this->rowGateway = $this->getMockForAbstractClass(AbstractRowGateway::class);
- $mockSql = $this->getMockBuilder(Sql::class)->setConstructorArgs([$this->mockAdapter])->onlyMethods([])->getMock();
+ $mockSql = $this->getMockForAbstractClass(Sql::class, [$this->mockAdapter]);
$rgPropertyValues = [
'primaryKeyColumn' => ['one', 'two'],
@@ -185,13 +187,12 @@ public function testSaveInsertMultiKey(): void
// test insert
$this->mockResult->expects($this->any())->method('current')
- ->willReturn(['one' => 'foo', 'two' => 'bar']);
+ ->will($this->returnValue(['one' => 'foo', 'two' => 'bar']));
// @todo Need to assert that $where was filled in
$refRowGateway = new ReflectionObject($this->rowGateway);
$refRowGatewayProp = $refRowGateway->getProperty('primaryKeyData');
- /** @psalm-suppress UnusedMethodCall */
$refRowGatewayProp->setAccessible(true);
$this->rowGateway->populate(['one' => 'foo', 'two' => 'bar']);
@@ -204,41 +205,47 @@ public function testSaveInsertMultiKey(): void
self::assertEquals(['one' => 'foo', 'two' => 'bar'], $refRowGatewayProp->getValue($this->rowGateway));
}
- public function testSaveUpdate(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::save
+ */
+ public function testSaveUpdate()
{
// test update
$this->mockResult->expects($this->any())->method('current')
- ->willReturn(['id' => 6, 'name' => 'foo']);
+ ->will($this->returnValue(['id' => 6, 'name' => 'foo']));
$this->rowGateway->populate(['id' => 6, 'name' => 'foo'], true);
$this->rowGateway->save();
self::assertEquals(6, $this->rowGateway['id']);
}
- public function testSaveUpdateChangingPrimaryKey(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::save
+ */
+ public function testSaveUpdateChangingPrimaryKey()
{
// this mock is the select to be used to re-fresh the rowobject's data
$selectMock = $this->getMockBuilder(Select::class)
- ->onlyMethods(['where'])
+ ->setMethods(['where'])
->getMock();
$selectMock->expects($this->once())
->method('where')
->with($this->equalTo(['id' => 7]))
- ->willReturn($selectMock);
+ ->will($this->returnValue($selectMock));
$sqlMock = $this->getMockBuilder(Sql::class)
- ->onlyMethods(['select'])
+ ->setMethods(['select'])
->setConstructorArgs([$this->mockAdapter])
->getMock();
$sqlMock->expects($this->any())
->method('select')
- ->willReturn($selectMock);
+ ->will($this->returnValue($selectMock));
$this->setRowGatewayState(['sql' => $sqlMock]);
// original mock returning updated data
$this->mockResult->expects($this->any())
->method('current')
- ->willReturn(['id' => 7, 'name' => 'fooUpdated']);
+ ->will($this->returnValue(['id' => 7, 'name' => 'fooUpdated']));
// populate forces an update in save(), seeds with original data (from db)
$this->rowGateway->populate(['id' => 6, 'name' => 'foo'], true);
@@ -247,7 +254,10 @@ public function testSaveUpdateChangingPrimaryKey(): void
self::assertEquals(['id' => 7, 'name' => 'fooUpdated'], $this->rowGateway->toArray());
}
- public function testDelete(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::delete
+ */
+ public function testDelete()
{
$this->rowGateway->foo = 'bar';
$affectedRows = $this->rowGateway->delete();
@@ -255,7 +265,11 @@ public function testDelete(): void
self::assertEquals(1, $affectedRows);
}
- public function testPopulate(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::populate
+ * @covers \Laminas\Db\RowGateway\RowGateway::rowExistsInDatabase
+ */
+ public function testPopulate()
{
$this->rowGateway->populate(['id' => 5, 'name' => 'foo']);
self::assertEquals(5, $this->rowGateway['id']);
@@ -266,7 +280,10 @@ public function testPopulate(): void
self::assertTrue($this->rowGateway->rowExistsInDatabase());
}
- public function testProcessPrimaryKeyData(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::processPrimaryKeyData
+ */
+ public function testProcessPrimaryKeyData()
{
$this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true);
@@ -275,27 +292,29 @@ public function testProcessPrimaryKeyData(): void
$this->rowGateway->populate(['boo' => 5, 'name' => 'foo'], true);
}
- public function testCount(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::count
+ */
+ public function testCount()
{
$this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true);
self::assertEquals(2, $this->rowGateway->count());
}
- public function testToArray(): void
+ /**
+ * @covers \Laminas\Db\RowGateway\RowGateway::toArray
+ */
+ public function testToArray()
{
$this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true);
self::assertEquals(['id' => 5, 'name' => 'foo'], $this->rowGateway->toArray());
}
- /**
- * @throws ReflectionException
- */
- protected function setRowGatewayState(array $properties): void
+ protected function setRowGatewayState(array $properties)
{
$refRowGateway = new ReflectionObject($this->rowGateway);
foreach ($properties as $rgPropertyName => $rgPropertyValue) {
$refRowGatewayProp = $refRowGateway->getProperty($rgPropertyName);
- /** @psalm-suppress UnusedMethodCall */
$refRowGatewayProp->setAccessible(true);
$refRowGatewayProp->setValue($this->rowGateway, $rgPropertyValue);
}
diff --git a/test/unit/RowGateway/RowGatewayTest.php b/test/unit/RowGateway/RowGatewayTest.php
index aa93438af..795367a0e 100644
--- a/test/unit/RowGateway/RowGatewayTest.php
+++ b/test/unit/RowGateway/RowGatewayTest.php
@@ -9,44 +9,43 @@
use Laminas\Db\Adapter\Driver\StatementInterface;
use Laminas\Db\RowGateway\Exception\RuntimeException;
use Laminas\Db\RowGateway\RowGateway;
-use Override;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-final class RowGatewayTest extends TestCase
+class RowGatewayTest extends TestCase
{
/** @var Adapter&MockObject */
- protected Adapter|MockObject $mockAdapter;
+ protected $mockAdapter;
- protected RowGateway $rowGateway;
+ /** @var RowGateway */
+ protected $rowGateway;
/** @var ResultInterface&MockObject */
- protected ResultInterface|MockObject $mockResult;
- #[Override]
+ protected $mockResult;
protected function setUp(): void
{
// mock the adapter, driver, and parts
$mockResult = $this->getMockBuilder(ResultInterface::class)->getMock();
- $mockResult->expects($this->any())->method('getAffectedRows')->willReturn(1);
+ $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(1));
$this->mockResult = $mockResult;
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
- $mockStatement->expects($this->any())->method('execute')->willReturn($mockResult);
+ $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
$mockConnection = $this->getMockBuilder(ConnectionInterface::class)->getMock();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement);
- $mockDriver->expects($this->any())->method('getConnection')->willReturn($mockConnection);
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
+ $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
// setup mock adapter
$this->mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
}
- public function testEmptyPrimaryKey(): void
+ public function testEmptyPrimaryKey()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('This row object does not have a primary key column set.');
diff --git a/test/unit/Sql/AbstractSqlTest.php b/test/unit/Sql/AbstractSqlTest.php
index 6fa5447e2..bfb253e70 100644
--- a/test/unit/Sql/AbstractSqlTest.php
+++ b/test/unit/Sql/AbstractSqlTest.php
@@ -11,13 +11,8 @@
use Laminas\Db\Sql\Predicate;
use Laminas\Db\Sql\Select;
use LaminasTest\Db\TestAsset\TrustingSql92Platform;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
use ReflectionMethod;
use function current;
@@ -26,36 +21,35 @@
use function preg_match;
use function uniqid;
-#[CoversMethod(AbstractSql::class, 'processExpression')]
-final class AbstractSqlTest extends TestCase
+class AbstractSqlTest extends TestCase
{
- protected AbstractSql&MockObject $abstractSql;
+ /** @var AbstractSql&MockObject */
+ protected $abstractSql;
- protected DriverInterface&MockObject $mockDriver;
+ /** @var DriverInterface&MockObject */
+ protected $mockDriver;
- /**
- * @throws Exception
- */
- #[Override]
protected function setUp(): void
{
- $this->abstractSql = $this->getMockBuilder(AbstractSql::class)->onlyMethods([])->getMock();
+ $this->abstractSql = $this->getMockForAbstractClass(AbstractSql::class);
$this->mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
$this->mockDriver
->expects($this->any())
->method('getPrepareType')
- ->willReturn(DriverInterface::PARAMETERIZATION_NAMED);
+ ->will($this->returnValue(DriverInterface::PARAMETERIZATION_NAMED));
$this->mockDriver
->expects($this->any())
->method('formatParameterName')
- ->willReturnCallback(fn($x) => ':' . $x);
+ ->will($this->returnCallback(function ($x) {
+ return ':' . $x;
+ }));
}
/**
- * @throws ReflectionException
+ * @covers \Laminas\Db\Sql\AbstractSql::processExpression
*/
- public function testProcessExpressionWithoutParameterContainer(): void
+ public function testProcessExpressionWithoutParameterContainer()
{
$expression = new Expression('? > ? AND y < ?', [['x' => ExpressionInterface::TYPE_IDENTIFIER], 5, 10]);
$sqlAndParams = $this->invokeProcessExpressionMethod($expression);
@@ -64,9 +58,9 @@ public function testProcessExpressionWithoutParameterContainer(): void
}
/**
- * @throws ReflectionException
+ * @covers \Laminas\Db\Sql\AbstractSql::processExpression
*/
- public function testProcessExpressionWithParameterContainerAndParameterizationTypeNamed(): void
+ public function testProcessExpressionWithParameterContainerAndParameterizationTypeNamed()
{
$parameterContainer = new ParameterContainer();
$expression = new Expression('? > ? AND y < ?', [['x' => ExpressionInterface::TYPE_IDENTIFIER], 5, 10]);
@@ -88,7 +82,7 @@ public function testProcessExpressionWithParameterContainerAndParameterizationTy
// ensure next invocation increases number by 1
$parameterContainer = new ParameterContainer();
- $this->invokeProcessExpressionMethod($expression, $parameterContainer);
+ $sqlAndParamsNext = $this->invokeProcessExpressionMethod($expression, $parameterContainer);
$parameters = $parameterContainer->getNamedArray();
@@ -99,9 +93,9 @@ public function testProcessExpressionWithParameterContainerAndParameterizationTy
}
/**
- * @throws ReflectionException
+ * @covers \Laminas\Db\Sql\AbstractSql::processExpression
*/
- public function testProcessExpressionWorksWithExpressionContainingStringParts(): void
+ public function testProcessExpressionWorksWithExpressionContainingStringParts()
{
$expression = new Predicate\Expression('x = ?', 5);
@@ -112,9 +106,9 @@ public function testProcessExpressionWorksWithExpressionContainingStringParts():
}
/**
- * @throws ReflectionException
+ * @covers \Laminas\Db\Sql\AbstractSql::processExpression
*/
- public function testProcessExpressionWorksWithExpressionContainingSelectObject(): void
+ public function testProcessExpressionWorksWithExpressionContainingSelectObject()
{
$select = new Select();
$select->from('x')->where->like('bar', 'Foo%');
@@ -126,10 +120,7 @@ public function testProcessExpressionWorksWithExpressionContainingSelectObject()
self::assertEquals('("x" IN (SELECT "x".* FROM "x" WHERE "bar" LIKE \'Foo%\'))', $sqlAndParams);
}
- /**
- * @throws ReflectionException
- */
- public function testProcessExpressionWorksWithExpressionContainingExpressionObject(): void
+ public function testProcessExpressionWorksWithExpressionContainingExpressionObject()
{
$expression = new Predicate\Operator(
'release_date',
@@ -142,10 +133,9 @@ public function testProcessExpressionWorksWithExpressionContainingExpressionObje
}
/**
- * @throws ReflectionException
+ * @group 7407
*/
- #[Group('7407')]
- public function testProcessExpressionWorksWithExpressionObjectWithPercentageSigns(): void
+ public function testProcessExpressionWorksWithExpressionObjectWithPercentageSigns()
{
$expressionString = 'FROM_UNIXTIME(date, "%Y-%m")';
$expression = new Expression($expressionString);
@@ -154,10 +144,7 @@ public function testProcessExpressionWorksWithExpressionObjectWithPercentageSign
self::assertSame($expressionString, $sqlString);
}
- /**
- * @throws ReflectionException
- */
- public function testProcessExpressionWorksWithNamedParameterPrefix(): void
+ public function testProcessExpressionWorksWithNamedParameterPrefix()
{
$parameterContainer = new ParameterContainer();
$namedParameterPrefix = uniqid();
@@ -167,10 +154,7 @@ public function testProcessExpressionWorksWithNamedParameterPrefix(): void
self::assertSame($namedParameterPrefix . '1', key($parameterContainer->getNamedArray()));
}
- /**
- * @throws ReflectionException
- */
- public function testProcessExpressionWorksWithNamedParameterPrefixContainingWhitespace(): void
+ public function testProcessExpressionWorksWithNamedParameterPrefixContainingWhitespace()
{
$parameterContainer = new ParameterContainer();
$namedParameterPrefix = "string\ncontaining white space";
@@ -181,17 +165,16 @@ public function testProcessExpressionWorksWithNamedParameterPrefixContainingWhit
}
/**
- * @param null $parameterContainer
- * @param null $namedParameterPrefix
- * @throws ReflectionException
+ * @param ParameterContainer $parameterContainer
+ * @param string $namedParameterPrefix
+ * @return StatementContainer|string
*/
protected function invokeProcessExpressionMethod(
ExpressionInterface $expression,
$parameterContainer = null,
$namedParameterPrefix = null
- ): string|StatementContainer {
+ ) {
$method = new ReflectionMethod($this->abstractSql, 'processExpression');
- /** @psalm-suppress UnusedMethodCall */
$method->setAccessible(true);
return $method->invoke(
$this->abstractSql,
diff --git a/test/unit/Sql/CombineTest.php b/test/unit/Sql/CombineTest.php
index ccc5f1563..b47dff01e 100644
--- a/test/unit/Sql/CombineTest.php
+++ b/test/unit/Sql/CombineTest.php
@@ -12,32 +12,31 @@
use Laminas\Db\Sql\Exception\InvalidArgumentException;
use Laminas\Db\Sql\Predicate\Expression;
use Laminas\Db\Sql\Select;
-use Override;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-final class CombineTest extends TestCase
+class CombineTest extends TestCase
{
- protected Combine $combine;
+ /** @var Combine */
+ protected $combine;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->combine = new Combine();
}
- public function testRejectsInvalidStatement(): void
+ public function testRejectsInvalidStatement()
{
$this->expectException(InvalidArgumentException::class);
$this->combine->combine('foo');
}
- public function testGetSqlString(): void
+ public function testGetSqlString()
{
$this->combine
->union(new Select('t1'))
@@ -53,7 +52,7 @@ public function testGetSqlString(): void
);
}
- public function testGetSqlStringWithModifier(): void
+ public function testGetSqlStringWithModifier()
{
$this->combine
->union(new Select('t1'))
@@ -65,7 +64,7 @@ public function testGetSqlStringWithModifier(): void
);
}
- public function testGetSqlStringFromArray(): void
+ public function testGetSqlStringFromArray()
{
$this->combine->combine([
[new Select('t1')],
@@ -91,12 +90,12 @@ public function testGetSqlStringFromArray(): void
);
}
- public function testGetSqlStringEmpty(): void
+ public function testGetSqlStringEmpty()
{
self::assertNull($this->combine->getSqlString());
}
- public function testPrepareStatementWithModifier(): void
+ public function testPrepareStatementWithModifier()
{
$select1 = new Select('t1');
$select1->where(['x1' => 10]);
@@ -118,7 +117,7 @@ public function testPrepareStatementWithModifier(): void
);
}
- public function testAlignColumns(): void
+ public function testAlignColumns()
{
$select1 = new Select('t1');
$select1->columns([
@@ -154,7 +153,7 @@ public function testAlignColumns(): void
);
}
- public function testGetRawState(): void
+ public function testGetRawState()
{
$select = new Select('t1');
$this->combine->combine($select);
@@ -175,13 +174,16 @@ public function testGetRawState(): void
);
}
- protected function getMockAdapter(): Adapter|MockObject
+ /**
+ * @return MockObject|Adapter
+ */
+ protected function getMockAdapter()
{
$parameterContainer = new ParameterContainer();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$mockStatement->expects($this->any())->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$setGetSqlFunction = function ($sql = null) use ($mockStatement) {
static $sqlValue;
@@ -191,15 +193,15 @@ protected function getMockAdapter(): Adapter|MockObject
}
return $sqlValue;
};
- $mockStatement->expects($this->any())->method('setSql')->willReturnCallback($setGetSqlFunction);
- $mockStatement->expects($this->any())->method('getSql')->willReturnCallback($setGetSqlFunction);
+ $mockStatement->expects($this->any())->method('setSql')->will($this->returnCallback($setGetSqlFunction));
+ $mockStatement->expects($this->any())->method('getSql')->will($this->returnCallback($setGetSqlFunction));
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
- $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement);
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
return $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
}
diff --git a/test/unit/Sql/Ddl/AlterTableTest.php b/test/unit/Sql/Ddl/AlterTableTest.php
index 2e7386902..73fa6c069 100644
--- a/test/unit/Sql/Ddl/AlterTableTest.php
+++ b/test/unit/Sql/Ddl/AlterTableTest.php
@@ -8,22 +8,16 @@
use Laminas\Db\Sql\Ddl\Constraint;
use Laminas\Db\Sql\Ddl\Constraint\ConstraintInterface;
use Laminas\Db\Sql\TableIdentifier;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
use function str_replace;
-#[CoversMethod(AlterTable::class, 'setTable')]
-#[CoversMethod(AlterTable::class, 'addColumn')]
-#[CoversMethod(AlterTable::class, 'changeColumn')]
-#[CoversMethod(AlterTable::class, 'dropColumn')]
-#[CoversMethod(AlterTable::class, 'dropConstraint')]
-#[CoversMethod(AlterTable::class, 'addConstraint')]
-#[CoversMethod(AlterTable::class, 'dropIndex')]
-#[CoversMethod(AlterTable::class, 'getSqlString')]
-final class AlterTableTest extends TestCase
+class AlterTableTest extends TestCase
{
- public function testSetTable(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\AlterTable::setTable
+ */
+ public function testSetTable()
{
$at = new AlterTable();
self::assertEquals('', $at->getRawState('table'));
@@ -31,7 +25,10 @@ public function testSetTable(): void
self::assertEquals('test', $at->getRawState('table'));
}
- public function testAddColumn(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\AlterTable::addColumn
+ */
+ public function testAddColumn()
{
$at = new AlterTable();
/** @var ColumnInterface $colMock */
@@ -40,7 +37,10 @@ public function testAddColumn(): void
self::assertEquals([$colMock], $at->getRawState($at::ADD_COLUMNS));
}
- public function testChangeColumn(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\AlterTable::changeColumn
+ */
+ public function testChangeColumn()
{
$at = new AlterTable();
/** @var ColumnInterface $colMock */
@@ -49,21 +49,30 @@ public function testChangeColumn(): void
self::assertEquals(['newname' => $colMock], $at->getRawState($at::CHANGE_COLUMNS));
}
- public function testDropColumn(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\AlterTable::dropColumn
+ */
+ public function testDropColumn()
{
$at = new AlterTable();
self::assertSame($at, $at->dropColumn('foo'));
self::assertEquals(['foo'], $at->getRawState($at::DROP_COLUMNS));
}
- public function testDropConstraint(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\AlterTable::dropConstraint
+ */
+ public function testDropConstraint()
{
$at = new AlterTable();
self::assertSame($at, $at->dropConstraint('foo'));
self::assertEquals(['foo'], $at->getRawState($at::DROP_CONSTRAINTS));
}
- public function testAddConstraint(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\AlterTable::addConstraint
+ */
+ public function testAddConstraint()
{
$at = new AlterTable();
/** @var ConstraintInterface $conMock */
@@ -72,7 +81,10 @@ public function testAddConstraint(): void
self::assertEquals([$conMock], $at->getRawState($at::ADD_CONSTRAINTS));
}
- public function testDropIndex(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\AlterTable::dropIndex
+ */
+ public function testDropIndex()
{
$at = new AlterTable();
self::assertSame($at, $at->dropIndex('foo'));
@@ -80,9 +92,10 @@ public function testDropIndex(): void
}
/**
- * @todo Implement testGetSqlString().
+ * @covers \Laminas\Db\Sql\Ddl\AlterTable::getSqlString
+ * @todo Implement testGetSqlString().
*/
- public function testGetSqlString(): void
+ public function testGetSqlString()
{
$at = new AlterTable('foo');
$at->addColumn(new Column\Varchar('another', 255));
diff --git a/test/unit/Sql/Ddl/Column/AbstractLengthColumnTest.php b/test/unit/Sql/Ddl/Column/AbstractLengthColumnTest.php
index ea1ba4f34..a92192f37 100644
--- a/test/unit/Sql/Ddl/Column/AbstractLengthColumnTest.php
+++ b/test/unit/Sql/Ddl/Column/AbstractLengthColumnTest.php
@@ -3,41 +3,36 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\AbstractLengthColumn;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(AbstractLengthColumn::class, 'setLength')]
-#[CoversMethod(AbstractLengthColumn::class, 'getLength')]
-#[CoversMethod(AbstractLengthColumn::class, 'getExpressionData')]
-final class AbstractLengthColumnTest extends TestCase
+class AbstractLengthColumnTest extends TestCase
{
/**
- * @throws Exception
+ * @covers \Laminas\Db\Sql\Ddl\Column\AbstractLengthColumn::setLength
*/
- public function testSetLength(): void
+ public function testSetLength()
{
- $column = $this->getMockBuilder(AbstractLengthColumn::class)->setConstructorArgs(['foo', 55])->onlyMethods([])->getMock();
+ $column = $this->getMockForAbstractClass(AbstractLengthColumn::class, ['foo', 55]);
self::assertEquals(55, $column->getLength());
self::assertSame($column, $column->setLength(20));
self::assertEquals(20, $column->getLength());
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Sql\Ddl\Column\AbstractLengthColumn::getLength
*/
- public function testGetLength(): void
+ public function testGetLength()
{
- $column = $this->getMockBuilder(AbstractLengthColumn::class)->setConstructorArgs(['foo', 55])->onlyMethods([])->getMock();
+ $column = $this->getMockForAbstractClass(AbstractLengthColumn::class, ['foo', 55]);
self::assertEquals(55, $column->getLength());
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Sql\Ddl\Column\AbstractLengthColumn::getExpressionData
*/
- public function testGetExpressionData(): void
+ public function testGetExpressionData()
{
- $column = $this->getMockBuilder(AbstractLengthColumn::class)->setConstructorArgs(['foo', 4])->onlyMethods([])->getMock();
+ $column = $this->getMockForAbstractClass(AbstractLengthColumn::class, ['foo', 4]);
self::assertEquals(
[['%s %s NOT NULL', ['foo', 'INTEGER(4)'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]],
diff --git a/test/unit/Sql/Ddl/Column/AbstractPrecisionColumnTest.php b/test/unit/Sql/Ddl/Column/AbstractPrecisionColumnTest.php
index 66b9a874d..2818ac595 100644
--- a/test/unit/Sql/Ddl/Column/AbstractPrecisionColumnTest.php
+++ b/test/unit/Sql/Ddl/Column/AbstractPrecisionColumnTest.php
@@ -3,63 +3,56 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\AbstractPrecisionColumn;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(AbstractPrecisionColumn::class, 'setDigits')]
-#[CoversMethod(AbstractPrecisionColumn::class, 'getDigits')]
-#[CoversMethod(AbstractPrecisionColumn::class, 'setDecimal')]
-#[CoversMethod(AbstractPrecisionColumn::class, 'getDecimal')]
-#[CoversMethod(AbstractPrecisionColumn::class, 'getExpressionData')]
-final class AbstractPrecisionColumnTest extends TestCase
+class AbstractPrecisionColumnTest extends TestCase
{
/**
- * @throws Exception
+ * @covers \Laminas\Db\Sql\Ddl\Column\AbstractPrecisionColumn::setDigits
*/
- public function testSetDigits(): void
+ public function testSetDigits()
{
- $column = $this->getMockBuilder(AbstractPrecisionColumn::class)->setConstructorArgs(['foo', 10])->onlyMethods([])->getMock();
+ $column = $this->getMockForAbstractClass(AbstractPrecisionColumn::class, ['foo', 10]);
self::assertEquals(10, $column->getDigits());
self::assertSame($column, $column->setDigits(12));
self::assertEquals(12, $column->getDigits());
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Sql\Ddl\Column\AbstractPrecisionColumn::getDigits
*/
- public function testGetDigits(): void
+ public function testGetDigits()
{
- $column = $this->getMockBuilder(AbstractPrecisionColumn::class)->setConstructorArgs(['foo', 10])->onlyMethods([])->getMock();
+ $column = $this->getMockForAbstractClass(AbstractPrecisionColumn::class, ['foo', 10]);
self::assertEquals(10, $column->getDigits());
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Sql\Ddl\Column\AbstractPrecisionColumn::setDecimal
*/
- public function testSetDecimal(): void
+ public function testSetDecimal()
{
- $column = $this->getMockBuilder(AbstractPrecisionColumn::class)->setConstructorArgs(['foo', 10, 5])->onlyMethods([])->getMock();
+ $column = $this->getMockForAbstractClass(AbstractPrecisionColumn::class, ['foo', 10, 5]);
self::assertEquals(5, $column->getDecimal());
self::assertSame($column, $column->setDecimal(2));
self::assertEquals(2, $column->getDecimal());
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Sql\Ddl\Column\AbstractPrecisionColumn::getDecimal
*/
- public function testGetDecimal(): void
+ public function testGetDecimal()
{
- $column = $this->getMockBuilder(AbstractPrecisionColumn::class)->setConstructorArgs(['foo', 10, 5])->onlyMethods([])->getMock();
+ $column = $this->getMockForAbstractClass(AbstractPrecisionColumn::class, ['foo', 10, 5]);
self::assertEquals(5, $column->getDecimal());
}
/**
- * @throws Exception
+ * @covers \Laminas\Db\Sql\Ddl\Column\AbstractPrecisionColumn::getExpressionData
*/
- public function testGetExpressionData(): void
+ public function testGetExpressionData()
{
- $column = $this->getMockBuilder(AbstractPrecisionColumn::class)->setConstructorArgs(['foo', 10, 5])->onlyMethods([])->getMock();
+ $column = $this->getMockForAbstractClass(AbstractPrecisionColumn::class, ['foo', 10, 5]);
self::assertEquals(
[['%s %s NOT NULL', ['foo', 'INTEGER(10,5)'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]],
diff --git a/test/unit/Sql/Ddl/Column/BigIntegerTest.php b/test/unit/Sql/Ddl/Column/BigIntegerTest.php
index d143d92f8..5461fb0ab 100644
--- a/test/unit/Sql/Ddl/Column/BigIntegerTest.php
+++ b/test/unit/Sql/Ddl/Column/BigIntegerTest.php
@@ -3,21 +3,23 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\BigInteger;
-use Laminas\Db\Sql\Ddl\Column\Column;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(BigInteger::class, '__construct')]
-#[CoversMethod(Column::class, 'getExpressionData')]
-final class BigIntegerTest extends TestCase
+class BigIntegerTest extends TestCase
{
- public function testObjectConstruction(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\BigInteger::__construct
+ */
+ public function testObjectConstruction()
{
$integer = new BigInteger('foo');
self::assertEquals('foo', $integer->getName());
}
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new BigInteger('foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/BinaryTest.php b/test/unit/Sql/Ddl/Column/BinaryTest.php
index 58242b1ae..70437636b 100644
--- a/test/unit/Sql/Ddl/Column/BinaryTest.php
+++ b/test/unit/Sql/Ddl/Column/BinaryTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Binary;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Binary::class, 'getExpressionData')]
-final class BinaryTest extends TestCase
+class BinaryTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Binary::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Binary('foo', 10000000);
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/BlobTest.php b/test/unit/Sql/Ddl/Column/BlobTest.php
index bb73f5b7b..b099065ef 100644
--- a/test/unit/Sql/Ddl/Column/BlobTest.php
+++ b/test/unit/Sql/Ddl/Column/BlobTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Blob;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Blob::class, 'getExpressionData')]
-final class BlobTest extends TestCase
+class BlobTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Blob::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Blob('foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/BooleanTest.php b/test/unit/Sql/Ddl/Column/BooleanTest.php
index 20760da33..0e001ad2b 100644
--- a/test/unit/Sql/Ddl/Column/BooleanTest.php
+++ b/test/unit/Sql/Ddl/Column/BooleanTest.php
@@ -3,16 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Boolean;
-use PHPUnit\Framework\Attributes\CoversClass;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Boolean::class, 'getExpressionData')]
-#[CoversClass(Boolean::class)]
-final class BooleanTest extends TestCase
+class BooleanTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Boolean::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Boolean('foo');
self::assertEquals(
@@ -21,8 +19,11 @@ public function testGetExpressionData(): void
);
}
- #[Group('6257')]
- public function testIsAlwaysNotNullable(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Boolean
+ * @group 6257
+ */
+ public function testIsAlwaysNotNullable()
{
$column = new Boolean('foo', true);
diff --git a/test/unit/Sql/Ddl/Column/CharTest.php b/test/unit/Sql/Ddl/Column/CharTest.php
index 0e833da09..3371eb0d3 100644
--- a/test/unit/Sql/Ddl/Column/CharTest.php
+++ b/test/unit/Sql/Ddl/Column/CharTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Char;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Char::class, 'getExpressionData')]
-final class CharTest extends TestCase
+class CharTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Char::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Char('foo', 20);
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/ColumnTest.php b/test/unit/Sql/Ddl/Column/ColumnTest.php
index 74075284b..2c7aef70d 100644
--- a/test/unit/Sql/Ddl/Column/ColumnTest.php
+++ b/test/unit/Sql/Ddl/Column/ColumnTest.php
@@ -3,22 +3,13 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Column;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Column::class, 'setName')]
-#[CoversMethod(Column::class, 'getName')]
-#[CoversMethod(Column::class, 'setNullable')]
-#[CoversMethod(Column::class, 'isNullable')]
-#[CoversMethod(Column::class, 'setDefault')]
-#[CoversMethod(Column::class, 'getDefault')]
-#[CoversMethod(Column::class, 'setOptions')]
-#[CoversMethod(Column::class, 'setOption')]
-#[CoversMethod(Column::class, 'getOptions')]
-#[CoversMethod(Column::class, 'getExpressionData')]
-final class ColumnTest extends TestCase
+class ColumnTest extends TestCase
{
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::setName
+ */
public function testSetName(): Column
{
$column = new Column();
@@ -26,12 +17,18 @@ public function testSetName(): Column
return $column;
}
- #[Depends('testSetName')]
- public function testGetName(Column $column): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::getName
+ * @depends testSetName
+ */
+ public function testGetName(Column $column)
{
self::assertEquals('foo', $column->getName());
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::setNullable
+ */
public function testSetNullable(): Column
{
$column = new Column();
@@ -39,14 +36,20 @@ public function testSetNullable(): Column
return $column;
}
- #[Depends('testSetNullable')]
- public function testIsNullable(Column $column): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::isNullable
+ * @depends testSetNullable
+ */
+ public function testIsNullable(Column $column)
{
self::assertTrue($column->isNullable());
$column->setNullable(false);
self::assertFalse($column->isNullable());
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::setDefault
+ */
public function testSetDefault(): Column
{
$column = new Column();
@@ -54,12 +57,18 @@ public function testSetDefault(): Column
return $column;
}
- #[Depends('testSetDefault')]
- public function testGetDefault(Column $column): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::getDefault
+ * @depends testSetDefault
+ */
+ public function testGetDefault(Column $column)
{
self::assertEquals('foo bar', $column->getDefault());
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::setOptions
+ */
public function testSetOptions(): Column
{
$column = new Column();
@@ -67,19 +76,28 @@ public function testSetOptions(): Column
return $column;
}
- public function testSetOption(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::setOption
+ */
+ public function testSetOption()
{
$column = new Column();
self::assertSame($column, $column->setOption('primary', true));
}
- #[Depends('testSetOptions')]
- public function testGetOptions(Column $column): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::getOptions
+ * @depends testSetOptions
+ */
+ public function testGetOptions(Column $column)
{
self::assertEquals(['autoincrement' => true], $column->getOptions());
}
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Column();
$column->setName('foo');
diff --git a/test/unit/Sql/Ddl/Column/DateTest.php b/test/unit/Sql/Ddl/Column/DateTest.php
index b8f0d222e..552d6761f 100644
--- a/test/unit/Sql/Ddl/Column/DateTest.php
+++ b/test/unit/Sql/Ddl/Column/DateTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Date;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Date::class, 'getExpressionData')]
-final class DateTest extends TestCase
+class DateTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Date::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Date('foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/DatetimeTest.php b/test/unit/Sql/Ddl/Column/DatetimeTest.php
index b825327b7..6a9c8565b 100644
--- a/test/unit/Sql/Ddl/Column/DatetimeTest.php
+++ b/test/unit/Sql/Ddl/Column/DatetimeTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Datetime;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Datetime::class, 'getExpressionData')]
-final class DatetimeTest extends TestCase
+class DatetimeTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Datetime::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Datetime('foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/DecimalTest.php b/test/unit/Sql/Ddl/Column/DecimalTest.php
index bc4ba635e..7b919e7e1 100644
--- a/test/unit/Sql/Ddl/Column/DecimalTest.php
+++ b/test/unit/Sql/Ddl/Column/DecimalTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Decimal;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Decimal::class, 'getExpressionData')]
-final class DecimalTest extends TestCase
+class DecimalTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Decimal::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Decimal('foo', 10, 5);
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/FloatingTest.php b/test/unit/Sql/Ddl/Column/FloatingTest.php
index 1fc053ab5..0312cbcec 100644
--- a/test/unit/Sql/Ddl/Column/FloatingTest.php
+++ b/test/unit/Sql/Ddl/Column/FloatingTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Floating;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Floating::class, 'getExpressionData')]
-final class FloatingTest extends TestCase
+class FloatingTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Floating::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Floating('foo', 10, 5);
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/IntegerTest.php b/test/unit/Sql/Ddl/Column/IntegerTest.php
index 09719bb20..54b9e88b2 100644
--- a/test/unit/Sql/Ddl/Column/IntegerTest.php
+++ b/test/unit/Sql/Ddl/Column/IntegerTest.php
@@ -2,23 +2,25 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
-use Laminas\Db\Sql\Ddl\Column\Column;
use Laminas\Db\Sql\Ddl\Column\Integer;
use Laminas\Db\Sql\Ddl\Constraint\PrimaryKey;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Integer::class, '__construct')]
-#[CoversMethod(Column::class, 'getExpressionData')]
-final class IntegerTest extends TestCase
+class IntegerTest extends TestCase
{
- public function testObjectConstruction(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Integer::__construct
+ */
+ public function testObjectConstruction()
{
$integer = new Integer('foo');
self::assertEquals('foo', $integer->getName());
}
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Column::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Integer('foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/TextTest.php b/test/unit/Sql/Ddl/Column/TextTest.php
index 7c734cda1..9d9d88919 100644
--- a/test/unit/Sql/Ddl/Column/TextTest.php
+++ b/test/unit/Sql/Ddl/Column/TextTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Text;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Text::class, 'getExpressionData')]
-final class TextTest extends TestCase
+class TextTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Text::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Text('foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/TimeTest.php b/test/unit/Sql/Ddl/Column/TimeTest.php
index 99b7cae1e..543cbbc86 100644
--- a/test/unit/Sql/Ddl/Column/TimeTest.php
+++ b/test/unit/Sql/Ddl/Column/TimeTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Time;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Time::class, 'getExpressionData')]
-final class TimeTest extends TestCase
+class TimeTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Time::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Time('foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/TimestampTest.php b/test/unit/Sql/Ddl/Column/TimestampTest.php
index e3313fb20..09723161d 100644
--- a/test/unit/Sql/Ddl/Column/TimestampTest.php
+++ b/test/unit/Sql/Ddl/Column/TimestampTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Timestamp;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Timestamp::class, 'getExpressionData')]
-final class TimestampTest extends TestCase
+class TimestampTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Timestamp::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Timestamp('foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/VarbinaryTest.php b/test/unit/Sql/Ddl/Column/VarbinaryTest.php
index 6c3fbccec..b8145e058 100644
--- a/test/unit/Sql/Ddl/Column/VarbinaryTest.php
+++ b/test/unit/Sql/Ddl/Column/VarbinaryTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Varbinary;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Varbinary::class, 'getExpressionData')]
-final class VarbinaryTest extends TestCase
+class VarbinaryTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Varbinary::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Varbinary('foo', 20);
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Column/VarcharTest.php b/test/unit/Sql/Ddl/Column/VarcharTest.php
index daff7b993..a7826db87 100644
--- a/test/unit/Sql/Ddl/Column/VarcharTest.php
+++ b/test/unit/Sql/Ddl/Column/VarcharTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Column;
use Laminas\Db\Sql\Ddl\Column\Varchar;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Varchar::class, 'getExpressionData')]
-final class VarcharTest extends TestCase
+class VarcharTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Column\Varchar::getExpressionData
+ */
+ public function testGetExpressionData()
{
$column = new Varchar('foo', 20);
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Constraint/AbstractConstraintTest.php b/test/unit/Sql/Ddl/Constraint/AbstractConstraintTest.php
index 12244d393..bab808d71 100644
--- a/test/unit/Sql/Ddl/Constraint/AbstractConstraintTest.php
+++ b/test/unit/Sql/Ddl/Constraint/AbstractConstraintTest.php
@@ -3,42 +3,40 @@
namespace LaminasTest\Db\Sql\Ddl\Constraint;
use Laminas\Db\Sql\Ddl\Constraint\AbstractConstraint;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\MockObject\Exception;
-use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(AbstractConstraint::class, 'setColumns')]
-#[CoversMethod(AbstractConstraint::class, 'addColumn')]
-#[CoversMethod(AbstractConstraint::class, 'getColumns')]
-final class AbstractConstraintTest extends TestCase
+class AbstractConstraintTest extends TestCase
{
/** @var AbstractConstraint */
- protected AbstractConstraint|MockObject $ac;
+ protected $ac;
- /**
- * @throws Exception
- */
- #[Override]
protected function setUp(): void
{
- $this->ac = $this->getMockBuilder(AbstractConstraint::class)->onlyMethods([])->getMock();
+ $this->ac = $this->getMockForAbstractClass(AbstractConstraint::class);
}
- public function testSetColumns(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\AbstractConstraint::setColumns
+ */
+ public function testSetColumns()
{
self::assertSame($this->ac, $this->ac->setColumns(['foo', 'bar']));
self::assertEquals(['foo', 'bar'], $this->ac->getColumns());
}
- public function testAddColumn(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\AbstractConstraint::addColumn
+ */
+ public function testAddColumn()
{
self::assertSame($this->ac, $this->ac->addColumn('foo'));
self::assertEquals(['foo'], $this->ac->getColumns());
}
- public function testGetColumns(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\AbstractConstraint::getColumns
+ */
+ public function testGetColumns()
{
$this->ac->setColumns(['foo', 'bar']);
self::assertEquals(['foo', 'bar'], $this->ac->getColumns());
diff --git a/test/unit/Sql/Ddl/Constraint/CheckTest.php b/test/unit/Sql/Ddl/Constraint/CheckTest.php
index ce087d590..b430aa113 100644
--- a/test/unit/Sql/Ddl/Constraint/CheckTest.php
+++ b/test/unit/Sql/Ddl/Constraint/CheckTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Constraint;
use Laminas\Db\Sql\Ddl\Constraint\Check;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Check::class, 'getExpressionData')]
-final class CheckTest extends TestCase
+class CheckTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\Check::getExpressionData
+ */
+ public function testGetExpressionData()
{
$check = new Check('id>0', 'foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Constraint/ForeignKeyTest.php b/test/unit/Sql/Ddl/Constraint/ForeignKeyTest.php
index e185d8382..81c1f809c 100644
--- a/test/unit/Sql/Ddl/Constraint/ForeignKeyTest.php
+++ b/test/unit/Sql/Ddl/Constraint/ForeignKeyTest.php
@@ -3,23 +3,13 @@
namespace LaminasTest\Db\Sql\Ddl\Constraint;
use Laminas\Db\Sql\Ddl\Constraint\ForeignKey;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(ForeignKey::class, 'setName')]
-#[CoversMethod(ForeignKey::class, 'getName')]
-#[CoversMethod(ForeignKey::class, 'setReferenceTable')]
-#[CoversMethod(ForeignKey::class, 'getReferenceTable')]
-#[CoversMethod(ForeignKey::class, 'setReferenceColumn')]
-#[CoversMethod(ForeignKey::class, 'getReferenceColumn')]
-#[CoversMethod(ForeignKey::class, 'setOnDeleteRule')]
-#[CoversMethod(ForeignKey::class, 'getOnDeleteRule')]
-#[CoversMethod(ForeignKey::class, 'setOnUpdateRule')]
-#[CoversMethod(ForeignKey::class, 'getOnUpdateRule')]
-#[CoversMethod(ForeignKey::class, 'getExpressionData')]
-final class ForeignKeyTest extends TestCase
+class ForeignKeyTest extends TestCase
{
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::setName
+ */
public function testSetName(): ForeignKey
{
$fk = new ForeignKey('foo', 'bar', 'baz', 'bam');
@@ -27,12 +17,18 @@ public function testSetName(): ForeignKey
return $fk;
}
- #[Depends('testSetName')]
- public function testGetName(ForeignKey $fk): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::getName
+ * @depends testSetName
+ */
+ public function testGetName(ForeignKey $fk)
{
self::assertEquals('xxxx', $fk->getName());
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::setReferenceTable
+ */
public function testSetReferenceTable(): ForeignKey
{
$fk = new ForeignKey('foo', 'bar', 'baz', 'bam');
@@ -40,12 +36,18 @@ public function testSetReferenceTable(): ForeignKey
return $fk;
}
- #[Depends('testSetReferenceTable')]
- public function testGetReferenceTable(ForeignKey $fk): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::getReferenceTable
+ * @depends testSetReferenceTable
+ */
+ public function testGetReferenceTable(ForeignKey $fk)
{
self::assertEquals('xxxx', $fk->getReferenceTable());
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::setReferenceColumn
+ */
public function testSetReferenceColumn(): ForeignKey
{
$fk = new ForeignKey('foo', 'bar', 'baz', 'bam');
@@ -53,12 +55,18 @@ public function testSetReferenceColumn(): ForeignKey
return $fk;
}
- #[Depends('testSetReferenceColumn')]
- public function testGetReferenceColumn(ForeignKey $fk): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::getReferenceColumn
+ * @depends testSetReferenceColumn
+ */
+ public function testGetReferenceColumn(ForeignKey $fk)
{
self::assertEquals(['xxxx'], $fk->getReferenceColumn());
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::setOnDeleteRule
+ */
public function testSetOnDeleteRule(): ForeignKey
{
$fk = new ForeignKey('foo', 'bar', 'baz', 'bam');
@@ -66,12 +74,18 @@ public function testSetOnDeleteRule(): ForeignKey
return $fk;
}
- #[Depends('testSetOnDeleteRule')]
- public function testGetOnDeleteRule(ForeignKey $fk): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::getOnDeleteRule
+ * @depends testSetOnDeleteRule
+ */
+ public function testGetOnDeleteRule(ForeignKey $fk)
{
self::assertEquals('CASCADE', $fk->getOnDeleteRule());
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::setOnUpdateRule
+ */
public function testSetOnUpdateRule(): ForeignKey
{
$fk = new ForeignKey('foo', 'bar', 'baz', 'bam');
@@ -79,13 +93,19 @@ public function testSetOnUpdateRule(): ForeignKey
return $fk;
}
- #[Depends('testSetOnUpdateRule')]
- public function testGetOnUpdateRule(ForeignKey $fk): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::getOnUpdateRule
+ * @depends testSetOnUpdateRule
+ */
+ public function testGetOnUpdateRule(ForeignKey $fk)
{
self::assertEquals('CASCADE', $fk->getOnUpdateRule());
}
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\ForeignKey::getExpressionData
+ */
+ public function testGetExpressionData()
{
$fk = new ForeignKey('foo', 'bar', 'baz', 'bam', 'CASCADE', 'SET NULL');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Constraint/PrimaryKeyTest.php b/test/unit/Sql/Ddl/Constraint/PrimaryKeyTest.php
index 2ea3acc4d..4f5327655 100644
--- a/test/unit/Sql/Ddl/Constraint/PrimaryKeyTest.php
+++ b/test/unit/Sql/Ddl/Constraint/PrimaryKeyTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Constraint;
use Laminas\Db\Sql\Ddl\Constraint\PrimaryKey;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(PrimaryKey::class, 'getExpressionData')]
-final class PrimaryKeyTest extends TestCase
+class PrimaryKeyTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\PrimaryKey::getExpressionData
+ */
+ public function testGetExpressionData()
{
$pk = new PrimaryKey('foo');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/Constraint/UniqueKeyTest.php b/test/unit/Sql/Ddl/Constraint/UniqueKeyTest.php
index f38cabc1c..928e6c29d 100644
--- a/test/unit/Sql/Ddl/Constraint/UniqueKeyTest.php
+++ b/test/unit/Sql/Ddl/Constraint/UniqueKeyTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Constraint;
use Laminas\Db\Sql\Ddl\Constraint\UniqueKey;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(UniqueKey::class, 'getExpressionData')]
-final class UniqueKeyTest extends TestCase
+class UniqueKeyTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Constraint\UniqueKey::getExpressionData
+ */
+ public function testGetExpressionData()
{
$uk = new UniqueKey('foo', 'my_uk');
self::assertEquals(
diff --git a/test/unit/Sql/Ddl/CreateTableTest.php b/test/unit/Sql/Ddl/CreateTableTest.php
index 4212bcc79..41b36551e 100644
--- a/test/unit/Sql/Ddl/CreateTableTest.php
+++ b/test/unit/Sql/Ddl/CreateTableTest.php
@@ -8,33 +8,28 @@
use Laminas\Db\Sql\Ddl\Constraint\ConstraintInterface;
use Laminas\Db\Sql\Ddl\CreateTable;
use Laminas\Db\Sql\TableIdentifier;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;
use function array_pop;
-#[CoversMethod(CreateTable::class, '__construct')]
-#[CoversMethod(CreateTable::class, 'setTemporary')]
-#[CoversMethod(CreateTable::class, 'isTemporary')]
-#[CoversMethod(CreateTable::class, 'setTable')]
-#[CoversMethod(CreateTable::class, 'getRawState')]
-#[CoversMethod(CreateTable::class, 'addColumn')]
-#[CoversMethod(CreateTable::class, 'addConstraint')]
-#[CoversMethod(CreateTable::class, 'getSqlString')]
-final class CreateTableTest extends TestCase
+class CreateTableTest extends TestCase
{
/**
* test object construction
+ *
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::__construct
*/
- public function testObjectConstruction(): void
+ public function testObjectConstruction()
{
$ct = new CreateTable('foo', true);
self::assertEquals('foo', $ct->getRawState($ct::TABLE));
self::assertTrue($ct->isTemporary());
}
- public function testSetTemporary(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::setTemporary
+ */
+ public function testSetTemporary()
{
$ct = new CreateTable();
self::assertSame($ct, $ct->setTemporary(false));
@@ -47,7 +42,10 @@ public function testSetTemporary(): void
self::assertStringStartsWith("CREATE TEMPORARY TABLE", $ct->getSqlString());
}
- public function testIsTemporary(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::isTemporary
+ */
+ public function testIsTemporary()
{
$ct = new CreateTable();
self::assertFalse($ct->isTemporary());
@@ -55,6 +53,9 @@ public function testIsTemporary(): void
self::assertTrue($ct->isTemporary());
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::setTable
+ */
public function testSetTable(): CreateTable
{
$ct = new CreateTable();
@@ -63,12 +64,18 @@ public function testSetTable(): CreateTable
return $ct;
}
- #[Depends('testSetTable')]
- public function testRawStateViaTable(CreateTable $ct): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::getRawState
+ * @depends testSetTable
+ */
+ public function testRawStateViaTable(CreateTable $ct)
{
self::assertEquals('test', $ct->getRawState('table'));
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::addColumn
+ */
public function testAddColumn(): CreateTable
{
$column = $this->getMockBuilder(ColumnInterface::class)->getMock();
@@ -77,8 +84,11 @@ public function testAddColumn(): CreateTable
return $ct;
}
- #[Depends('testAddColumn')]
- public function testRawStateViaColumn(CreateTable $ct): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::getRawState
+ * @depends testAddColumn
+ */
+ public function testRawStateViaColumn(CreateTable $ct)
{
$state = $ct->getRawState('columns');
self::assertIsArray($state);
@@ -86,6 +96,9 @@ public function testRawStateViaColumn(CreateTable $ct): void
self::assertInstanceOf(ColumnInterface::class, $column);
}
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::addConstraint
+ */
public function testAddConstraint(): CreateTable
{
$constraint = $this->getMockBuilder(ConstraintInterface::class)->getMock();
@@ -94,8 +107,11 @@ public function testAddConstraint(): CreateTable
return $ct;
}
- #[Depends('testAddConstraint')]
- public function testRawStateViaConstraint(CreateTable $ct): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::getRawState
+ * @depends testAddConstraint
+ */
+ public function testRawStateViaConstraint(CreateTable $ct)
{
$state = $ct->getRawState('constraints');
self::assertIsArray($state);
@@ -103,7 +119,10 @@ public function testRawStateViaConstraint(CreateTable $ct): void
self::assertInstanceOf(ConstraintInterface::class, $constraint);
}
- public function testGetSqlString(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\CreateTable::getSqlString
+ */
+ public function testGetSqlString()
{
$ct = new CreateTable('foo');
self::assertEquals("CREATE TABLE \"foo\" ( \n)", $ct->getSqlString());
diff --git a/test/unit/Sql/Ddl/DropTableTest.php b/test/unit/Sql/Ddl/DropTableTest.php
index fc9c8b5ac..ac03b312e 100644
--- a/test/unit/Sql/Ddl/DropTableTest.php
+++ b/test/unit/Sql/Ddl/DropTableTest.php
@@ -4,13 +4,14 @@
use Laminas\Db\Sql\Ddl\DropTable;
use Laminas\Db\Sql\TableIdentifier;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(DropTable::class, 'getSqlString')]
-final class DropTableTest extends TestCase
+class DropTableTest extends TestCase
{
- public function testGetSqlString(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\DropTable::getSqlString
+ */
+ public function testGetSqlString()
{
$dt = new DropTable('foo');
self::assertEquals('DROP TABLE "foo"', $dt->getSqlString());
diff --git a/test/unit/Sql/Ddl/Index/IndexTest.php b/test/unit/Sql/Ddl/Index/IndexTest.php
index 68f0d4df7..3539f9098 100644
--- a/test/unit/Sql/Ddl/Index/IndexTest.php
+++ b/test/unit/Sql/Ddl/Index/IndexTest.php
@@ -3,13 +3,14 @@
namespace LaminasTest\Db\Sql\Ddl\Index;
use Laminas\Db\Sql\Ddl\Index\Index;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Index::class, 'getExpressionData')]
-final class IndexTest extends TestCase
+class IndexTest extends TestCase
{
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Index\Index::getExpressionData
+ */
+ public function testGetExpressionData()
{
$uk = new Index('foo', 'my_uk');
self::assertEquals(
@@ -24,7 +25,10 @@ public function testGetExpressionData(): void
);
}
- public function testGetExpressionDataWithLength(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Index\Index::getExpressionData
+ */
+ public function testGetExpressionDataWithLength()
{
$key = new Index(['foo', 'bar'], 'my_uk', [10, 5]);
self::assertEquals(
@@ -39,7 +43,10 @@ public function testGetExpressionDataWithLength(): void
);
}
- public function testGetExpressionDataWithLengthUnmatched(): void
+ /**
+ * @covers \Laminas\Db\Sql\Ddl\Index\Index::getExpressionData
+ */
+ public function testGetExpressionDataWithLengthUnmatched()
{
$key = new Index(['foo', 'bar'], 'my_uk', [10]);
self::assertEquals(
diff --git a/test/unit/Sql/DeleteTest.php b/test/unit/Sql/DeleteTest.php
index 65e0249f0..d9697f63f 100644
--- a/test/unit/Sql/DeleteTest.php
+++ b/test/unit/Sql/DeleteTest.php
@@ -16,26 +16,19 @@
use Laminas\Db\Sql\Where;
use LaminasTest\Db\DeprecatedAssertionsTrait;
use LaminasTest\Db\TestAsset\DeleteIgnore;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Delete::class, 'from')]
-#[CoversMethod(Delete::class, 'where')]
-#[CoversMethod(Delete::class, 'prepareStatement')]
-#[CoversMethod(Delete::class, 'getSqlString')]
-final class DeleteTest extends TestCase
+class DeleteTest extends TestCase
{
use DeprecatedAssertionsTrait;
- protected Delete $delete;
+ /** @var Delete */
+ protected $delete;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->delete = new Delete();
@@ -49,9 +42,12 @@ protected function tearDown(): void
{
}
- public function testFrom(): void
+ /**
+ * @covers \Laminas\Db\Sql\Delete::from
+ */
+ public function testFrom()
{
- $this->delete->from('foo');
+ $this->delete->from('foo', 'bar');
self::assertEquals('foo', $this->readAttribute($this->delete, 'table'));
$tableIdentifier = new TableIdentifier('foo', 'bar');
@@ -60,9 +56,10 @@ public function testFrom(): void
}
/**
+ * @covers \Laminas\Db\Sql\Delete::where
* @todo REMOVE THIS IN 3.x
*/
- public function testWhere(): void
+ public function testWhere()
{
$this->delete->where('x = y');
$this->delete->where(['foo > ?' => 5]);
@@ -106,21 +103,24 @@ public function testWhere(): void
$this->delete->where($where);
self::assertSame($where, $this->delete->where);
- $this->delete->where(function ($what) use ($where): void {
+ $this->delete->where(function ($what) use ($where) {
self::assertSame($where, $what);
});
}
- public function testPrepareStatement(): void
+ /**
+ * @covers \Laminas\Db\Sql\Delete::prepareStatement
+ */
+ public function testPrepareStatement()
{
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->at(2))
->method('setSql')
->with($this->equalTo('DELETE FROM "foo" WHERE x = y'));
@@ -133,12 +133,12 @@ public function testPrepareStatement(): void
$this->delete = new Delete();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->at(2))
->method('setSql')
->with($this->equalTo('DELETE FROM "sch"."foo" WHERE x = y'));
@@ -148,7 +148,10 @@ public function testPrepareStatement(): void
$this->delete->prepareStatement($mockAdapter, $mockStatement);
}
- public function testGetSqlString(): void
+ /**
+ * @covers \Laminas\Db\Sql\Delete::getSqlString
+ */
+ public function testGetSqlString()
{
$this->delete->from('foo')
->where('x = y');
@@ -161,19 +164,21 @@ public function testGetSqlString(): void
self::assertEquals('DELETE FROM "sch"."foo" WHERE x = y', $this->delete->getSqlString());
}
- #[CoversNothing]
- public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement(): void
+ /**
+ * @coversNothing
+ */
+ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement()
{
$deleteIgnore = new DeleteIgnore();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->at(2))
->method('setSql')
->with($this->equalTo('DELETE IGNORE FROM "foo" WHERE x = y'));
@@ -187,12 +192,12 @@ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareSt
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->at(2))
->method('setSql')
->with($this->equalTo('DELETE IGNORE FROM "sch"."foo" WHERE x = y'));
@@ -202,8 +207,10 @@ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareSt
$deleteIgnore->prepareStatement($mockAdapter, $mockStatement);
}
- #[CoversNothing]
- public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString(): void
+ /**
+ * @coversNothing
+ */
+ public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString()
{
$deleteIgnore = new DeleteIgnore();
diff --git a/test/unit/Sql/ExpressionTest.php b/test/unit/Sql/ExpressionTest.php
index a01a92f72..3eeda3108 100644
--- a/test/unit/Sql/ExpressionTest.php
+++ b/test/unit/Sql/ExpressionTest.php
@@ -4,10 +4,6 @@
use Laminas\Db\Sql\Exception\InvalidArgumentException;
use Laminas\Db\Sql\Expression;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\Depends;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use TypeError;
@@ -17,14 +13,10 @@
*
* Expression is a value object with no dependencies/collaborators, therefore, no fixure needed
*/
-#[CoversMethod(Expression::class, 'setExpression')]
-#[CoversMethod(Expression::class, 'getExpression')]
-#[CoversMethod(Expression::class, 'setParameters')]
-#[CoversMethod(Expression::class, 'getParameters')]
-#[CoversMethod(Expression::class, 'getExpressionData')]
-final class ExpressionTest extends TestCase
+class ExpressionTest extends TestCase
{
/**
+ * @covers \Laminas\Db\Sql\Expression::setExpression
* @return Expression
*/
public function testSetExpression()
@@ -35,11 +27,13 @@ public function testSetExpression()
return $return;
}
- public function testSetExpressionException(): void
+ /**
+ * @covers \Laminas\Db\Sql\Expression::setExpression
+ */
+ public function testSetExpressionException()
{
$expression = new Expression();
$this->expectException(TypeError::class);
- /** @psalm-suppress NullArgument - ensure an exception is thrown */
$expression->setExpression(null);
$expression = new Expression();
@@ -48,12 +42,18 @@ public function testSetExpressionException(): void
$expression->setExpression('');
}
- #[Depends('testSetExpression')]
- public function testGetExpression(Expression $expression): void
+ /**
+ * @covers \Laminas\Db\Sql\Expression::getExpression
+ * @depends testSetExpression
+ */
+ public function testGetExpression(Expression $expression)
{
self::assertEquals('Foo Bar', $expression->getExpression());
}
+ /**
+ * @covers \Laminas\Db\Sql\Expression::setParameters
+ */
public function testSetParameters(): Expression
{
$expression = new Expression();
@@ -62,22 +62,30 @@ public function testSetParameters(): Expression
return $return;
}
- public function testSetParametersException(): void
+ /**
+ * @covers \Laminas\Db\Sql\Expression::setParameters
+ */
+ public function testSetParametersException()
{
$expression = new Expression('', 'foo');
$this->expectException(TypeError::class);
- /** @psalm-suppress NullArgument - ensure an exception is thrown */
$expression->setParameters(null);
}
- #[Depends('testSetParameters')]
- public function testGetParameters(Expression $expression): void
+ /**
+ * @covers \Laminas\Db\Sql\Expression::getParameters
+ * @depends testSetParameters
+ */
+ public function testGetParameters(Expression $expression)
{
self::assertEquals('foo', $expression->getParameters());
}
- public function testGetExpressionData(): void
+ /**
+ * @covers \Laminas\Db\Sql\Expression::getExpressionData
+ */
+ public function testGetExpressionData()
{
$expression = new Expression(
'X SAME AS ? AND Y = ? BUT LITERALLY ?',
@@ -99,7 +107,7 @@ public function testGetExpressionData(): void
self::assertEquals($expected, $expression->getExpressionData());
}
- public function testGetExpressionDataWillEscapePercent(): void
+ public function testGetExpressionDataWillEscapePercent()
{
$expression = new Expression('X LIKE "foo%"');
self::assertEquals(
@@ -108,14 +116,16 @@ public function testGetExpressionDataWillEscapePercent(): void
);
}
- public function testConstructorWithLiteralZero(): void
+ public function testConstructorWithLiteralZero()
{
$expression = new Expression('0');
self::assertSame('0', $expression->getExpression());
}
- #[Group('7407')]
- public function testGetExpressionPreservesPercentageSignInFromUnixtime(): void
+ /**
+ * @group 7407
+ */
+ public function testGetExpressionPreservesPercentageSignInFromUnixtime()
{
$expressionString = 'FROM_UNIXTIME(date, "%Y-%m")';
$expression = new Expression($expressionString);
@@ -123,7 +133,7 @@ public function testGetExpressionPreservesPercentageSignInFromUnixtime(): void
self::assertSame($expressionString, $expression->getExpression());
}
- public function testNumberOfReplacementsConsidersWhenSameVariableIsUsedManyTimes(): void
+ public function testNumberOfReplacementsConsidersWhenSameVariableIsUsedManyTimes()
{
$expression = new Expression('uf.user_id = :user_id OR uf.friend_id = :user_id', ['user_id' => 1]);
@@ -139,21 +149,24 @@ public function testNumberOfReplacementsConsidersWhenSameVariableIsUsedManyTimes
);
}
- #[DataProvider('falsyExpressionParametersProvider')]
- public function testConstructorWithFalsyValidParameters(mixed $falsyParameter): void
+ /**
+ * @dataProvider falsyExpressionParametersProvider
+ * @param mixed $falsyParameter
+ */
+ public function testConstructorWithFalsyValidParameters($falsyParameter)
{
$expression = new Expression('?', $falsyParameter);
self::assertSame($falsyParameter, $expression->getParameters());
}
- public function testConstructorWithInvalidParameter(): void
+ public function testConstructorWithInvalidParameter()
{
$this->expectException(TypeError::class);
new Expression('?', (object) []);
}
/** @psalm-return array */
- public static function falsyExpressionParametersProvider(): array
+ public function falsyExpressionParametersProvider(): array
{
return [
[''],
@@ -165,7 +178,7 @@ public static function falsyExpressionParametersProvider(): array
];
}
- public function testNumberOfReplacementsForExpressionWithParameters(): void
+ public function testNumberOfReplacementsForExpressionWithParameters()
{
$expression = new Expression(':a + :b', ['a' => 1, 'b' => 2]);
diff --git a/test/unit/Sql/InsertIgnoreTest.php b/test/unit/Sql/InsertIgnoreTest.php
index 02f472af9..2075f0f9c 100644
--- a/test/unit/Sql/InsertIgnoreTest.php
+++ b/test/unit/Sql/InsertIgnoreTest.php
@@ -15,28 +15,25 @@
use LaminasTest\Db\DeprecatedAssertionsTrait;
use LaminasTest\Db\TestAsset\Replace;
use LaminasTest\Db\TestAsset\TrustingSql92Platform;
-use Override;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
-final class InsertIgnoreTest extends TestCase
+class InsertIgnoreTest extends TestCase
{
use DeprecatedAssertionsTrait;
- protected InsertIgnore $insert;
+ /** @var InsertIgnore */
+ protected $insert;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->insert = new InsertIgnore();
}
- public function testInto(): void
+ public function testInto()
{
$this->insert->into('table');
self::assertEquals('table', $this->insert->getRawState('table'));
@@ -46,14 +43,14 @@ public function testInto(): void
self::assertEquals($tableIdentifier, $this->insert->getRawState('table'));
}
- public function testColumns(): void
+ public function testColumns()
{
$columns = ['foo', 'bar'];
$this->insert->columns($columns);
self::assertEquals($columns, $this->insert->getRawState('columns'));
}
- public function testValues(): void
+ public function testValues()
{
$this->insert->values(['foo' => 'bar']);
self::assertEquals(['foo'], $this->insert->getRawState('columns'));
@@ -70,14 +67,14 @@ public function testValues(): void
self::assertEquals(['bax'], $this->insert->getRawState('values'));
}
- public function testValuesThrowsExceptionWhenNotArrayOrSelect(): void
+ public function testValuesThrowsExceptionWhenNotArrayOrSelect()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('values() expects an array of values or Laminas\Db\Sql\Select instance');
$this->insert->values(5);
}
- public function testValuesThrowsExceptionWhenSelectMergeOverArray(): void
+ public function testValuesThrowsExceptionWhenSelectMergeOverArray()
{
$this->insert->values(['foo' => 'bar']);
@@ -86,7 +83,7 @@ public function testValuesThrowsExceptionWhenSelectMergeOverArray(): void
$this->insert->values(new Select(), InsertIgnore::VALUES_MERGE);
}
- public function testValuesThrowsExceptionWhenArrayMergeOverSelect(): void
+ public function testValuesThrowsExceptionWhenArrayMergeOverSelect()
{
$this->insert->values(new Select());
@@ -99,29 +96,28 @@ public function testValuesThrowsExceptionWhenArrayMergeOverSelect(): void
}
/**
- * @throws ReflectionException
+ * @group Laminas-4926
*/
- #[Group('Laminas-4926')]
- public function testEmptyArrayValues(): void
+ public function testEmptyArrayValues()
{
$this->insert->values([]);
self::assertEquals([], $this->readAttribute($this->insert, 'columns'));
}
- public function testPrepareStatement(): void
+ public function testPrepareStatement()
{
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('INSERT IGNORE INTO "foo" ("bar", "boo") VALUES (?, NOW())'));
@@ -133,17 +129,17 @@ public function testPrepareStatement(): void
// with TableIdentifier
$this->insert = new InsertIgnore();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('INSERT IGNORE INTO "sch"."foo" ("bar", "boo") VALUES (?, NOW())'));
@@ -153,13 +149,13 @@ public function testPrepareStatement(): void
$this->insert->prepareStatement($mockAdapter, $mockStatement);
}
- public function testPrepareStatementWithSelect(): void
+ public function testPrepareStatementWithSelect()
{
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
@@ -180,7 +176,7 @@ public function testPrepareStatementWithSelect(): void
self::assertSame(['subselect1where1' => 5], $parameters);
}
- public function testGetSqlString(): void
+ public function testGetSqlString()
{
$this->insert->into('foo')
->values(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]);
@@ -218,7 +214,7 @@ public function testGetSqlString(): void
);
}
- public function testGetSqlStringUsingColumnsAndValuesMethods(): void
+ public function testGetSqlStringUsingColumnsAndValuesMethods()
{
// With columns() and values()
$this->insert
@@ -232,7 +228,7 @@ public function testGetSqlStringUsingColumnsAndValuesMethods(): void
}
// @codingStandardsIgnoreStart
- public function test__set(): void
+ public function test__set()
{
// @codingStandardsIgnoreEnd
$this->insert->foo = 'bar';
@@ -241,7 +237,7 @@ public function test__set(): void
}
// @codingStandardsIgnoreStart
- public function test__unset(): void
+ public function test__unset()
{
// @codingStandardsIgnoreEnd
$this->insert->foo = 'bar';
@@ -261,7 +257,7 @@ public function test__unset(): void
}
// @codingStandardsIgnoreStart
- public function test__isset(): void
+ public function test__isset()
{
// @codingStandardsIgnoreEnd
$this->insert->foo = 'bar';
@@ -272,7 +268,7 @@ public function test__isset(): void
}
// @codingStandardsIgnoreStart
- public function test__get(): void
+ public function test__get()
{
// @codingStandardsIgnoreEnd
$this->insert->foo = 'bar';
@@ -282,8 +278,10 @@ public function test__get(): void
self::assertNull($this->insert->foo);
}
- #[Group('Laminas-536')]
- public function testValuesMerge(): void
+ /**
+ * @group Laminas-536
+ */
+ public function testValuesMerge()
{
$this->insert->into('foo')
->values(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]);
@@ -296,22 +294,22 @@ public function testValuesMerge(): void
);
}
- public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement(): void
+ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement()
{
$replace = new Replace();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('REPLACE INTO "foo" ("bar", "boo") VALUES (?, NOW())'));
@@ -324,17 +322,17 @@ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareSt
$replace = new Replace();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('REPLACE INTO "sch"."foo" ("bar", "boo") VALUES (?, NOW())'));
@@ -344,7 +342,7 @@ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareSt
$replace->prepareStatement($mockAdapter, $mockStatement);
}
- public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString(): void
+ public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString()
{
$replace = new Replace();
$replace->into('foo')
diff --git a/test/unit/Sql/InsertTest.php b/test/unit/Sql/InsertTest.php
index e9f8312a7..0b6f853ac 100644
--- a/test/unit/Sql/InsertTest.php
+++ b/test/unit/Sql/InsertTest.php
@@ -15,41 +15,30 @@
use LaminasTest\Db\DeprecatedAssertionsTrait;
use LaminasTest\Db\TestAsset\Replace;
use LaminasTest\Db\TestAsset\TrustingSql92Platform;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\CoversNothing;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
-
-#[CoversMethod(Insert::class, 'into')]
-#[CoversMethod(Insert::class, 'columns')]
-#[CoversMethod(Insert::class, 'values')]
-#[CoversMethod(Insert::class, 'prepareStatement')]
-#[CoversMethod(Insert::class, 'getSqlString')]
-#[CoversMethod(Insert::class, '__set')]
-#[CoversMethod(Insert::class, '__unset')]
-#[CoversMethod(Insert::class, '__isset')]
-#[CoversMethod(Insert::class, '__get')]
-final class InsertTest extends TestCase
+
+class InsertTest extends TestCase
{
use DeprecatedAssertionsTrait;
- protected Insert $insert;
+ /** @var Insert */
+ protected $insert;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->insert = new Insert();
}
- public function testInto(): void
+ /**
+ * @covers \Laminas\Db\Sql\Insert::into
+ */
+ public function testInto()
{
- $this->insert->into('table');
+ $this->insert->into('table', 'schema');
self::assertEquals('table', $this->insert->getRawState('table'));
$tableIdentifier = new TableIdentifier('table', 'schema');
@@ -57,14 +46,20 @@ public function testInto(): void
self::assertEquals($tableIdentifier, $this->insert->getRawState('table'));
}
- public function testColumns(): void
+ /**
+ * @covers \Laminas\Db\Sql\Insert::columns
+ */
+ public function testColumns()
{
$columns = ['foo', 'bar'];
$this->insert->columns($columns);
self::assertEquals($columns, $this->insert->getRawState('columns'));
}
- public function testValues(): void
+ /**
+ * @covers \Laminas\Db\Sql\Insert::values
+ */
+ public function testValues()
{
$this->insert->values(['foo' => 'bar']);
self::assertEquals(['foo'], $this->insert->getRawState('columns'));
@@ -81,15 +76,20 @@ public function testValues(): void
self::assertEquals(['bax'], $this->insert->getRawState('values'));
}
- public function testValuesThrowsExceptionWhenNotArrayOrSelect(): void
+ /**
+ * @covers \Laminas\Db\Sql\Insert::values
+ */
+ public function testValuesThrowsExceptionWhenNotArrayOrSelect()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('values() expects an array of values or Laminas\Db\Sql\Select instance');
- /** @psalm-suppress InvalidArgument */
$this->insert->values(5);
}
- public function testValuesThrowsExceptionWhenSelectMergeOverArray(): void
+ /**
+ * @covers \Laminas\Db\Sql\Insert::values
+ */
+ public function testValuesThrowsExceptionWhenSelectMergeOverArray()
{
$this->insert->values(['foo' => 'bar']);
@@ -98,7 +98,10 @@ public function testValuesThrowsExceptionWhenSelectMergeOverArray(): void
$this->insert->values(new Select(), Insert::VALUES_MERGE);
}
- public function testValuesThrowsExceptionWhenArrayMergeOverSelect(): void
+ /**
+ * @covers \Laminas\Db\Sql\Insert::values
+ */
+ public function testValuesThrowsExceptionWhenArrayMergeOverSelect()
{
$this->insert->values(new Select());
@@ -111,29 +114,32 @@ public function testValuesThrowsExceptionWhenArrayMergeOverSelect(): void
}
/**
- * @throws ReflectionException
+ * @covers \Laminas\Db\Sql\Insert::values
+ * @group Laminas-4926
*/
- #[Group('Laminas-4926')]
- public function testEmptyArrayValues(): void
+ public function testEmptyArrayValues()
{
$this->insert->values([]);
self::assertEquals([], $this->readAttribute($this->insert, 'columns'));
}
- public function testPrepareStatement(): void
+ /**
+ * @covers \Laminas\Db\Sql\Insert::prepareStatement
+ */
+ public function testPrepareStatement()
{
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('INSERT INTO "foo" ("bar", "boo") VALUES (?, NOW())'));
@@ -145,17 +151,17 @@ public function testPrepareStatement(): void
// with TableIdentifier
$this->insert = new Insert();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('INSERT INTO "sch"."foo" ("bar", "boo") VALUES (?, NOW())'));
@@ -165,13 +171,16 @@ public function testPrepareStatement(): void
$this->insert->prepareStatement($mockAdapter, $mockStatement);
}
- public function testPrepareStatementWithSelect(): void
+ /**
+ * @covers \Laminas\Db\Sql\Insert::prepareStatement
+ */
+ public function testPrepareStatementWithSelect()
{
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
@@ -188,14 +197,14 @@ public function testPrepareStatementWithSelect(): void
'INSERT INTO "foo" ("col1") SELECT "bar".* FROM "bar" WHERE "x" = ?',
$mockStatement->getSql()
);
- $parameters = $mockStatement->getParameterContainer();
- $this->assertInstanceOf(ParameterContainer::class, $parameters);
-
- $namedArray = $parameters->getNamedArray();
- self::assertSame(['subselect1where1' => 5], $namedArray);
+ $parameters = $mockStatement->getParameterContainer()->getNamedArray();
+ self::assertSame(['subselect1where1' => 5], $parameters);
}
- public function testGetSqlString(): void
+ /**
+ * @covers \Laminas\Db\Sql\Insert::getSqlString
+ */
+ public function testGetSqlString()
{
$this->insert->into('foo')
->values(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]);
@@ -233,7 +242,7 @@ public function testGetSqlString(): void
);
}
- public function testGetSqlStringUsingColumnsAndValuesMethods(): void
+ public function testGetSqlStringUsingColumnsAndValuesMethods()
{
// With columns() and values()
$this->insert
@@ -246,21 +255,25 @@ public function testGetSqlStringUsingColumnsAndValuesMethods(): void
);
}
+ /**
+ * @covers \Laminas\Db\Sql\Insert::__set
+ */
// @codingStandardsIgnoreStart
- public function test__set(): void
+ public function test__set()
{
// @codingStandardsIgnoreEnd
- /** @psalm-suppress UndefinedMagicPropertyAssignment */
$this->insert->foo = 'bar';
self::assertEquals(['foo'], $this->insert->getRawState('columns'));
self::assertEquals(['bar'], $this->insert->getRawState('values'));
}
+ /**
+ * @covers \Laminas\Db\Sql\Insert::__unset
+ */
// @codingStandardsIgnoreStart
- public function test__unset(): void
+ public function test__unset()
{
// @codingStandardsIgnoreEnd
- /** @psalm-suppress UndefinedMagicPropertyAssignment */
$this->insert->foo = 'bar';
self::assertEquals(['foo'], $this->insert->getRawState('columns'));
self::assertEquals(['bar'], $this->insert->getRawState('values'));
@@ -268,7 +281,6 @@ public function test__unset(): void
self::assertEquals([], $this->insert->getRawState('columns'));
self::assertEquals([], $this->insert->getRawState('values'));
- /** @psalm-suppress UndefinedMagicPropertyAssignment */
$this->insert->foo = null;
self::assertEquals(['foo'], $this->insert->getRawState('columns'));
self::assertEquals([null], $this->insert->getRawState('values'));
@@ -278,36 +290,38 @@ public function test__unset(): void
self::assertEquals([], $this->insert->getRawState('values'));
}
+ /**
+ * @covers \Laminas\Db\Sql\Insert::__isset
+ */
// @codingStandardsIgnoreStart
- public function test__isset(): void
+ public function test__isset()
{
// @codingStandardsIgnoreEnd
- /** @psalm-suppress UndefinedMagicPropertyAssignment */
$this->insert->foo = 'bar';
- /** @psalm-suppress RedundantCondition */
self::assertTrue(isset($this->insert->foo));
- /** @psalm-suppress UndefinedMagicPropertyAssignment */
$this->insert->foo = null;
- /** @psalm-suppress TypeDoesNotContainType */
self::assertTrue(isset($this->insert->foo));
}
+ /**
+ * @covers \Laminas\Db\Sql\Insert::__get
+ */
// @codingStandardsIgnoreStart
- public function test__get(): void
+ public function test__get()
{
// @codingStandardsIgnoreEnd
- /** @psalm-suppress UndefinedMagicPropertyAssignment */
$this->insert->foo = 'bar';
self::assertEquals('bar', $this->insert->foo);
- /** @psalm-suppress UndefinedMagicPropertyAssignment */
$this->insert->foo = null;
self::assertNull($this->insert->foo);
}
- #[Group('Laminas-536')]
- public function testValuesMerge(): void
+ /**
+ * @group Laminas-536
+ */
+ public function testValuesMerge()
{
$this->insert->into('foo')
->values(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]);
@@ -320,23 +334,25 @@ public function testValuesMerge(): void
);
}
- #[CoversNothing]
- public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement(): void
+ /**
+ * @coversNothing
+ */
+ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement()
{
$replace = new Replace();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('REPLACE INTO "foo" ("bar", "boo") VALUES (?, NOW())'));
@@ -349,17 +365,17 @@ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareSt
$replace = new Replace();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('REPLACE INTO "sch"."foo" ("bar", "boo") VALUES (?, NOW())'));
@@ -369,8 +385,10 @@ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareSt
$replace->prepareStatement($mockAdapter, $mockStatement);
}
- #[CoversNothing]
- public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString(): void
+ /**
+ * @coversNothing
+ */
+ public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString()
{
$replace = new Replace();
$replace->into('foo')
diff --git a/test/unit/Sql/JoinTest.php b/test/unit/Sql/JoinTest.php
index 55d3f9673..df4b629d3 100644
--- a/test/unit/Sql/JoinTest.php
+++ b/test/unit/Sql/JoinTest.php
@@ -6,32 +6,20 @@
use Laminas\Db\Sql\Join;
use Laminas\Db\Sql\Select;
use LaminasTest\Db\DeprecatedAssertionsTrait;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
-#[CoversMethod(Join::class, 'join')]
-#[CoversMethod(Join::class, 'count')]
-#[CoversMethod(Join::class, 'reset')]
-final class JoinTest extends TestCase
+class JoinTest extends TestCase
{
use DeprecatedAssertionsTrait;
- /**
- * @throws ReflectionException
- */
- public function testInitialPositionIsZero(): void
+ public function testInitialPositionIsZero()
{
$join = new Join();
self::assertAttributeEquals(0, 'position', $join);
}
- /**
- * @throws ReflectionException
- */
- public function testNextIncrementsThePosition(): void
+ public function testNextIncrementsThePosition()
{
$join = new Join();
@@ -40,10 +28,7 @@ public function testNextIncrementsThePosition(): void
self::assertAttributeEquals(1, 'position', $join);
}
- /**
- * @throws ReflectionException
- */
- public function testRewindResetsPositionToZero(): void
+ public function testRewindResetsPositionToZero()
{
$join = new Join();
@@ -55,7 +40,7 @@ public function testRewindResetsPositionToZero(): void
self::assertAttributeEquals(0, 'position', $join);
}
- public function testKeyReturnsTheCurrentPosition(): void
+ public function testKeyReturnsTheCurrentPosition()
{
$join = new Join();
@@ -66,7 +51,7 @@ public function testKeyReturnsTheCurrentPosition(): void
self::assertEquals(3, $join->key());
}
- public function testCurrentReturnsTheCurrentJoinSpecification(): void
+ public function testCurrentReturnsTheCurrentJoinSpecification()
{
$name = 'baz';
$on = 'foo.id = baz.id';
@@ -84,7 +69,7 @@ public function testCurrentReturnsTheCurrentJoinSpecification(): void
self::assertEquals($expectedSpecification, $join->current());
}
- public function testValidReturnsTrueIfTheIteratorIsAtAValidPositionAndFalseIfNot(): void
+ public function testValidReturnsTrueIfTheIteratorIsAtAValidPositionAndFalseIfNot()
{
$join = new Join();
$join->join('baz', 'foo.id = baz.id');
@@ -96,33 +81,39 @@ public function testValidReturnsTrueIfTheIteratorIsAtAValidPositionAndFalseIfNot
self::assertFalse($join->valid());
}
- #[TestDox('unit test: Test join() returns Join object (is chainable)')]
- public function testJoin(): void
+ /**
+ * @testdox unit test: Test join() returns Join object (is chainable)
+ * @covers \Laminas\Db\Sql\Join::join
+ */
+ public function testJoin()
{
$join = new Join();
$return = $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT);
self::assertSame($join, $return);
}
- public function testJoinFullOuter(): void
+ public function testJoinFullOuter()
{
$join = new Join();
$return = $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_FULL_OUTER);
self::assertSame($join, $return);
}
- public function testJoinWillThrowAnExceptionIfNameIsNoValid(): void
+ public function testJoinWillThrowAnExceptionIfNameIsNoValid()
{
$join = new Join();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("join() expects '' as a single element associative array");
- /** @psalm-suppress InvalidArgument */
$join->join([], false);
}
- #[TestDox('unit test: Test count() returns correct count')]
- public function testCount(): void
+ /**
+ * @testdox unit test: Test count() returns correct count
+ * @covers \Laminas\Db\Sql\Join::count
+ * @covers \Laminas\Db\Sql\Join::join
+ */
+ public function testCount()
{
$join = new Join();
$join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT);
@@ -132,8 +123,13 @@ public function testCount(): void
self::assertCount($join->count(), $join->getJoins());
}
- #[TestDox('unit test: Test reset() resets the joins')]
- public function testReset(): void
+ /**
+ * @testdox unit test: Test reset() resets the joins
+ * @covers \Laminas\Db\Sql\Join::count
+ * @covers \Laminas\Db\Sql\Join::join
+ * @covers \Laminas\Db\Sql\Join::reset
+ */
+ public function testReset()
{
$join = new Join();
$join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT);
diff --git a/test/unit/Sql/LiteralTest.php b/test/unit/Sql/LiteralTest.php
index e0e5ad367..a80fd6b02 100644
--- a/test/unit/Sql/LiteralTest.php
+++ b/test/unit/Sql/LiteralTest.php
@@ -5,27 +5,27 @@
use Laminas\Db\Sql\Literal;
use PHPUnit\Framework\TestCase;
-final class LiteralTest extends TestCase
+class LiteralTest extends TestCase
{
- public function testSetLiteral(): void
+ public function testSetLiteral()
{
$literal = new Literal('bar');
self::assertSame($literal, $literal->setLiteral('foo'));
}
- public function testGetLiteral(): void
+ public function testGetLiteral()
{
$literal = new Literal('bar');
self::assertEquals('bar', $literal->getLiteral());
}
- public function testGetExpressionData(): void
+ public function testGetExpressionData()
{
$literal = new Literal('bar');
self::assertEquals([['bar', [], []]], $literal->getExpressionData());
}
- public function testGetExpressionDataWillEscapePercent(): void
+ public function testGetExpressionDataWillEscapePercent()
{
$expression = new Literal('X LIKE "foo%"');
self::assertEquals(
diff --git a/test/unit/Sql/Platform/IbmDb2/SelectDecoratorTest.php b/test/unit/Sql/Platform/IbmDb2/SelectDecoratorTest.php
index 0289c1f58..ca496d99f 100644
--- a/test/unit/Sql/Platform/IbmDb2/SelectDecoratorTest.php
+++ b/test/unit/Sql/Platform/IbmDb2/SelectDecoratorTest.php
@@ -11,32 +11,31 @@
use Laminas\Db\Sql\Platform\IbmDb2\SelectDecorator;
use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Where;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(\Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::class, 'prepareStatement')]
-#[CoversMethod(\Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::class, 'processLimitOffset')]
-#[CoversMethod(SelectDecorator::class, 'getSqlString')]
-final class SelectDecoratorTest extends TestCase
+class SelectDecoratorTest extends TestCase
{
- #[DataProvider('dataProvider')]
- #[TestDox('integration test: Testing SelectDecorator will use Select to produce properly IBM Db2
- dialect prepared sql')]
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select to produce properly IBM Db2
+ * dialect prepared sql
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::prepareStatement
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::processLimitOffset
+ * @dataProvider dataProvider
+ * @param mixed $notUsed
+ */
public function testPrepareStatement(
Select $select,
string $expectedPrepareSql,
array $expectedParams,
- mixed $notUsed,
+ $notUsed,
bool $supportsLimitOffset
- ): void {
+ ) {
$driver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $driver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $driver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
// test
$adapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([
$driver,
new IbmDb2Platform(),
@@ -49,7 +48,7 @@ public function testPrepareStatement(
$statement
->expects($this->any())
->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$statement
->expects($this->once())
->method('setSql')
@@ -63,22 +62,27 @@ public function testPrepareStatement(
self::assertEquals($expectedParams, $parameterContainer->getNamedArray());
}
- #[DataProvider('dataProvider')]
- #[TestDox('integration test: Testing SelectDecorator will use Select to produce properly Ibm DB2
- dialect sql statements')]
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select to produce properly Ibm DB2
+ * dialect sql statements
+ * @covers \Laminas\Db\Sql\Platform\IbmDb2\SelectDecorator::getSqlString
+ * @dataProvider dataProvider
+ * @param mixed $ignored0
+ * @param mixed $ignored1
+ */
public function testGetSqlString(
Select $select,
- mixed $ignored0,
- mixed $ignored1,
+ $ignored0,
+ $ignored1,
string $expectedSql,
bool $supportsLimitOffset
- ): void {
+ ) {
$parameterContainer = new ParameterContainer();
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$statement
->expects($this->any())
->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$selectDecorator = new SelectDecorator();
$selectDecorator->setSubject($select);
@@ -89,8 +93,10 @@ public function testGetSqlString(
/**
* Data provider for testGetSqlString
+ *
+ * @return array
*/
- public static function dataProvider(): array
+ public function dataProvider()
{
// phpcs:disable Generic.Files.LineLength.TooLong
$select0 = new Select();
diff --git a/test/unit/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php b/test/unit/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php
index 352ea2187..645edee4a 100644
--- a/test/unit/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php
+++ b/test/unit/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php
@@ -7,21 +7,24 @@
use Laminas\Db\Sql\Ddl\Column\Column;
use Laminas\Db\Sql\Ddl\Constraint\PrimaryKey;
use Laminas\Db\Sql\Platform\Mysql\Ddl\AlterTableDecorator;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(AlterTableDecorator::class, 'setSubject')]
-#[CoversMethod(AlterTableDecorator::class, 'getSqlString')]
-final class AlterTableDecoratorTest extends TestCase
+class AlterTableDecoratorTest extends TestCase
{
- public function testSetSubject(): void
+ /**
+ * @covers \Laminas\Db\Sql\Platform\Mysql\Ddl\AlterTableDecorator::setSubject
+ */
+ public function testSetSubject()
{
$ctd = new AlterTableDecorator();
$ct = new AlterTable();
self::assertSame($ctd, $ctd->setSubject($ct));
}
- public function testGetSqlString(): void
+ /**
+ * @covers \Laminas\Db\Sql\Platform\Mysql\Ddl\AlterTableDecorator::getSqlString
+ */
+ public function testGetSqlString()
{
$ctd = new AlterTableDecorator();
$ct = new AlterTable('foo');
diff --git a/test/unit/Sql/Platform/Mysql/Ddl/CreateTableDecoratorTest.php b/test/unit/Sql/Platform/Mysql/Ddl/CreateTableDecoratorTest.php
index 3f63e402d..cb4c04e16 100644
--- a/test/unit/Sql/Platform/Mysql/Ddl/CreateTableDecoratorTest.php
+++ b/test/unit/Sql/Platform/Mysql/Ddl/CreateTableDecoratorTest.php
@@ -7,21 +7,24 @@
use Laminas\Db\Sql\Ddl\Constraint\PrimaryKey;
use Laminas\Db\Sql\Ddl\CreateTable;
use Laminas\Db\Sql\Platform\Mysql\Ddl\CreateTableDecorator;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(CreateTableDecorator::class, 'setSubject')]
-#[CoversMethod(CreateTableDecorator::class, 'getSqlString')]
-final class CreateTableDecoratorTest extends TestCase
+class CreateTableDecoratorTest extends TestCase
{
- public function testSetSubject(): void
+ /**
+ * @covers \Laminas\Db\Sql\Platform\Mysql\Ddl\CreateTableDecorator::setSubject
+ */
+ public function testSetSubject()
{
$ctd = new CreateTableDecorator();
$ct = new CreateTable();
self::assertSame($ctd, $ctd->setSubject($ct));
}
- public function testGetSqlString(): void
+ /**
+ * @covers \Laminas\Db\Sql\Platform\Mysql\Ddl\CreateTableDecorator::getSqlString
+ */
+ public function testGetSqlString()
{
$ctd = new CreateTableDecorator();
$ct = new CreateTable('foo');
diff --git a/test/unit/Sql/Platform/Mysql/MysqlTest.php b/test/unit/Sql/Platform/Mysql/MysqlTest.php
index 70c64bde4..14e3ebf6b 100644
--- a/test/unit/Sql/Platform/Mysql/MysqlTest.php
+++ b/test/unit/Sql/Platform/Mysql/MysqlTest.php
@@ -5,18 +5,18 @@
use Laminas\Db\Sql\Platform\Mysql\Mysql;
use Laminas\Db\Sql\Platform\Mysql\SelectDecorator;
use Laminas\Db\Sql\Select;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
use function current;
use function key;
-#[CoversMethod(Mysql::class, '__construct')]
-final class MysqlTest extends TestCase
+class MysqlTest extends TestCase
{
- #[TestDox('unit test / object test: Test Mysql object has Select proxy')]
- public function testConstruct(): void
+ /**
+ * @testdox unit test / object test: Test Mysql object has Select proxy
+ * @covers \Laminas\Db\Sql\Platform\Mysql\Mysql::__construct
+ */
+ public function testConstruct()
{
$mysql = new Mysql();
$decorators = $mysql->getDecorators();
diff --git a/test/unit/Sql/Platform/Mysql/SelectDecoratorTest.php b/test/unit/Sql/Platform/Mysql/SelectDecoratorTest.php
index b48324b1e..41c3aebc1 100644
--- a/test/unit/Sql/Platform/Mysql/SelectDecoratorTest.php
+++ b/test/unit/Sql/Platform/Mysql/SelectDecoratorTest.php
@@ -15,33 +15,32 @@
use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Sql;
use LaminasTest\Db\TestAsset\TrustingMysqlPlatform;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(SelectDecorator::class, 'prepareStatement')]
-#[CoversMethod(SelectDecorator::class, 'processLimit')]
-#[CoversMethod(SelectDecorator::class, 'processOffset')]
-#[CoversMethod(SelectDecorator::class, 'getSqlString')]
-final class SelectDecoratorTest extends TestCase
+class SelectDecoratorTest extends TestCase
{
- protected Adapter&MockObject $mockAdapter;
+ /** @var Adapter&MockObject */
+ protected $mockAdapter;
- protected Sql $sql;
- #[DataProvider('dataProvider')]
-
- #[TestDox('integration test: Testing SelectDecorator will use Select an internal state to prepare
- a proper limit/offset sql statement')]
- public function testPrepareStatement(Select $select, string $expectedSql, array $expectedParams): void
+ /** @var Sql */
+ protected $sql;
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare
+ * a proper limit/offset sql statement
+ * @covers \Laminas\Db\Sql\Platform\Mysql\SelectDecorator::prepareStatement
+ * @covers \Laminas\Db\Sql\Platform\Mysql\SelectDecorator::processLimit
+ * @covers \Laminas\Db\Sql\Platform\Mysql\SelectDecorator::processOffset
+ * @dataProvider dataProvider
+ */
+ public function testPrepareStatement(Select $select, string $expectedSql, array $expectedParams)
{
$driver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $driver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $driver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
// test
$adapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([
$driver,
new MysqlPlatform(),
@@ -51,7 +50,7 @@ public function testPrepareStatement(Select $select, string $expectedSql, array
$parameterContainer = new ParameterContainer();
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$statement->expects($this->any())->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$statement->expects($this->once())->method('setSql')->with($expectedSql);
@@ -62,16 +61,24 @@ public function testPrepareStatement(Select $select, string $expectedSql, array
self::assertEquals($expectedParams, $parameterContainer->getNamedArray());
}
- #[DataProvider('dataProvider')]
- #[TestDox('integration test: Testing SelectDecorator will use Select an internal state to prepare
- a proper limit/offset sql statement')]
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare
+ * a proper limit/offset sql statement
+ * @covers \Laminas\Db\Sql\Platform\Mysql\SelectDecorator::prepareStatement
+ * @covers \Laminas\Db\Sql\Platform\Mysql\SelectDecorator::processLimit
+ * @covers \Laminas\Db\Sql\Platform\Mysql\SelectDecorator::processOffset
+ * @dataProvider dataProvider
+ * @param mixed $ignore
+ * @param array $params
+ * @param mixed $alsoIgnore
+ */
public function testPrepareStatementForSqlObject(
Select $select,
- mixed $ignore,
+ $ignore,
array $expectedParams,
- mixed $alsoIgnore,
+ $alsoIgnore,
string $expectedPdoSql
- ): void {
+ ) {
// mock the adapter, driver, and parts
$newStatement = new Statement();
$driver = new Pdo(new Connection());
@@ -79,8 +86,8 @@ public function testPrepareStatementForSqlObject(
->setConstructorArgs([$driver, new TrustingMysqlPlatform()])
->getMock();
$trustingPlatform = new TrustingMysqlPlatform();
- $mockAdapter->expects($this->any())->method('getPlatform')->willReturn($trustingPlatform);
- $mockAdapter->expects($this->any())->method('getDriver')->willReturn($driver);
+ $mockAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue($trustingPlatform));
+ $mockAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($driver));
// setup mock adapter
$this->mockAdapter = $mockAdapter;
@@ -91,15 +98,22 @@ public function testPrepareStatementForSqlObject(
self::assertEquals($expectedPdoSql, $statement->getSql());
}
- #[DataProvider('dataProvider')]
- #[TestDox('integration test: Testing SelectDecorator will use Select an internal state to prepare
- a proper limit/offset sql statement')]
- public function testGetSqlString(Select $select, mixed $ignore, mixed $alsoIgnore, string $expectedSql): void
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare
+ * a proper limit/offset sql statement
+ * @covers \Laminas\Db\Sql\Platform\Mysql\SelectDecorator::getSqlString
+ * @covers \Laminas\Db\Sql\Platform\Mysql\SelectDecorator::processLimit
+ * @covers \Laminas\Db\Sql\Platform\Mysql\SelectDecorator::processOffset
+ * @dataProvider dataProvider
+ * @param mixed $ignore
+ * @param mixed $alsoIgnore
+ */
+ public function testGetSqlString(Select $select, $ignore, $alsoIgnore, string $expectedSql)
{
$parameterContainer = new ParameterContainer();
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$statement->expects($this->any())->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$selectDecorator = new SelectDecorator();
$selectDecorator->setSubject($select);
@@ -115,7 +129,7 @@ public function testGetSqlString(Select $select, mixed $ignore, mixed $alsoIgnor
* 4: string
* }>
*/
- public static function dataProvider(): array
+ public function dataProvider(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
$select0 = new Select();
diff --git a/test/unit/Sql/Platform/Oracle/OracleTest.php b/test/unit/Sql/Platform/Oracle/OracleTest.php
index 041d909c7..c92932995 100644
--- a/test/unit/Sql/Platform/Oracle/OracleTest.php
+++ b/test/unit/Sql/Platform/Oracle/OracleTest.php
@@ -5,18 +5,18 @@
use Laminas\Db\Sql\Platform\Oracle\Oracle;
use Laminas\Db\Sql\Platform\Oracle\SelectDecorator;
use Laminas\Db\Sql\Select;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
use function current;
use function key;
-#[CoversMethod(Oracle::class, '__construct')]
-final class OracleTest extends TestCase
+class OracleTest extends TestCase
{
- #[TestDox('unit test / object test: Test Mysql object has Select proxy')]
- public function testConstruct(): void
+ /**
+ * @testdox unit test / object test: Test Mysql object has Select proxy
+ * @covers \Laminas\Db\Sql\Platform\Oracle\Oracle::__construct
+ */
+ public function testConstruct()
{
$oracle = new Oracle();
$decorators = $oracle->getDecorators();
diff --git a/test/unit/Sql/Platform/Oracle/SelectDecoratorTest.php b/test/unit/Sql/Platform/Oracle/SelectDecoratorTest.php
index e111e7188..421f7f80d 100644
--- a/test/unit/Sql/Platform/Oracle/SelectDecoratorTest.php
+++ b/test/unit/Sql/Platform/Oracle/SelectDecoratorTest.php
@@ -9,34 +9,33 @@
use Laminas\Db\Adapter\Platform\Oracle as OraclePlatform;
use Laminas\Db\Sql\Platform\Oracle\SelectDecorator;
use Laminas\Db\Sql\Select;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(\Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::class, 'prepareStatement')]
-#[CoversMethod(\Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::class, 'processLimitOffset')]
-#[CoversMethod(SelectDecorator::class, 'getSqlString')]
-final class SelectDecoratorTest extends TestCase
+class SelectDecoratorTest extends TestCase
{
- #[DataProvider('dataProvider')]
- #[TestDox('integration test: Testing SelectDecorator will use Select to produce properly Oracle
- dialect prepared sql')]
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select to produce properly Oracle
+ * dialect prepared sql
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::prepareStatement
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::processLimitOffset
+ * @dataProvider dataProvider
+ * @param mixed $notUsed
+ */
public function testPrepareStatement(
Select $select,
string $expectedSql,
array $expectedParams,
- mixed $notUsed,
+ $notUsed,
int $expectedFormatParamCount
- ): void {
+ ) {
$driver = $this->getMockBuilder(DriverInterface::class)->getMock();
$driver->expects($this->exactly($expectedFormatParamCount))
->method('formatParameterName')
- ->willReturn('?');
+ ->will($this->returnValue('?'));
// test
$adapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([
$driver,
new OraclePlatform(),
@@ -47,7 +46,7 @@ public function testPrepareStatement(
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$statement->expects($this->any())
->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$statement->expects($this->once())->method('setSql')->with($expectedSql);
@@ -58,16 +57,21 @@ public function testPrepareStatement(
self::assertEquals($expectedParams, $parameterContainer->getNamedArray());
}
- #[DataProvider('dataProvider')]
- #[TestDox('integration test: Testing SelectDecorator will use Select to produce properly Oracle
- dialect sql statements')]
- public function testGetSqlString(Select $select, mixed $ignored, mixed $alsoIgnored, string $expectedSql): void
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select to produce properly Oracle
+ * dialect sql statements
+ * @covers \Laminas\Db\Sql\Platform\Oracle\SelectDecorator::getSqlString
+ * @dataProvider dataProvider
+ * @param mixed $ignored
+ * @param mixed $alsoIgnored
+ */
+ public function testGetSqlString(Select $select, $ignored, $alsoIgnored, string $expectedSql)
{
$parameterContainer = new ParameterContainer();
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$statement->expects($this->any())
->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$selectDecorator = new SelectDecorator();
$selectDecorator->setSubject($select);
@@ -85,7 +89,7 @@ public function testGetSqlString(Select $select, mixed $ignored, mixed $alsoIgno
* 4: int
* }>
*/
- public static function dataProvider(): array
+ public function dataProvider(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong,WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCaps
$select0 = new Select();
diff --git a/test/unit/Sql/Platform/PlatformTest.php b/test/unit/Sql/Platform/PlatformTest.php
index 94b03451c..bc3c5940f 100644
--- a/test/unit/Sql/Platform/PlatformTest.php
+++ b/test/unit/Sql/Platform/PlatformTest.php
@@ -8,41 +8,31 @@
use Laminas\Db\Sql\Exception\RuntimeException;
use Laminas\Db\Sql\Platform\Platform;
use LaminasTest\Db\TestAsset;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
-final class PlatformTest extends TestCase
+class PlatformTest extends TestCase
{
- /**
- * @throws ReflectionException
- */
- public function testResolveDefaultPlatform(): void
+ public function testResolveDefaultPlatform()
{
$adapter = $this->resolveAdapter('sql92');
$platform = new Platform($adapter);
$reflectionMethod = new ReflectionMethod($platform, 'resolvePlatform');
- /** @psalm-suppress UnusedMethodCall */
$reflectionMethod->setAccessible(true);
self::assertEquals($adapter->getPlatform(), $reflectionMethod->invoke($platform, null));
}
- /**
- * @throws ReflectionException
- */
- public function testResolvePlatformName(): void
+ public function testResolvePlatformName()
{
$platform = new Platform($this->resolveAdapter('sql92'));
$reflectionMethod = new ReflectionMethod($platform, 'resolvePlatformName');
- /** @psalm-suppress UnusedMethodCall */
$reflectionMethod->setAccessible(true);
self::assertEquals('mysql', $reflectionMethod->invoke($platform, new TestAsset\TrustingMysqlPlatform()));
@@ -55,20 +45,18 @@ public function testResolvePlatformName(): void
}
/**
- * @throws ReflectionException
+ * @group 6890
*/
- #[Group('6890')]
- public function testAbstractPlatformCrashesGracefullyOnMissingDefaultPlatform(): void
+ public function testAbstractPlatformCrashesGracefullyOnMissingDefaultPlatform()
{
$adapter = $this->resolveAdapter('sql92');
$reflectionProperty = new ReflectionProperty($adapter, 'platform');
- /** @psalm-suppress UnusedMethodCall */
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($adapter, null);
$platform = new Platform($adapter);
$reflectionMethod = new ReflectionMethod($platform, 'resolvePlatform');
- /** @psalm-suppress UnusedMethodCall */
+
$reflectionMethod->setAccessible(true);
$this->expectException(RuntimeException::class);
@@ -78,20 +66,18 @@ public function testAbstractPlatformCrashesGracefullyOnMissingDefaultPlatform():
}
/**
- * @throws ReflectionException
+ * @group 6890
*/
- #[Group('6890')]
- public function testAbstractPlatformCrashesGracefullyOnMissingDefaultPlatformWithGetDecorators(): void
+ public function testAbstractPlatformCrashesGracefullyOnMissingDefaultPlatformWithGetDecorators()
{
$adapter = $this->resolveAdapter('sql92');
$reflectionProperty = new ReflectionProperty($adapter, 'platform');
- /** @psalm-suppress UnusedMethodCall */
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($adapter, null);
$platform = new Platform($adapter);
$reflectionMethod = new ReflectionMethod($platform, 'resolvePlatform');
- /** @psalm-suppress UnusedMethodCall */
+
$reflectionMethod->setAccessible(true);
$this->expectException(RuntimeException::class);
@@ -100,7 +86,11 @@ public function testAbstractPlatformCrashesGracefullyOnMissingDefaultPlatformWit
$platform->getDecorators();
}
- protected function resolveAdapter(string $platformName): Adapter
+ /**
+ * @param string $platformName
+ * @return Adapter
+ */
+ protected function resolveAdapter($platformName)
{
$platform = null;
@@ -122,8 +112,10 @@ protected function resolveAdapter(string $platformName): Adapter
/** @var DriverInterface|MockObject $mockDriver */
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
- $mockDriver->expects($this->any())->method('createStatement')->willReturnCallback(fn() => new StatementContainer());
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnCallback(function () {
+ return new StatementContainer();
+ }));
return new Adapter($mockDriver, $platform);
}
diff --git a/test/unit/Sql/Platform/SqlServer/Ddl/CreateTableDecoratorTest.php b/test/unit/Sql/Platform/SqlServer/Ddl/CreateTableDecoratorTest.php
index ffe15f169..cc125d10c 100644
--- a/test/unit/Sql/Platform/SqlServer/Ddl/CreateTableDecoratorTest.php
+++ b/test/unit/Sql/Platform/SqlServer/Ddl/CreateTableDecoratorTest.php
@@ -5,13 +5,14 @@
use Laminas\Db\Sql\Ddl\Column\Column;
use Laminas\Db\Sql\Ddl\CreateTable;
use Laminas\Db\Sql\Platform\SqlServer\Ddl\CreateTableDecorator;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(CreateTableDecorator::class, 'getSqlString')]
-final class CreateTableDecoratorTest extends TestCase
+class CreateTableDecoratorTest extends TestCase
{
- public function testGetSqlString(): void
+ /**
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\Ddl\CreateTableDecorator::getSqlString
+ */
+ public function testGetSqlString()
{
$ctd = new CreateTableDecorator();
diff --git a/test/unit/Sql/Platform/SqlServer/SelectDecoratorTest.php b/test/unit/Sql/Platform/SqlServer/SelectDecoratorTest.php
index 31271a8cc..a9f42fa8f 100644
--- a/test/unit/Sql/Platform/SqlServer/SelectDecoratorTest.php
+++ b/test/unit/Sql/Platform/SqlServer/SelectDecoratorTest.php
@@ -10,36 +10,33 @@
use Laminas\Db\Sql\Expression;
use Laminas\Db\Sql\Platform\SqlServer\SelectDecorator;
use Laminas\Db\Sql\Select;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(SelectDecorator::class, 'prepareStatement')]
-#[CoversMethod(SelectDecorator::class, 'processLimitOffset')]
-#[CoversMethod(SelectDecorator::class, 'getSqlString')]
-final class SelectDecoratorTest extends TestCase
+class SelectDecoratorTest extends TestCase
{
/**
+ * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare
+ * a proper limit/offset sql statement
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::prepareStatement
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::processLimitOffset
+ * @dataProvider dataProvider
* @param array $expectedParams
+ * @param mixed $notUsed
*/
- #[DataProvider('dataProvider')]
- #[TestDox('integration test: Testing SelectDecorator will use Select an internal state to prepare
- a proper limit/offset sql statement')]
public function testPrepareStatement(
Select $select,
string $expectedSql,
array $expectedParams,
- mixed $notUsed,
+ $notUsed,
int $expectedFormatParamCount
- ): void {
+ ) {
$driver = $this->getMockBuilder(DriverInterface::class)->getMock();
$driver->expects($this->exactly($expectedFormatParamCount))->method('formatParameterName')
- ->willReturn('?');
+ ->will($this->returnValue('?'));
// test
$adapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([
$driver,
new SqlServerPlatform(),
@@ -49,7 +46,7 @@ public function testPrepareStatement(
$parameterContainer = new ParameterContainer();
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$statement->expects($this->any())->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$statement->expects($this->once())->method('setSql')->with($expectedSql);
@@ -60,15 +57,21 @@ public function testPrepareStatement(
self::assertEquals($expectedParams, $parameterContainer->getNamedArray());
}
- #[DataProvider('dataProvider')]
- #[TestDox('integration test: Testing SelectDecorator will use Select an internal state to prepare
- a proper limit/offset sql statement')]
- public function testGetSqlString(Select $select, mixed $ignored, mixed $alsoIgnored, string $expectedSql): void
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare
+ * a proper limit/offset sql statement
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::getSqlString
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\SelectDecorator::processLimitOffset
+ * @dataProvider dataProvider
+ * @param mixed $ignored
+ * @param mixed $alsoIgnored
+ */
+ public function testGetSqlString(Select $select, $ignored, $alsoIgnored, string $expectedSql)
{
$parameterContainer = new ParameterContainer();
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$statement->expects($this->any())->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$selectDecorator = new SelectDecorator();
$selectDecorator->setSubject($select);
@@ -76,7 +79,7 @@ public function testGetSqlString(Select $select, mixed $ignored, mixed $alsoIgno
}
/** @psalm-return array, 3: string, 4: int}> */
- public static function dataProvider(): array
+ public function dataProvider(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
$select0 = new Select();
diff --git a/test/unit/Sql/Platform/SqlServer/SqlServerTest.php b/test/unit/Sql/Platform/SqlServer/SqlServerTest.php
index 08df6dad1..845e24d06 100644
--- a/test/unit/Sql/Platform/SqlServer/SqlServerTest.php
+++ b/test/unit/Sql/Platform/SqlServer/SqlServerTest.php
@@ -5,18 +5,18 @@
use Laminas\Db\Sql\Platform\SqlServer\SelectDecorator;
use Laminas\Db\Sql\Platform\SqlServer\SqlServer;
use Laminas\Db\Sql\Select;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
use function current;
use function key;
-#[CoversMethod(SqlServer::class, '__construct')]
-final class SqlServerTest extends TestCase
+class SqlServerTest extends TestCase
{
- #[TestDox('unit test / object test: Test SqlServer object has Select proxy')]
- public function testConstruct(): void
+ /**
+ * @testdox unit test / object test: Test SqlServer object has Select proxy
+ * @covers \Laminas\Db\Sql\Platform\SqlServer\SqlServer::__construct
+ */
+ public function testConstruct()
{
$sqlServer = new SqlServer();
$decorators = $sqlServer->getDecorators();
diff --git a/test/unit/Sql/Platform/Sqlite/SelectDecoratorTest.php b/test/unit/Sql/Platform/Sqlite/SelectDecoratorTest.php
index f53140732..b909950e8 100644
--- a/test/unit/Sql/Platform/Sqlite/SelectDecoratorTest.php
+++ b/test/unit/Sql/Platform/Sqlite/SelectDecoratorTest.php
@@ -10,30 +10,28 @@
use Laminas\Db\Sql\Expression;
use Laminas\Db\Sql\Platform\Sqlite\SelectDecorator;
use Laminas\Db\Sql\Select;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(SelectDecorator::class, 'prepareStatement')]
-#[CoversMethod(SelectDecorator::class, 'processCombine')]
-#[CoversMethod(SelectDecorator::class, 'getSqlString')]
-final class SelectDecoratorTest extends TestCase
+class SelectDecoratorTest extends TestCase
{
- #[DataProvider('dataProviderUnionSyntaxFromCombine')]
- #[TestDox('integration test: Testing SelectDecorator will use Select an internal state to prepare a proper combine
-statement')]
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare a proper combine
+ * statement
+ * @covers \Laminas\Db\Sql\Platform\Sqlite\SelectDecorator::prepareStatement
+ * @covers \Laminas\Db\Sql\Platform\Sqlite\SelectDecorator::processCombine
+ * @dataProvider dataProviderUnionSyntaxFromCombine
+ */
public function testPrepareStatementPreparesUnionSyntaxFromCombine(
Select $select,
string $expectedSql,
array $expectedParams
- ): void {
+ ) {
$driver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $driver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $driver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
// test
$adapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([
$driver,
new SqlitePlatform(),
@@ -43,7 +41,7 @@ public function testPrepareStatementPreparesUnionSyntaxFromCombine(
$parameterContainer = new ParameterContainer();
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$statement->expects($this->any())->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$statement->expects($this->once())->method('setSql')->with($expectedSql);
@@ -54,19 +52,25 @@ public function testPrepareStatementPreparesUnionSyntaxFromCombine(
self::assertEquals($expectedParams, $parameterContainer->getNamedArray());
}
- #[DataProvider('dataProviderUnionSyntaxFromCombine')]
- #[TestDox('integration test: Testing SelectDecorator will use Select an internal state to prepare a proper combine
-statement')]
+ /**
+ * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare a proper combine
+ * statement
+ * @covers \Laminas\Db\Sql\Platform\Sqlite\SelectDecorator::getSqlString
+ * @covers \Laminas\Db\Sql\Platform\Sqlite\SelectDecorator::processCombine
+ * @dataProvider dataProviderUnionSyntaxFromCombine
+ * @param mixed $ignore
+ * @param mixed $alsoIgnore
+ */
public function testGetSqlStringPreparesUnionSyntaxFromCombine(
Select $select,
- mixed $ignore,
- mixed $alsoIgnore,
+ $ignore,
+ $alsoIgnore,
string $expectedSql
- ): void {
+ ) {
$parameterContainer = new ParameterContainer();
$statement = $this->getMockBuilder(StatementInterface::class)->getMock();
$statement->expects($this->any())->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$selectDecorator = new SelectDecorator();
$selectDecorator->setSubject($select);
@@ -83,7 +87,7 @@ public function testGetSqlStringPreparesUnionSyntaxFromCombine(
* 3: string
* }>
*/
- public static function dataProviderUnionSyntaxFromCombine(): array
+ public function dataProviderUnionSyntaxFromCombine(): array
{
$select0 = new Select();
$select0->from('foo');
diff --git a/test/unit/Sql/Platform/Sqlite/SqliteTest.php b/test/unit/Sql/Platform/Sqlite/SqliteTest.php
index 688c21821..c8ef75ea3 100644
--- a/test/unit/Sql/Platform/Sqlite/SqliteTest.php
+++ b/test/unit/Sql/Platform/Sqlite/SqliteTest.php
@@ -5,18 +5,18 @@
use Laminas\Db\Sql\Platform\Sqlite\SelectDecorator;
use Laminas\Db\Sql\Platform\Sqlite\Sqlite;
use Laminas\Db\Sql\Select;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
use function current;
use function key;
-#[CoversMethod(Sqlite::class, '__construct')]
-final class SqliteTest extends TestCase
+class SqliteTest extends TestCase
{
- #[TestDox('unit test / object test: Test Sqlite constructor will register the decorator')]
- public function testConstructorRegistersSqliteDecorator(): void
+ /**
+ * @testdox unit test / object test: Test Sqlite constructor will register the decorator
+ * @covers \Laminas\Db\Sql\Platform\Sqlite\Sqlite::__construct
+ */
+ public function testConstructorRegistersSqliteDecorator()
{
$mysql = new Sqlite();
$decorators = $mysql->getDecorators();
diff --git a/test/unit/Sql/Predicate/BetweenTest.php b/test/unit/Sql/Predicate/BetweenTest.php
index 88c8500b5..900c6c690 100644
--- a/test/unit/Sql/Predicate/BetweenTest.php
+++ b/test/unit/Sql/Predicate/BetweenTest.php
@@ -3,38 +3,38 @@
namespace LaminasTest\Db\Sql\Predicate;
use Laminas\Db\Sql\Predicate\Between;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(Between::class, '__construct')]
-#[CoversMethod(Between::class, 'getIdentifier')]
-#[CoversMethod(Between::class, 'getMinValue')]
-#[CoversMethod(Between::class, 'getMaxValue')]
-#[CoversMethod(Between::class, 'getSpecification')]
-#[CoversMethod(Between::class, 'setIdentifier')]
-#[CoversMethod(Between::class, 'setMinValue')]
-#[CoversMethod(Between::class, 'setMaxValue')]
-#[CoversMethod(Between::class, 'setSpecification')]
-#[CoversMethod(Between::class, 'getExpressionData')]
-final class BetweenTest extends TestCase
+class BetweenTest extends TestCase
{
- protected Between $between;
+ /** @var Between */
+ protected $between;
- #[Override]
protected function setUp(): void
{
$this->between = new Between();
}
- public function testConstructorYieldsNullIdentifierMinimumAndMaximumValues(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\Between::__construct
+ * @covers \Laminas\Db\Sql\Predicate\Between::getIdentifier
+ * @covers \Laminas\Db\Sql\Predicate\Between::getMinValue
+ * @covers \Laminas\Db\Sql\Predicate\Between::getMaxValue
+ */
+ public function testConstructorYieldsNullIdentifierMinimumAndMaximumValues()
{
self::assertNull($this->between->getIdentifier());
self::assertNull($this->between->getMinValue());
self::assertNull($this->between->getMaxValue());
}
- public function testConstructorCanPassIdentifierMinimumAndMaximumValues(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\Between::__construct
+ * @covers \Laminas\Db\Sql\Predicate\Between::getIdentifier
+ * @covers \Laminas\Db\Sql\Predicate\Between::getMinValue
+ * @covers \Laminas\Db\Sql\Predicate\Between::getMaxValue
+ */
+ public function testConstructorCanPassIdentifierMinimumAndMaximumValues()
{
$between = new Between('foo.bar', 1, 300);
self::assertEquals('foo.bar', $between->getIdentifier());
@@ -52,36 +52,58 @@ public function testConstructorCanPassIdentifierMinimumAndMaximumValues(): void
self::assertSame(0, $between->getMaxValue());
}
- public function testSpecificationHasSaneDefaultValue(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\Between::getSpecification
+ */
+ public function testSpecificationHasSaneDefaultValue()
{
self::assertEquals('%1$s BETWEEN %2$s AND %3$s', $this->between->getSpecification());
}
- public function testIdentifierIsMutable(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\Between::setIdentifier
+ * @covers \Laminas\Db\Sql\Predicate\Between::getIdentifier
+ */
+ public function testIdentifierIsMutable()
{
$this->between->setIdentifier('foo.bar');
self::assertEquals('foo.bar', $this->between->getIdentifier());
}
- public function testMinValueIsMutable(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\Between::setMinValue
+ * @covers \Laminas\Db\Sql\Predicate\Between::getMinValue
+ */
+ public function testMinValueIsMutable()
{
$this->between->setMinValue(10);
self::assertEquals(10, $this->between->getMinValue());
}
- public function testMaxValueIsMutable(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\Between::setMaxValue
+ * @covers \Laminas\Db\Sql\Predicate\Between::getMaxValue
+ */
+ public function testMaxValueIsMutable()
{
$this->between->setMaxValue(10);
self::assertEquals(10, $this->between->getMaxValue());
}
- public function testSpecificationIsMutable(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\Between::setSpecification
+ * @covers \Laminas\Db\Sql\Predicate\Between::getSpecification
+ */
+ public function testSpecificationIsMutable()
{
$this->between->setSpecification('%1$s IS INBETWEEN %2$s AND %3$s');
self::assertEquals('%1$s IS INBETWEEN %2$s AND %3$s', $this->between->getSpecification());
}
- public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\Between::getExpressionData
+ */
+ public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes()
{
$this->between->setIdentifier('foo.bar')
->setMinValue(10)
diff --git a/test/unit/Sql/Predicate/ExpressionTest.php b/test/unit/Sql/Predicate/ExpressionTest.php
index 5acd9ed95..63ea71ed9 100644
--- a/test/unit/Sql/Predicate/ExpressionTest.php
+++ b/test/unit/Sql/Predicate/ExpressionTest.php
@@ -4,138 +4,165 @@
use Laminas\Db\Sql\Predicate\Expression;
use Laminas\Db\Sql\Predicate\IsNull;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use function var_export;
-final class ExpressionTest extends TestCase
+class ExpressionTest extends TestCase
{
- public function testEmptyConstructorYieldsEmptyLiteralAndParameter(): void
+ public function testEmptyConstructorYieldsEmptyLiteralAndParameter()
{
$expression = new Expression();
self::assertEquals('', $expression->getExpression());
self::assertEmpty($expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassLiteralAndSingleScalarParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassLiteralAndSingleScalarParameterToConstructor()
{
$expression = new Expression('foo.bar = ?', 'bar');
self::assertEquals('foo.bar = ?', $expression->getExpression());
self::assertEquals(['bar'], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassNoParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassNoParameterToConstructor()
{
$expression = new Expression('foo.bar');
self::assertEquals([], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassSingleNullParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassSingleNullParameterToConstructor()
{
$expression = new Expression('?', null);
self::assertEquals([null], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassSingleZeroParameterValueToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassSingleZeroParameterValueToConstructor()
{
$predicate = new Expression('?', 0);
self::assertEquals([0], $predicate->getParameters());
}
- #[Group('6849')]
- public function testCanPassSinglePredicateParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassSinglePredicateParameterToConstructor()
{
$predicate = new IsNull('foo.baz');
$expression = new Expression('?', $predicate);
self::assertEquals([$predicate], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassMultiScalarParametersToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassMultiScalarParametersToConstructor()
{
$expression = new Expression('? OR ?', 'foo', 'bar');
self::assertEquals(['foo', 'bar'], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassMultiNullParametersToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassMultiNullParametersToConstructor()
{
$expression = new Expression('? OR ?', null, null);
self::assertEquals([null, null], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassMultiPredicateParametersToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassMultiPredicateParametersToConstructor()
{
$predicate = new IsNull('foo.baz');
$expression = new Expression('? OR ?', $predicate, $predicate);
self::assertEquals([$predicate, $predicate], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassArrayOfOneScalarParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassArrayOfOneScalarParameterToConstructor()
{
$expression = new Expression('?', ['foo']);
self::assertEquals(['foo'], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassArrayOfMultiScalarsParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassArrayOfMultiScalarsParameterToConstructor()
{
$expression = new Expression('? OR ?', ['foo', 'bar']);
self::assertEquals(['foo', 'bar'], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassArrayOfOneNullParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassArrayOfOneNullParameterToConstructor()
{
$expression = new Expression('?', [null]);
self::assertEquals([null], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassArrayOfMultiNullsParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassArrayOfMultiNullsParameterToConstructor()
{
$expression = new Expression('? OR ?', [null, null]);
self::assertEquals([null, null], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassArrayOfOnePredicateParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassArrayOfOnePredicateParameterToConstructor()
{
$predicate = new IsNull('foo.baz');
$expression = new Expression('?', [$predicate]);
self::assertEquals([$predicate], $expression->getParameters());
}
- #[Group('6849')]
- public function testCanPassArrayOfMultiPredicatesParameterToConstructor(): void
+ /**
+ * @group 6849
+ */
+ public function testCanPassArrayOfMultiPredicatesParameterToConstructor()
{
$predicate = new IsNull('foo.baz');
$expression = new Expression('? OR ?', [$predicate, $predicate]);
self::assertEquals([$predicate, $predicate], $expression->getParameters());
}
- public function testLiteralIsMutable(): void
+ public function testLiteralIsMutable()
{
$expression = new Expression();
$expression->setExpression('foo.bar = ?');
self::assertEquals('foo.bar = ?', $expression->getExpression());
}
- public function testParameterIsMutable(): void
+ public function testParameterIsMutable()
{
$expression = new Expression();
$expression->setParameters(['foo', 'bar']);
self::assertEquals(['foo', 'bar'], $expression->getParameters());
}
- public function testRetrievingWherePartsReturnsSpecificationArrayOfLiteralAndParametersAndArrayOfTypes(): void
+ public function testRetrievingWherePartsReturnsSpecificationArrayOfLiteralAndParametersAndArrayOfTypes()
{
$expression = new Expression();
$expression->setExpression('foo.bar = ? AND id != ?')
@@ -148,6 +175,6 @@ public function testRetrievingWherePartsReturnsSpecificationArrayOfLiteralAndPar
],
];
$test = $expression->getExpressionData();
- self::assertEquals($expected, $test, var_export($test, true));
+ self::assertEquals($expected, $test, var_export($test, 1));
}
}
diff --git a/test/unit/Sql/Predicate/InTest.php b/test/unit/Sql/Predicate/InTest.php
index dc10b1c4e..ce5d3d57a 100644
--- a/test/unit/Sql/Predicate/InTest.php
+++ b/test/unit/Sql/Predicate/InTest.php
@@ -6,44 +6,44 @@
use Laminas\Db\Sql\Select;
use PHPUnit\Framework\TestCase;
-final class InTest extends TestCase
+class InTest extends TestCase
{
- public function testEmptyConstructorYieldsNullIdentifierAndValueSet(): void
+ public function testEmptyConstructorYieldsNullIdentifierAndValueSet()
{
$in = new In();
self::assertNull($in->getIdentifier());
self::assertNull($in->getValueSet());
}
- public function testCanPassIdentifierAndValueSetToConstructor(): void
+ public function testCanPassIdentifierAndValueSetToConstructor()
{
$in = new In('foo.bar', [1, 2]);
self::assertEquals('foo.bar', $in->getIdentifier());
self::assertEquals([1, 2], $in->getValueSet());
}
- public function testCanPassIdentifierAndEmptyValueSetToConstructor(): void
+ public function testCanPassIdentifierAndEmptyValueSetToConstructor()
{
$in = new In('foo.bar', []);
$this->assertEquals('foo.bar', $in->getIdentifier());
$this->assertEquals([], $in->getValueSet());
}
- public function testIdentifierIsMutable(): void
+ public function testIdentifierIsMutable()
{
$in = new In();
$in->setIdentifier('foo.bar');
self::assertEquals('foo.bar', $in->getIdentifier());
}
- public function testValueSetIsMutable(): void
+ public function testValueSetIsMutable()
{
$in = new In();
$in->setValueSet([1, 2]);
self::assertEquals([1, 2], $in->getValueSet());
}
- public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes(): void
+ public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes()
{
$in = new In();
$in->setIdentifier('foo.bar')
@@ -70,11 +70,11 @@ public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAnd
[In::TYPE_IDENTIFIER, In::TYPE_LITERAL, In::TYPE_VALUE, In::TYPE_LITERAL],
],
];
- $in->getExpressionData();
+ $qqq = $in->getExpressionData();
self::assertEquals($expected, $in->getExpressionData());
}
- public function testGetExpressionDataWithSubselect(): void
+ public function testGetExpressionDataWithSubselect()
{
$select = new Select();
$in = new In('foo', $select);
@@ -88,9 +88,9 @@ public function testGetExpressionDataWithSubselect(): void
self::assertEquals($expected, $in->getExpressionData());
}
- public function testGetExpressionDataWithEmptyValues(): void
+ public function testGetExpressionDataWithEmptyValues()
{
- new Select();
+ $select = new Select();
$in = new In('foo', []);
$expected = [
[
@@ -102,7 +102,7 @@ public function testGetExpressionDataWithEmptyValues(): void
$this->assertEquals($expected, $in->getExpressionData());
}
- public function testGetExpressionDataWithSubselectAndIdentifier(): void
+ public function testGetExpressionDataWithSubselectAndIdentifier()
{
$select = new Select();
$in = new In('foo', $select);
@@ -116,7 +116,7 @@ public function testGetExpressionDataWithSubselectAndIdentifier(): void
self::assertEquals($expected, $in->getExpressionData());
}
- public function testGetExpressionDataWithSubselectAndArrayIdentifier(): void
+ public function testGetExpressionDataWithSubselectAndArrayIdentifier()
{
$select = new Select();
$in = new In(['foo', 'bar'], $select);
diff --git a/test/unit/Sql/Predicate/IsNullTest.php b/test/unit/Sql/Predicate/IsNullTest.php
index c456add07..9899c2b31 100644
--- a/test/unit/Sql/Predicate/IsNullTest.php
+++ b/test/unit/Sql/Predicate/IsNullTest.php
@@ -5,42 +5,42 @@
use Laminas\Db\Sql\Predicate\IsNotNull;
use PHPUnit\Framework\TestCase;
-final class IsNullTest extends TestCase
+class IsNullTest extends TestCase
{
- public function testEmptyConstructorYieldsNullIdentifier(): void
+ public function testEmptyConstructorYieldsNullIdentifier()
{
$isNotNull = new IsNotNull();
self::assertNull($isNotNull->getIdentifier());
}
- public function testSpecificationHasSaneDefaultValue(): void
+ public function testSpecificationHasSaneDefaultValue()
{
$isNotNull = new IsNotNull();
self::assertEquals('%1$s IS NOT NULL', $isNotNull->getSpecification());
}
- public function testCanPassIdentifierToConstructor(): void
+ public function testCanPassIdentifierToConstructor()
{
- new IsNotNull();
- $isnull = new IsNotNull('foo.bar');
+ $isNotNull = new IsNotNull();
+ $isnull = new IsNotNull('foo.bar');
self::assertEquals('foo.bar', $isnull->getIdentifier());
}
- public function testIdentifierIsMutable(): void
+ public function testIdentifierIsMutable()
{
$isNotNull = new IsNotNull();
$isNotNull->setIdentifier('foo.bar');
self::assertEquals('foo.bar', $isNotNull->getIdentifier());
}
- public function testSpecificationIsMutable(): void
+ public function testSpecificationIsMutable()
{
$isNotNull = new IsNotNull();
$isNotNull->setSpecification('%1$s NOT NULL');
self::assertEquals('%1$s NOT NULL', $isNotNull->getSpecification());
}
- public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndArrayOfTypes(): void
+ public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndArrayOfTypes()
{
$isNotNull = new IsNotNull();
$isNotNull->setIdentifier('foo.bar');
diff --git a/test/unit/Sql/Predicate/LikeTest.php b/test/unit/Sql/Predicate/LikeTest.php
index 86226f159..7b2ccc6af 100644
--- a/test/unit/Sql/Predicate/LikeTest.php
+++ b/test/unit/Sql/Predicate/LikeTest.php
@@ -5,23 +5,23 @@
use Laminas\Db\Sql\Predicate\Like;
use PHPUnit\Framework\TestCase;
-final class LikeTest extends TestCase
+class LikeTest extends TestCase
{
- public function testConstructEmptyArgs(): void
+ public function testConstructEmptyArgs()
{
$like = new Like();
self::assertEquals('', $like->getIdentifier());
self::assertEquals('', $like->getLike());
}
- public function testConstructWithArgs(): void
+ public function testConstructWithArgs()
{
$like = new Like('bar', 'Foo%');
self::assertEquals('bar', $like->getIdentifier());
self::assertEquals('Foo%', $like->getLike());
}
- public function testAccessorsMutators(): void
+ public function testAccessorsMutators()
{
$like = new Like();
$like->setIdentifier('bar');
@@ -32,7 +32,7 @@ public function testAccessorsMutators(): void
self::assertEquals('target = target', $like->getSpecification());
}
- public function testGetExpressionData(): void
+ public function testGetExpressionData()
{
$like = new Like('bar', 'Foo%');
self::assertEquals(
@@ -51,7 +51,7 @@ public function testGetExpressionData(): void
);
}
- public function testInstanceOfPerSetters(): void
+ public function testInstanceOfPerSetters()
{
$like = new Like();
self::assertInstanceOf(Like::class, $like->setIdentifier('bar'));
diff --git a/test/unit/Sql/Predicate/LiteralTest.php b/test/unit/Sql/Predicate/LiteralTest.php
index b18c780dd..7a1d2ee4d 100644
--- a/test/unit/Sql/Predicate/LiteralTest.php
+++ b/test/unit/Sql/Predicate/LiteralTest.php
@@ -5,21 +5,21 @@
use Laminas\Db\Sql\Predicate\Literal;
use PHPUnit\Framework\TestCase;
-final class LiteralTest extends TestCase
+class LiteralTest extends TestCase
{
- public function testSetLiteral(): void
+ public function testSetLiteral()
{
$literal = new Literal('bar');
self::assertSame($literal, $literal->setLiteral('foo'));
}
- public function testGetLiteral(): void
+ public function testGetLiteral()
{
$literal = new Literal('bar');
self::assertEquals('bar', $literal->getLiteral());
}
- public function testGetExpressionData(): void
+ public function testGetExpressionData()
{
$literal = new Literal('bar');
self::assertEquals([['bar', [], []]], $literal->getExpressionData());
diff --git a/test/unit/Sql/Predicate/NotBetweenTest.php b/test/unit/Sql/Predicate/NotBetweenTest.php
index 5040a65a1..2f39f194e 100644
--- a/test/unit/Sql/Predicate/NotBetweenTest.php
+++ b/test/unit/Sql/Predicate/NotBetweenTest.php
@@ -2,30 +2,31 @@
namespace LaminasTest\Db\Sql\Predicate;
-use Laminas\Db\Sql\ExpressionInterface;
use Laminas\Db\Sql\Predicate\NotBetween;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-#[CoversMethod(NotBetween::class, 'getSpecification')]
-#[CoversMethod(NotBetween::class, 'getExpressionData')]
-final class NotBetweenTest extends TestCase
+class NotBetweenTest extends TestCase
{
- protected NotBetween $notBetween;
+ /** @var NotBetween */
+ protected $notBetween;
- #[Override]
protected function setUp(): void
{
$this->notBetween = new NotBetween();
}
- public function testSpecificationHasSameDefaultValue(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\NotBetween::getSpecification
+ */
+ public function testSpecificationHasSameDefaultValue()
{
self::assertEquals('%1$s NOT BETWEEN %2$s AND %3$s', $this->notBetween->getSpecification());
}
- public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes(): void
+ /**
+ * @covers \Laminas\Db\Sql\Predicate\NotBetween::getExpressionData
+ */
+ public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes()
{
$this->notBetween->setIdentifier('foo.bar')
->setMinValue(10)
@@ -34,20 +35,19 @@ public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAnd
[
$this->notBetween->getSpecification(),
['foo.bar', 10, 19],
- [ExpressionInterface::TYPE_IDENTIFIER, ExpressionInterface::TYPE_VALUE, ExpressionInterface::TYPE_VALUE],
+ [NotBetween::TYPE_IDENTIFIER, NotBetween::TYPE_VALUE, NotBetween::TYPE_VALUE],
],
];
self::assertEquals($expected, $this->notBetween->getExpressionData());
- $this->notBetween
- ->setIdentifier(10)
- ->setMinValue(['foo.bar' => ExpressionInterface::TYPE_IDENTIFIER])
- ->setMaxValue(['foo.baz' => ExpressionInterface::TYPE_IDENTIFIER]);
+ $this->notBetween->setIdentifier([10 => NotBetween::TYPE_VALUE])
+ ->setMinValue(['foo.bar' => NotBetween::TYPE_IDENTIFIER])
+ ->setMaxValue(['foo.baz' => NotBetween::TYPE_IDENTIFIER]);
$expected = [
[
$this->notBetween->getSpecification(),
[10, 'foo.bar', 'foo.baz'],
- [ExpressionInterface::TYPE_VALUE, ExpressionInterface::TYPE_IDENTIFIER, ExpressionInterface::TYPE_IDENTIFIER],
+ [NotBetween::TYPE_VALUE, NotBetween::TYPE_IDENTIFIER, NotBetween::TYPE_IDENTIFIER],
],
];
self::assertEquals($expected, $this->notBetween->getExpressionData());
diff --git a/test/unit/Sql/Predicate/NotInTest.php b/test/unit/Sql/Predicate/NotInTest.php
index 0decea1d8..b25144ab5 100644
--- a/test/unit/Sql/Predicate/NotInTest.php
+++ b/test/unit/Sql/Predicate/NotInTest.php
@@ -6,9 +6,9 @@
use Laminas\Db\Sql\Select;
use PHPUnit\Framework\TestCase;
-final class NotInTest extends TestCase
+class NotInTest extends TestCase
{
- public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes(): void
+ public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes()
{
$in = new NotIn();
$in->setIdentifier('foo.bar')
@@ -23,7 +23,7 @@ public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAnd
self::assertEquals($expected, $in->getExpressionData());
}
- public function testGetExpressionDataWithSubselect(): void
+ public function testGetExpressionDataWithSubselect()
{
$select = new Select();
$in = new NotIn('foo', $select);
@@ -37,7 +37,7 @@ public function testGetExpressionDataWithSubselect(): void
self::assertEquals($expected, $in->getExpressionData());
}
- public function testGetExpressionDataWithSubselectAndIdentifier(): void
+ public function testGetExpressionDataWithSubselectAndIdentifier()
{
$select = new Select();
$in = new NotIn('foo', $select);
@@ -51,7 +51,7 @@ public function testGetExpressionDataWithSubselectAndIdentifier(): void
self::assertEquals($expected, $in->getExpressionData());
}
- public function testGetExpressionDataWithSubselectAndArrayIdentifier(): void
+ public function testGetExpressionDataWithSubselectAndArrayIdentifier()
{
$select = new Select();
$in = new NotIn(['foo', 'bar'], $select);
diff --git a/test/unit/Sql/Predicate/NotLikeTest.php b/test/unit/Sql/Predicate/NotLikeTest.php
index 0b5f772ab..904805266 100644
--- a/test/unit/Sql/Predicate/NotLikeTest.php
+++ b/test/unit/Sql/Predicate/NotLikeTest.php
@@ -6,23 +6,23 @@
use Laminas\Db\Sql\Predicate\NotLike;
use PHPUnit\Framework\TestCase;
-final class NotLikeTest extends TestCase
+class NotLikeTest extends TestCase
{
- public function testConstructEmptyArgs(): void
+ public function testConstructEmptyArgs()
{
$notLike = new NotLike();
self::assertEquals('', $notLike->getIdentifier());
self::assertEquals('', $notLike->getLike());
}
- public function testConstructWithArgs(): void
+ public function testConstructWithArgs()
{
$notLike = new NotLike('bar', 'Foo%');
self::assertEquals('bar', $notLike->getIdentifier());
self::assertEquals('Foo%', $notLike->getLike());
}
- public function testAccessorsMutators(): void
+ public function testAccessorsMutators()
{
$notLike = new NotLike();
$notLike->setIdentifier('bar');
@@ -33,7 +33,7 @@ public function testAccessorsMutators(): void
self::assertEquals('target = target', $notLike->getSpecification());
}
- public function testGetExpressionData(): void
+ public function testGetExpressionData()
{
$notLike = new NotLike('bar', 'Foo%');
self::assertEquals(
@@ -48,7 +48,7 @@ public function testGetExpressionData(): void
);
}
- public function testInstanceOfPerSetters(): void
+ public function testInstanceOfPerSetters()
{
$notLike = new NotLike();
self::assertInstanceOf(Like::class, $notLike->setIdentifier('bar'));
diff --git a/test/unit/Sql/Predicate/OperatorTest.php b/test/unit/Sql/Predicate/OperatorTest.php
index 899774cae..fe866cc39 100644
--- a/test/unit/Sql/Predicate/OperatorTest.php
+++ b/test/unit/Sql/Predicate/OperatorTest.php
@@ -7,16 +7,16 @@
use function var_export;
-final class OperatorTest extends TestCase
+class OperatorTest extends TestCase
{
- public function testEmptyConstructorYieldsNullLeftAndRightValues(): void
+ public function testEmptyConstructorYieldsNullLeftAndRightValues()
{
$operator = new Operator();
self::assertNull($operator->getLeft());
self::assertNull($operator->getRight());
}
- public function testEmptyConstructorYieldsDefaultsForOperatorAndLeftAndRightTypes(): void
+ public function testEmptyConstructorYieldsDefaultsForOperatorAndLeftAndRightTypes()
{
$operator = new Operator();
self::assertEquals(Operator::OP_EQ, $operator->getOperator());
@@ -24,7 +24,7 @@ public function testEmptyConstructorYieldsDefaultsForOperatorAndLeftAndRightType
self::assertEquals(Operator::TYPE_VALUE, $operator->getRightType());
}
- public function testCanPassAllValuesToConstructor(): void
+ public function testCanPassAllValuesToConstructor()
{
$operator = new Operator('bar', '>=', 'foo.bar', Operator::TYPE_VALUE, Operator::TYPE_IDENTIFIER);
self::assertEquals(Operator::OP_GTE, $operator->getOperator());
@@ -44,42 +44,42 @@ public function testCanPassAllValuesToConstructor(): void
self::assertEquals(0, $operator->getRight());
}
- public function testLeftIsMutable(): void
+ public function testLeftIsMutable()
{
$operator = new Operator();
$operator->setLeft('foo.bar');
self::assertEquals('foo.bar', $operator->getLeft());
}
- public function testRightIsMutable(): void
+ public function testRightIsMutable()
{
$operator = new Operator();
$operator->setRight('bar');
self::assertEquals('bar', $operator->getRight());
}
- public function testLeftTypeIsMutable(): void
+ public function testLeftTypeIsMutable()
{
$operator = new Operator();
$operator->setLeftType(Operator::TYPE_VALUE);
self::assertEquals(Operator::TYPE_VALUE, $operator->getLeftType());
}
- public function testRightTypeIsMutable(): void
+ public function testRightTypeIsMutable()
{
$operator = new Operator();
$operator->setRightType(Operator::TYPE_IDENTIFIER);
self::assertEquals(Operator::TYPE_IDENTIFIER, $operator->getRightType());
}
- public function testOperatorIsMutable(): void
+ public function testOperatorIsMutable()
{
$operator = new Operator();
$operator->setOperator(Operator::OP_LTE);
self::assertEquals(Operator::OP_LTE, $operator->getOperator());
}
- public function testRetrievingWherePartsReturnsSpecificationArrayOfLeftAndRightAndArrayOfTypes(): void
+ public function testRetrievingWherePartsReturnsSpecificationArrayOfLeftAndRightAndArrayOfTypes()
{
$operator = new Operator();
$operator->setLeft('foo')
@@ -95,6 +95,6 @@ public function testRetrievingWherePartsReturnsSpecificationArrayOfLeftAndRightA
],
];
$test = $operator->getExpressionData();
- self::assertEquals($expected, $test, var_export($test, true));
+ self::assertEquals($expected, $test, var_export($test, 1));
}
}
diff --git a/test/unit/Sql/Predicate/PredicateSetTest.php b/test/unit/Sql/Predicate/PredicateSetTest.php
index 17332b825..80f452f7f 100644
--- a/test/unit/Sql/Predicate/PredicateSetTest.php
+++ b/test/unit/Sql/Predicate/PredicateSetTest.php
@@ -11,49 +11,45 @@
use Laminas\Db\Sql\Predicate\Operator;
use Laminas\Db\Sql\Predicate\PredicateSet;
use LaminasTest\Db\DeprecatedAssertionsTrait;
-use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
use function var_export;
-#[CoversMethod(PredicateSet::class, 'addPredicates')]
-final class PredicateSetTest extends TestCase
+class PredicateSetTest extends TestCase
{
use DeprecatedAssertionsTrait;
- public function testEmptyConstructorYieldsCountOfZero(): void
+ public function testEmptyConstructorYieldsCountOfZero()
{
$predicateSet = new PredicateSet();
self::assertCount(0, $predicateSet);
}
- public function testCombinationIsAndByDefault(): void
+ public function testCombinationIsAndByDefault()
{
$predicateSet = new PredicateSet();
$predicateSet->addPredicate(new IsNull('foo'))
->addPredicate(new IsNull('bar'));
$parts = $predicateSet->getExpressionData();
self::assertCount(3, $parts);
-
- self::assertStringContainsString('AND', (string) $parts[1]);
- self::assertStringNotContainsString('OR', (string) $parts[1]);
+ self::assertStringContainsString('AND', $parts[1]);
+ self::assertStringNotContainsString('OR', $parts[1]);
}
- public function testCanPassPredicatesAndDefaultCombinationViaConstructor(): void
+ public function testCanPassPredicatesAndDefaultCombinationViaConstructor()
{
- new PredicateSet();
- $set = new PredicateSet([
+ $predicateSet = new PredicateSet();
+ $set = new PredicateSet([
new IsNull('foo'),
new IsNull('bar'),
], 'OR');
- $parts = $set->getExpressionData();
+ $parts = $set->getExpressionData();
self::assertCount(3, $parts);
- self::assertStringContainsString('OR', (string) $parts[1]);
- self::assertStringNotContainsString('AND', (string) $parts[1]);
+ self::assertStringContainsString('OR', $parts[1]);
+ self::assertStringNotContainsString('AND', $parts[1]);
}
- public function testCanPassBothPredicateAndCombinationToAddPredicate(): void
+ public function testCanPassBothPredicateAndCombinationToAddPredicate()
{
$predicateSet = new PredicateSet();
$predicateSet->addPredicate(new IsNull('foo'), 'OR')
@@ -63,17 +59,17 @@ public function testCanPassBothPredicateAndCombinationToAddPredicate(): void
$parts = $predicateSet->getExpressionData();
self::assertCount(7, $parts);
- self::assertStringNotContainsString('OR', (string) $parts[1], var_export($parts, true));
- self::assertStringContainsString('AND', (string) $parts[1]);
+ self::assertStringNotContainsString('OR', $parts[1], var_export($parts, 1));
+ self::assertStringContainsString('AND', $parts[1]);
- self::assertStringContainsString('OR', (string) $parts[3]);
- self::assertStringNotContainsString('AND', (string) $parts[3]);
+ self::assertStringContainsString('OR', $parts[3]);
+ self::assertStringNotContainsString('AND', $parts[3]);
- self::assertStringNotContainsString('OR', (string) $parts[5]);
- self::assertStringContainsString('AND', (string) $parts[5]);
+ self::assertStringNotContainsString('OR', $parts[5]);
+ self::assertStringContainsString('AND', $parts[5]);
}
- public function testCanUseOrPredicateAndAndPredicateMethods(): void
+ public function testCanUseOrPredicateAndAndPredicateMethods()
{
$predicateSet = new PredicateSet();
$predicateSet->orPredicate(new IsNull('foo'))
@@ -83,20 +79,20 @@ public function testCanUseOrPredicateAndAndPredicateMethods(): void
$parts = $predicateSet->getExpressionData();
self::assertCount(7, $parts);
- self::assertStringNotContainsString('OR', (string) $parts[1], var_export($parts, true));
- self::assertStringContainsString('AND', (string) $parts[1]);
+ self::assertStringNotContainsString('OR', $parts[1], var_export($parts, 1));
+ self::assertStringContainsString('AND', $parts[1]);
- self::assertStringContainsString('OR', (string) $parts[3]);
- self::assertStringNotContainsString('AND', (string) $parts[3]);
+ self::assertStringContainsString('OR', $parts[3]);
+ self::assertStringNotContainsString('AND', $parts[3]);
- self::assertStringNotContainsString('OR', (string) $parts[5]);
- self::assertStringContainsString('AND', (string) $parts[5]);
+ self::assertStringNotContainsString('OR', $parts[5]);
+ self::assertStringContainsString('AND', $parts[5]);
}
/**
- * @throws ReflectionException
+ * @covers \Laminas\Db\Sql\Predicate\PredicateSet::addPredicates
*/
- public function testAddPredicates(): void
+ public function testAddPredicates()
{
$predicateSet = new PredicateSet();
@@ -108,44 +104,34 @@ public function testAddPredicates(): void
$predicateSet->addPredicates(['c2' => [1, 2, 3]]);
$predicateSet->addPredicates([new IsNotNull('c3')]);
- $predicates = (array) $this->readAttribute($predicateSet, 'predicates');
- self::assertCount(7, $predicates);
-
- self::assertIsArray($predicates[0]);
+ $predicates = $this->readAttribute($predicateSet, 'predicates');
self::assertEquals('AND', $predicates[0][0]);
self::assertInstanceOf(Literal::class, $predicates[0][1]);
- self::assertIsArray($predicates[1]);
self::assertEquals('AND', $predicates[1][0]);
self::assertInstanceOf(Expression::class, $predicates[1][1]);
- self::assertIsArray($predicates[2]);
self::assertEquals('AND', $predicates[2][0]);
self::assertInstanceOf(Operator::class, $predicates[2][1]);
- self::assertIsArray($predicates[3]);
self::assertEquals('OR', $predicates[3][0]);
self::assertInstanceOf(Literal::class, $predicates[3][1]);
- self::assertIsArray($predicates[4]);
self::assertEquals('AND', $predicates[4][0]);
self::assertInstanceOf(IsNull::class, $predicates[4][1]);
- self::assertIsArray($predicates[5]);
self::assertEquals('AND', $predicates[5][0]);
self::assertInstanceOf(In::class, $predicates[5][1]);
- self::assertIsArray($predicates[6]);
self::assertEquals('AND', $predicates[6][0]);
self::assertInstanceOf(IsNotNull::class, $predicates[6][1]);
- $predicateSet->addPredicates(function (PredicateSet $what) use ($predicateSet): void {
+ $predicateSet->addPredicates(function ($what) use ($predicateSet) {
self::assertSame($predicateSet, $what);
});
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Predicate cannot be null');
- /** @psalm-suppress NullArgument - ensure an exception is thrown */
$predicateSet->addPredicates(null);
}
}
diff --git a/test/unit/Sql/Predicate/PredicateTest.php b/test/unit/Sql/Predicate/PredicateTest.php
index e4d870fb9..c84891367 100644
--- a/test/unit/Sql/Predicate/PredicateTest.php
+++ b/test/unit/Sql/Predicate/PredicateTest.php
@@ -2,187 +2,168 @@
namespace LaminasTest\Db\Sql\Predicate;
-use ErrorException;
use Laminas\Db\Adapter\Platform\Sql92;
use Laminas\Db\Sql\Expression;
-use Laminas\Db\Sql\ExpressionInterface;
use Laminas\Db\Sql\Predicate\Predicate;
use Laminas\Db\Sql\Select;
use Laminas\Stdlib\ErrorHandler;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
use const E_USER_NOTICE;
-final class PredicateTest extends TestCase
+class PredicateTest extends TestCase
{
- public function testEqualToCreatesOperatorPredicate(): void
+ public function testEqualToCreatesOperatorPredicate()
{
$predicate = new Predicate();
$predicate->equalTo('foo.bar', 'bar');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%s = %s', $parts[0]);
self::assertContains(['foo.bar', 'bar'], $parts[0]);
}
- public function testNotEqualToCreatesOperatorPredicate(): void
+ public function testNotEqualToCreatesOperatorPredicate()
{
$predicate = new Predicate();
$predicate->notEqualTo('foo.bar', 'bar');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%s != %s', $parts[0]);
self::assertContains(['foo.bar', 'bar'], $parts[0]);
}
- public function testLessThanCreatesOperatorPredicate(): void
+ public function testLessThanCreatesOperatorPredicate()
{
$predicate = new Predicate();
$predicate->lessThan('foo.bar', 'bar');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%s < %s', $parts[0]);
self::assertContains(['foo.bar', 'bar'], $parts[0]);
}
- public function testGreaterThanCreatesOperatorPredicate(): void
+ public function testGreaterThanCreatesOperatorPredicate()
{
$predicate = new Predicate();
$predicate->greaterThan('foo.bar', 'bar');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%s > %s', $parts[0]);
self::assertContains(['foo.bar', 'bar'], $parts[0]);
}
- public function testLessThanOrEqualToCreatesOperatorPredicate(): void
+ public function testLessThanOrEqualToCreatesOperatorPredicate()
{
$predicate = new Predicate();
$predicate->lessThanOrEqualTo('foo.bar', 'bar');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%s <= %s', $parts[0]);
self::assertContains(['foo.bar', 'bar'], $parts[0]);
}
- public function testGreaterThanOrEqualToCreatesOperatorPredicate(): void
+ public function testGreaterThanOrEqualToCreatesOperatorPredicate()
{
$predicate = new Predicate();
$predicate->greaterThanOrEqualTo('foo.bar', 'bar');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%s >= %s', $parts[0]);
self::assertContains(['foo.bar', 'bar'], $parts[0]);
}
- public function testLikeCreatesLikePredicate(): void
+ public function testLikeCreatesLikePredicate()
{
$predicate = new Predicate();
$predicate->like('foo.bar', 'bar%');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%1$s LIKE %2$s', $parts[0]);
self::assertContains(['foo.bar', 'bar%'], $parts[0]);
}
- public function testNotLikeCreatesLikePredicate(): void
+ public function testNotLikeCreatesLikePredicate()
{
$predicate = new Predicate();
$predicate->notLike('foo.bar', 'bar%');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%1$s NOT LIKE %2$s', $parts[0]);
self::assertContains(['foo.bar', 'bar%'], $parts[0]);
}
- public function testLiteralCreatesLiteralPredicate(): void
+ public function testLiteralCreatesLiteralPredicate()
{
$predicate = new Predicate();
- /** @psalm-suppress TooManyArguments */
$predicate->literal('foo.bar = ?', 'bar');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('foo.bar = %s', $parts[0]);
self::assertContains(['bar'], $parts[0]);
}
- public function testIsNullCreatesIsNullPredicate(): void
+ public function testIsNullCreatesIsNullPredicate()
{
$predicate = new Predicate();
$predicate->isNull('foo.bar');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%1$s IS NULL', $parts[0]);
self::assertContains(['foo.bar'], $parts[0]);
}
- public function testIsNotNullCreatesIsNotNullPredicate(): void
+ public function testIsNotNullCreatesIsNotNullPredicate()
{
$predicate = new Predicate();
$predicate->isNotNull('foo.bar');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%1$s IS NOT NULL', $parts[0]);
self::assertContains(['foo.bar'], $parts[0]);
}
- public function testInCreatesInPredicate(): void
+ public function testInCreatesInPredicate()
{
$predicate = new Predicate();
$predicate->in('foo.bar', ['foo', 'bar']);
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%s IN (%s, %s)', $parts[0]);
self::assertContains(['foo.bar', 'foo', 'bar'], $parts[0]);
}
- public function testNotInCreatesNotInPredicate(): void
+ public function testNotInCreatesNotInPredicate()
{
$predicate = new Predicate();
$predicate->notIn('foo.bar', ['foo', 'bar']);
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%s NOT IN (%s, %s)', $parts[0]);
self::assertContains(['foo.bar', 'foo', 'bar'], $parts[0]);
}
- public function testBetweenCreatesBetweenPredicate(): void
+ public function testBetweenCreatesBetweenPredicate()
{
$predicate = new Predicate();
$predicate->between('foo.bar', 1, 10);
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%1$s BETWEEN %2$s AND %3$s', $parts[0]);
self::assertContains(['foo.bar', 1, 10], $parts[0]);
}
- public function testBetweenCreatesNotBetweenPredicate(): void
+ public function testBetweenCreatesNotBetweenPredicate()
{
$predicate = new Predicate();
$predicate->notBetween('foo.bar', 1, 10);
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(1, $parts);
self::assertContains('%1$s NOT BETWEEN %2$s AND %3$s', $parts[0]);
self::assertContains(['foo.bar', 1, 10], $parts[0]);
}
- public function testCanChainPredicateFactoriesBetweenOperators(): void
+ public function testCanChainPredicateFactoriesBetweenOperators()
{
$predicate = new Predicate();
$predicate->isNull('foo.bar')
@@ -191,7 +172,6 @@ public function testCanChainPredicateFactoriesBetweenOperators(): void
->and
->equalTo('baz.bat', 'foo');
$parts = $predicate->getExpressionData();
- $this->assertIsArray($parts[0]);
self::assertCount(5, $parts);
self::assertContains('%1$s IS NULL', $parts[0]);
@@ -199,18 +179,16 @@ public function testCanChainPredicateFactoriesBetweenOperators(): void
self::assertEquals(' OR ', $parts[1]);
- $this->assertIsArray($parts[2]);
self::assertContains('%1$s IS NOT NULL', $parts[2]);
self::assertContains(['bar.baz'], $parts[2]);
self::assertEquals(' AND ', $parts[3]);
- $this->assertIsArray($parts[4]);
self::assertContains('%s = %s', $parts[4]);
self::assertContains(['baz.bat', 'foo'], $parts[4]);
}
- public function testCanNestPredicates(): void
+ public function testCanNestPredicates()
{
$predicate = new Predicate();
$predicate->isNull('foo.bar')
@@ -223,7 +201,6 @@ public function testCanNestPredicates(): void
self::assertCount(7, $parts);
- $this->assertIsArray($parts[0]);
self::assertContains('%1$s IS NULL', $parts[0]);
self::assertContains(['foo.bar'], $parts[0]);
@@ -231,21 +208,21 @@ public function testCanNestPredicates(): void
self::assertEquals('(', $parts[2]);
- $this->assertIsArray($parts[3]);
self::assertContains('%1$s IS NOT NULL', $parts[3]);
self::assertContains(['bar.baz'], $parts[3]);
self::assertEquals(' AND ', $parts[4]);
- $this->assertIsArray($parts[5]);
self::assertContains('%s = %s', $parts[5]);
self::assertContains(['baz.bat', 'foo'], $parts[5]);
self::assertEquals(')', $parts[6]);
}
- #[TestDox('Unit test: Test expression() is chainable and returns proper values')]
- public function testExpression(): void
+ /**
+ * @testdox Unit test: Test expression() is chainable and returns proper values
+ */
+ public function testExpression()
{
$predicate = new Predicate();
@@ -253,30 +230,28 @@ public function testExpression(): void
self::assertSame($predicate, $predicate->expression('foo = ?', 0));
// with parameter
self::assertEquals(
- [['foo = %s', [0], [ExpressionInterface::TYPE_VALUE]]],
+ [['foo = %s', [0], [Expression::TYPE_VALUE]]],
$predicate->getExpressionData()
);
}
- #[TestDox('Unit test: Test expression() allows null $parameters')]
- public function testExpressionNullParameters(): void
+ /**
+ * @testdox Unit test: Test expression() allows null $parameters
+ */
+ public function testExpressionNullParameters()
{
$predicate = new Predicate();
$predicate->expression('foo = bar');
$predicates = $predicate->getPredicates();
-
- if (isset($predicates[0][1])) {
- $expression = $predicates[0][1];
- $this->assertInstanceOf(Expression::class, $expression);
- self::assertEquals([], $expression->getParameters());
- } else {
- $this->fail('Expression not found');
- }
+ $expression = $predicates[0][1];
+ self::assertEquals([], $expression->getParameters());
}
- #[TestDox('Unit test: Test literal() is chainable, returns proper values, and is backwards compatible with 2.0.*')]
- public function testLiteral(): void
+ /**
+ * @testdox Unit test: Test literal() is chainable, returns proper values, and is backwards compatible with 2.0.*
+ */
+ public function testLiteral()
{
$predicate = new Predicate();
@@ -293,7 +268,7 @@ public function testLiteral(): void
$predicate->expression('foo = ?', 'bar');
// with parameter
self::assertEquals(
- [['foo = %s', ['bar'], [ExpressionInterface::TYPE_VALUE]]],
+ [['foo = %s', ['bar'], [Expression::TYPE_VALUE]]],
$predicate->getExpressionData()
);
@@ -302,14 +277,11 @@ public function testLiteral(): void
$predicate->expression('foo = ?', 0);
// with parameter
self::assertEquals(
- [['foo = %s', [0], [ExpressionInterface::TYPE_VALUE]]],
+ [['foo = %s', [0], [Expression::TYPE_VALUE]]],
$predicate->getExpressionData()
);
}
- /**
- * @throws ErrorException
- */
public function testCanCreateExpressionsWithoutAnyBoundSqlParameters(): void
{
$where1 = new Predicate();
@@ -322,9 +294,6 @@ public function testCanCreateExpressionsWithoutAnyBoundSqlParameters(): void
);
}
- /**
- * @throws ErrorException
- */
public function testWillBindSqlParametersToExpressionsWithGivenParameter(): void
{
$where = new Predicate();
@@ -337,9 +306,6 @@ public function testWillBindSqlParametersToExpressionsWithGivenParameter(): void
);
}
- /**
- * @throws ErrorException
- */
public function testWillBindSqlParametersToExpressionsWithGivenStringParameter(): void
{
$where = new Predicate();
@@ -352,9 +318,6 @@ public function testWillBindSqlParametersToExpressionsWithGivenStringParameter()
);
}
- /**
- * @throws ErrorException
- */
private function makeSqlString(Predicate $where): string
{
$select = new Select('a_table');
diff --git a/test/unit/Sql/SelectTest.php b/test/unit/Sql/SelectTest.php
index 6d30f4f60..35cec4028 100644
--- a/test/unit/Sql/SelectTest.php
+++ b/test/unit/Sql/SelectTest.php
@@ -11,7 +11,6 @@
use Laminas\Db\Sql\Expression;
use Laminas\Db\Sql\ExpressionInterface;
use Laminas\Db\Sql\Having;
-use Laminas\Db\Sql\Join;
use Laminas\Db\Sql\Predicate;
use Laminas\Db\Sql\Predicate\In;
use Laminas\Db\Sql\Predicate\IsNotNull;
@@ -21,69 +20,47 @@
use Laminas\Db\Sql\TableIdentifier;
use Laminas\Db\Sql\Where;
use LaminasTest\Db\TestAsset\TrustingSql92Platform;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\Depends;
-use PHPUnit\Framework\Attributes\Group;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
use ReflectionObject;
-#[CoversMethod(Select::class, '__construct')]
-#[CoversMethod(Select::class, 'from')]
-#[CoversMethod(Select::class, 'getRawState')]
-#[CoversMethod(Select::class, 'quantifier')]
-#[CoversMethod(Select::class, 'columns')]
-#[CoversMethod(Select::class, 'isTableReadOnly')]
-#[CoversMethod(Select::class, 'join')]
-#[CoversMethod(Select::class, 'processJoins')]
-#[CoversMethod(Select::class, 'where')]
-#[CoversMethod(Select::class, 'order')]
-#[CoversMethod(Select::class, 'limit')]
-#[CoversMethod(Select::class, 'offset')]
-#[CoversMethod(Select::class, 'group')]
-#[CoversMethod(Select::class, 'having')]
-#[CoversMethod(Select::class, 'combine')]
-#[CoversMethod(Select::class, 'reset')]
-#[CoversMethod(Select::class, 'prepareStatement')]
-#[CoversMethod(Select::class, 'getSqlString')]
-#[CoversMethod(Select::class, '__get')]
-#[CoversMethod(Select::class, '__clone')]
-#[CoversMethod(Select::class, 'processSelect')]
-#[CoversMethod(Select::class, 'processWhere')]
-#[CoversMethod(Select::class, 'processGroup')]
-#[CoversMethod(Select::class, 'processHaving')]
-#[CoversMethod(Select::class, 'processOrder')]
-#[CoversMethod(Select::class, 'processLimit')]
-#[CoversMethod(Select::class, 'processOffset')]
-#[CoversMethod(Select::class, 'processCombine')]
-final class SelectTest extends TestCase
+class SelectTest extends TestCase
{
- public function testConstruct(): void
+ /**
+ * @covers \Laminas\Db\Sql\Select::__construct
+ */
+ public function testConstruct()
{
$select = new Select('foo');
self::assertEquals('foo', $select->getRawState('table'));
}
- #[TestDox('unit test: Test from() returns Select object (is chainable)')]
+ /**
+ * @testdox unit test: Test from() returns Select object (is chainable)
+ * @covers \Laminas\Db\Sql\Select::from
+ */
public function testFrom(): Select
{
$select = new Select();
- $return = $select->from('foo');
+ $return = $select->from('foo', 'bar');
self::assertSame($select, $return);
return $return;
}
- #[Depends('testFrom')]
- #[TestDox('unit test: Test getRawState() returns information populated via from()')]
- public function testGetRawStateViaFrom(Select $select): void
+ /**
+ * @testdox unit test: Test getRawState() returns information populated via from()
+ * @covers \Laminas\Db\Sql\Select::getRawState
+ * @depends testFrom
+ */
+ public function testGetRawStateViaFrom(Select $select)
{
self::assertEquals('foo', $select->getRawState('table'));
}
- #[TestDox('unit test: Test quantifier() returns Select object (is chainable)')]
+ /**
+ * @testdox unit test: Test quantifier() returns Select object (is chainable)
+ * @covers \Laminas\Db\Sql\Select::quantifier
+ */
public function testQuantifier(): Select
{
$select = new Select();
@@ -92,19 +69,24 @@ public function testQuantifier(): Select
return $return;
}
- #[Depends('testQuantifier')]
- #[TestDox('unit test: Test getRawState() returns information populated via quantifier()')]
- public function testGetRawStateViaQuantifier(Select $select): void
+ /**
+ * @testdox unit test: Test getRawState() returns information populated via quantifier()
+ * @covers \Laminas\Db\Sql\Select::getRawState
+ * @depends testQuantifier
+ */
+ public function testGetRawStateViaQuantifier(Select $select)
{
self::assertEquals(Select::QUANTIFIER_DISTINCT, $select->getRawState('quantifier'));
}
- #[TestDox('unit test: Test quantifier() accepts expression')]
- public function testQuantifierParameterExpressionInterface(): void
+ /**
+ * @testdox unit test: Test quantifier() accepts expression
+ * @covers \Laminas\Db\Sql\Select::quantifier
+ */
+ public function testQuantifierParameterExpressionInterface()
{
- $expr = $this->getMockBuilder(ExpressionInterface::class)->onlyMethods([])->getMock();
+ $expr = $this->getMockBuilder(ExpressionInterface::class)->getMock();
$select = new Select();
- /** @psalm-suppress InvalidArgument */
$select->quantifier($expr);
self::assertSame(
$expr,
@@ -112,7 +94,10 @@ public function testQuantifierParameterExpressionInterface(): void
);
}
- #[TestDox('unit test: Test columns() returns Select object (is chainable)')]
+ /**
+ * @testdox unit test: Test columns() returns Select object (is chainable)
+ * @covers \Laminas\Db\Sql\Select::columns
+ */
public function testColumns(): Select
{
$select = new Select();
@@ -122,8 +107,11 @@ public function testColumns(): Select
return $select;
}
- #[TestDox('unit test: Test isTableReadOnly() returns correct state for read only')]
- public function testIsTableReadOnly(): void
+ /**
+ * @testdox unit test: Test isTableReadOnly() returns correct state for read only
+ * @covers \Laminas\Db\Sql\Select::isTableReadOnly
+ */
+ public function testIsTableReadOnly()
{
$select = new Select('foo');
self::assertTrue($select->isTableReadOnly());
@@ -132,63 +120,74 @@ public function testIsTableReadOnly(): void
self::assertFalse($select->isTableReadOnly());
}
- #[Depends('testColumns')]
- #[TestDox('unit test: Test getRawState() returns information populated via columns()')]
- public function testGetRawStateViaColumns(Select $select): void
+ /**
+ * @testdox unit test: Test getRawState() returns information populated via columns()
+ * @covers \Laminas\Db\Sql\Select::getRawState
+ * @depends testColumns
+ */
+ public function testGetRawStateViaColumns(Select $select)
{
self::assertEquals(['foo', 'bar'], $select->getRawState('columns'));
}
- #[TestDox('unit test: Test join() returns same Select object (is chainable)')]
+ /**
+ * @testdox unit test: Test join() returns same Select object (is chainable)
+ * @covers \Laminas\Db\Sql\Select::join
+ */
public function testJoin(): Select
{
$select = new Select();
- $return = $select->join('foo', 'x = y');
+ $return = $select->join('foo', 'x = y', Select::SQL_STAR, Select::JOIN_INNER);
self::assertSame($select, $return);
return $return;
}
- #[TestDox('unit test: Test join() exception with bad join')]
- public function testBadJoin(): void
+ /**
+ * @testdox unit test: Test join() exception with bad join
+ * @covers \Laminas\Db\Sql\Select::join
+ */
+ public function testBadJoin()
{
$select = new Select();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("expects 'foo' as");
- $select->join(['foo'], 'x = y');
+ $select->join(['foo'], 'x = y', Select::SQL_STAR, Select::JOIN_INNER);
}
/**
- * @throws ReflectionException
+ * @testdox unit test: Test processJoins() exception with bad join name
+ * @covers \Laminas\Db\Sql\Select::processJoins
*/
- #[TestDox('unit test: Test processJoins() exception with bad join name')]
- public function testBadJoinName(): void
+ public function testBadJoinName()
{
$mockExpression = $this->getMockBuilder(ExpressionInterface::class)
->getMock();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$parameterContainer = new ParameterContainer();
$select = new Select();
- $select->join(['foo' => $mockExpression], 'x = y');
+ $select->join(['foo' => $mockExpression], 'x = y', Select::SQL_STAR, Select::JOIN_INNER);
$sr = new ReflectionObject($select);
$mr = $sr->getMethod('processJoins');
- /** @psalm-suppress UnusedMethodCall */
+
$mr->setAccessible(true);
$this->expectException(InvalidArgumentException::class);
+
$mr->invokeArgs($select, [new Sql92(), $mockDriver, $parameterContainer]);
}
- #[Depends('testJoin')]
- #[TestDox('unit test: Test getRawState() returns information populated via join()')]
- public function testGetRawStateViaJoin(Select $select): void
+ /**
+ * @testdox unit test: Test getRawState() returns information populated via join()
+ * @covers \Laminas\Db\Sql\Select::getRawState
+ * @depends testJoin
+ */
+ public function testGetRawStateViaJoin(Select $select)
{
- $joins = $select->getRawState('joins');
- self::assertInstanceOf(Join::class, $joins);
self::assertEquals(
[
[
@@ -198,19 +197,25 @@ public function testGetRawStateViaJoin(Select $select): void
'type' => Select::JOIN_INNER,
],
],
- $joins->getJoins()
+ $select->getRawState('joins')->getJoins()
);
}
- #[TestDox('unit test: Test where() returns Select object (is chainable)')]
- public function testWhereReturnsSameSelectObject(): void
+ /**
+ * @testdox unit test: Test where() returns Select object (is chainable)
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereReturnsSameSelectObject()
{
$select = new Select();
self::assertSame($select, $select->where('x = y'));
}
- #[TestDox('unit test: Test where() will accept a string for the predicate to create an expression predicate')]
- public function testWhereArgument1IsString(): void
+ /**
+ * @testdox unit test: Test where() will accept a string for the predicate to create an expression predicate
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsString()
{
$select = new Select();
$select->where('x = ?');
@@ -219,9 +224,8 @@ public function testWhereArgument1IsString(): void
$where = $select->getRawState('where');
$predicates = $where->getPredicates();
self::assertCount(1, $predicates);
- self::assertIsArray($predicates[0]);
- self::assertInstanceOf(Predicate\Expression::class, $predicates[0][1]);
- self::assertEquals(Predicate\PredicateSet::OP_AND, $predicates[0][0]);
+ self::assertInstanceOf(\Laminas\Db\Sql\Predicate\Expression::class, $predicates[0][1]);
+ self::assertEquals(Where::OP_AND, $predicates[0][0]);
self::assertEquals('x = ?', $predicates[0][1]->getExpression());
$select = new Select();
@@ -230,13 +234,15 @@ public function testWhereArgument1IsString(): void
/** @var Where $where */
$where = $select->getRawState('where');
$predicates = $where->getPredicates();
- self::assertIsArray($predicates[0]);
self::assertInstanceOf(Literal::class, $predicates[0][1]);
}
- #[TestDox('unit test: Test where() will accept an array with a string key (containing ?) used as an
- expression with placeholder')]
- public function testWhereArgument1IsAssociativeArrayContainingReplacementCharacter(): void
+ /**
+ * @testdox unit test: Test where() will accept an array with a string key (containing ?) used as an
+ * expression with placeholder
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsAssociativeArrayContainingReplacementCharacter()
{
$select = new Select();
$select->where(['foo > ?' => 5]);
@@ -245,16 +251,18 @@ public function testWhereArgument1IsAssociativeArrayContainingReplacementCharact
$where = $select->getRawState('where');
$predicates = $where->getPredicates();
self::assertCount(1, $predicates);
- self::assertIsArray($predicates[0]);
- self::assertInstanceOf(Predicate\Expression::class, $predicates[0][1]);
- self::assertEquals(Predicate\PredicateSet::OP_AND, $predicates[0][0]);
+ self::assertInstanceOf(\Laminas\Db\Sql\Predicate\Expression::class, $predicates[0][1]);
+ self::assertEquals(Where::OP_AND, $predicates[0][0]);
self::assertEquals('foo > ?', $predicates[0][1]->getExpression());
self::assertEquals([5], $predicates[0][1]->getParameters());
}
- #[TestDox('unit test: Test where() will accept any array with string key (without ?) to be used
- as Operator predicate')]
- public function testWhereArgument1IsAssociativeArrayNotContainingReplacementCharacter(): void
+ /**
+ * @testdox unit test: Test where() will accept any array with string key (without ?) to be used
+ * as Operator predicate
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsAssociativeArrayNotContainingReplacementCharacter()
{
$select = new Select();
$select->where(['name' => 'Ralph', 'age' => 33]);
@@ -263,33 +271,30 @@ public function testWhereArgument1IsAssociativeArrayNotContainingReplacementChar
$where = $select->getRawState('where');
$predicates = $where->getPredicates();
self::assertCount(2, $predicates);
- self::assertIsArray($predicates[0]);
- self::assertIsArray($predicates[1]);
self::assertInstanceOf(Operator::class, $predicates[0][1]);
- self::assertEquals(Predicate\PredicateSet::OP_AND, $predicates[0][0]);
+ self::assertEquals(Where::OP_AND, $predicates[0][0]);
self::assertEquals('name', $predicates[0][1]->getLeft());
self::assertEquals('Ralph', $predicates[0][1]->getRight());
self::assertInstanceOf(Operator::class, $predicates[1][1]);
- self::assertEquals(Predicate\PredicateSet::OP_AND, $predicates[1][0]);
+ self::assertEquals(Where::OP_AND, $predicates[1][0]);
self::assertEquals('age', $predicates[1][1]->getLeft());
self::assertEquals(33, $predicates[1][1]->getRight());
$select = new Select();
$select->where(['x = y']);
- /** @var Where $where */
$where = $select->getRawState('where');
$predicates = $where->getPredicates();
- self::assertIsArray($predicates[0]);
self::assertInstanceOf(Literal::class, $predicates[0][1]);
}
- #[TestDox('
- unit test: Test where() will accept any array with string key (without ?) with Predicate throw Exception
- ')]
- public function testWhereArgument1IsAssociativeArrayIsPredicate(): void
+ /**
+ * @testdox unit test: Test where() will accept any array with string key (without ?) with Predicate throw Exception
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsAssociativeArrayIsPredicate()
{
$select = new Select();
$where = [
@@ -301,8 +306,11 @@ public function testWhereArgument1IsAssociativeArrayIsPredicate(): void
$select->where($where);
}
- #[TestDox('unit test: Test where() will accept an indexed array to be used by joining string expressions')]
- public function testWhereArgument1IsIndexedArray(): void
+ /**
+ * @testdox unit test: Test where() will accept an indexed array to be used by joining string expressions
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsIndexedArray()
{
$select = new Select();
$select->where(['name = "Ralph"']);
@@ -311,43 +319,51 @@ public function testWhereArgument1IsIndexedArray(): void
$where = $select->getRawState('where');
$predicates = $where->getPredicates();
self::assertCount(1, $predicates);
- self::assertIsArray($predicates[0]);
+
self::assertInstanceOf(Literal::class, $predicates[0][1]);
- self::assertEquals(Predicate\PredicateSet::OP_AND, $predicates[0][0]);
+ self::assertEquals(Where::OP_AND, $predicates[0][0]);
self::assertEquals('name = "Ralph"', $predicates[0][1]->getLiteral());
}
- #[TestDox('unit test: Test where() will accept an indexed array to be used by joining string expressions,
- combined by OR')]
- public function testWhereArgument1IsIndexedArrayArgument2IsOr(): void
+ /**
+ * @testdox unit test: Test where() will accept an indexed array to be used by joining string expressions,
+ * combined by OR
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsIndexedArrayArgument2IsOr()
{
$select = new Select();
- $select->where(['name = "Ralph"'], Predicate\PredicateSet::OP_OR);
+ $select->where(['name = "Ralph"'], Where::OP_OR);
/** @var Where $where */
$where = $select->getRawState('where');
$predicates = $where->getPredicates();
self::assertCount(1, $predicates);
- self::assertIsArray($predicates[0]);
+
self::assertInstanceOf(Literal::class, $predicates[0][1]);
- self::assertEquals(Predicate\PredicateSet::OP_OR, $predicates[0][0]);
+ self::assertEquals(Where::OP_OR, $predicates[0][0]);
self::assertEquals('name = "Ralph"', $predicates[0][1]->getLiteral());
}
- #[TestDox('unit test: Test where() will accept a closure to be executed with Where object as argument')]
- public function testWhereArgument1IsClosure(): void
+ /**
+ * @testdox unit test: Test where() will accept a closure to be executed with Where object as argument
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsClosure()
{
$select = new Select();
- /** @var Where $where */
$where = $select->getRawState('where');
- $select->where(function (Where $what) use ($where): void {
+ $select->where(function ($what) use ($where) {
self::assertSame($where, $what);
});
}
- #[TestDox('unit test: Test where() will accept any Predicate object as-is')]
- public function testWhereArgument1IsPredicate(): void
+ /**
+ * @testdox unit test: Test where() will accept any Predicate object as-is
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsPredicate()
{
$select = new Select();
$predicate = new Predicate\Predicate([
@@ -359,12 +375,14 @@ public function testWhereArgument1IsPredicate(): void
/** @var Where $where */
$where = $select->getRawState('where');
$predicates = $where->getPredicates();
- self::assertIsArray($predicates[0]);
self::assertSame($predicate, $predicates[0][1]);
}
- #[TestDox('unit test: Test where() will accept a Where object')]
- public function testWhereArgument1IsWhereObject(): void
+ /**
+ * @testdox unit test: Test where() will accept a Where object
+ * @covers \Laminas\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsWhereObject()
{
$select = new Select();
$select->where($newWhere = new Where());
@@ -372,10 +390,10 @@ public function testWhereArgument1IsWhereObject(): void
}
/**
- * @throws ReflectionException
+ * @testdox unit test: Test order()
+ * @covers \Laminas\Db\Sql\Select::order
*/
- #[TestDox('unit test: Test order()')]
- public function testOrder(): void
+ public function testOrder()
{
$select = new Select();
$return = $select->order('id DESC');
@@ -395,7 +413,6 @@ public function testOrder(): void
$select->order(new Expression('RAND()'));
$sr = new ReflectionObject($select);
$method = $sr->getMethod('processOrder');
- /** @psalm-suppress UnusedMethodCall */
$method->setAccessible(true);
self::assertEquals(
[[['RAND()']]],
@@ -403,16 +420,14 @@ public function testOrder(): void
);
$select = new Select();
- /** @psalm-suppress InvalidArgument - mocked Operator */
$select->order(
$this->getMockBuilder(Operator::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs(['rating', '<', '10'])
->getMock()
);
$sr = new ReflectionObject($select);
$method = $sr->getMethod('processOrder');
- /** @psalm-suppress UnusedMethodCall */
$method->setAccessible(true);
self::assertEquals(
[[['"rating" < \'10\'']]],
@@ -420,8 +435,11 @@ public function testOrder(): void
);
}
- #[TestDox('unit test: Test order() correctly splits parameters.')]
- public function testOrderCorrectlySplitsParameter(): void
+ /**
+ * @testdox unit test: Test order() correctly splits parameters.
+ * @covers \Laminas\Db\Sql\Select::order
+ */
+ public function testOrderCorrectlySplitsParameter()
{
$select = new Select();
$select->order('name desc');
@@ -431,7 +449,10 @@ public function testOrderCorrectlySplitsParameter(): void
);
}
- #[TestDox(': unit test: test limit()')]
+ /**
+ * @testdox: unit test: test limit()
+ * @covers \Laminas\Db\Sql\Select::limit
+ */
public function testLimit(): Select
{
$select = new Select();
@@ -439,17 +460,21 @@ public function testLimit(): Select
return $select;
}
- #[Depends('testLimit')]
- #[TestDox(': unit test: Test getRawState() returns information populated via limit()')]
- public function testGetRawStateViaLimit(Select $select): void
+ /**
+ * @testdox: unit test: Test getRawState() returns information populated via limit()
+ * @covers \Laminas\Db\Sql\Select::getRawState
+ * @depends testLimit
+ */
+ public function testGetRawStateViaLimit(Select $select)
{
- $limit = $select->getRawState((string) $select::LIMIT);
- self::assertIsNumeric($limit);
- self::assertEquals(5, $limit);
+ self::assertEquals(5, $select->getRawState($select::LIMIT));
}
- #[TestDox(': unit test: test limit() throws exception when invalid parameter passed')]
- public function testLimitExceptionOnInvalidParameter(): void
+ /**
+ * @testdox: unit test: test limit() throws execption when invalid parameter passed
+ * @covers \Laminas\Db\Sql\Select::limit
+ */
+ public function testLimitExceptionOnInvalidParameter()
{
$select = new Select();
$this->expectException(InvalidArgumentException::class);
@@ -457,7 +482,10 @@ public function testLimitExceptionOnInvalidParameter(): void
$select->limit('foobar');
}
- #[TestDox(': unit test: test offset()')]
+ /**
+ * @testdox: unit test: test offset()
+ * @covers \Laminas\Db\Sql\Select::offset
+ */
public function testOffset(): Select
{
$select = new Select();
@@ -465,17 +493,21 @@ public function testOffset(): Select
return $select;
}
- #[Depends('testOffset')]
- #[TestDox(': unit test: Test getRawState() returns information populated via offset()')]
- public function testGetRawStateViaOffset(Select $select): void
+ /**
+ * @testdox: unit test: Test getRawState() returns information populated via offset()
+ * @covers \Laminas\Db\Sql\Select::getRawState
+ * @depends testOffset
+ */
+ public function testGetRawStateViaOffset(Select $select)
{
- $offset = $select->getRawState((string) $select::OFFSET);
- self::assertIsNumeric($offset);
- self::assertEquals(10, $offset);
+ self::assertEquals(10, $select->getRawState($select::OFFSET));
}
- #[TestDox(': unit test: test offset() throws exception when invalid parameter passed')]
- public function testOffsetExceptionOnInvalidParameter(): void
+ /**
+ * @testdox: unit test: test offset() throws exception when invalid parameter passed
+ * @covers \Laminas\Db\Sql\Select::offset
+ */
+ public function testOffsetExceptionOnInvalidParameter()
{
$select = new Select();
$this->expectException(InvalidArgumentException::class);
@@ -483,7 +515,10 @@ public function testOffsetExceptionOnInvalidParameter(): void
$select->offset('foobar');
}
- #[TestDox('unit test: Test group() returns same Select object (is chainable)')]
+ /**
+ * @testdox unit test: Test group() returns same Select object (is chainable)
+ * @covers \Laminas\Db\Sql\Select::group
+ */
public function testGroup(): Select
{
$select = new Select();
@@ -493,9 +528,12 @@ public function testGroup(): Select
return $return;
}
- #[Depends('testGroup')]
- #[TestDox('unit test: Test getRawState() returns information populated via group()')]
- public function testGetRawStateViaGroup(Select $select): void
+ /**
+ * @testdox unit test: Test getRawState() returns information populated via group()
+ * @covers \Laminas\Db\Sql\Select::getRawState
+ * @depends testGroup
+ */
+ public function testGetRawStateViaGroup(Select $select)
{
self::assertEquals(
['col1', 'col2'],
@@ -503,7 +541,10 @@ public function testGetRawStateViaGroup(Select $select): void
);
}
- #[TestDox('unit test: Test having() returns same Select object (is chainable)')]
+ /**
+ * @testdox unit test: Test having() returns same Select object (is chainable)
+ * @covers \Laminas\Db\Sql\Select::having
+ */
public function testHaving(): Select
{
$select = new Select();
@@ -513,7 +554,10 @@ public function testHaving(): Select
return $return;
}
- #[TestDox('unit test: Test having() returns same Select object (is chainable)')]
+ /**
+ * @testdox unit test: Test having() returns same Select object (is chainable)
+ * @covers \Laminas\Db\Sql\Select::having
+ */
public function testHavingArgument1IsHavingObject(): Select
{
$select = new Select();
@@ -525,14 +569,20 @@ public function testHavingArgument1IsHavingObject(): Select
return $return;
}
- #[Depends('testHaving')]
- #[TestDox('unit test: Test getRawState() returns information populated via having()')]
- public function testGetRawStateViaHaving(Select $select): void
+ /**
+ * @testdox unit test: Test getRawState() returns information populated via having()
+ * @covers \Laminas\Db\Sql\Select::getRawState
+ * @depends testHaving
+ */
+ public function testGetRawStateViaHaving(Select $select)
{
self::assertInstanceOf(Having::class, $select->getRawState('having'));
}
- #[TestDox('unit test: Test combine() returns same Select object (is chainable)')]
+ /**
+ * @testdox unit test: Test combine() returns same Select object (is chainable)
+ * @covers \Laminas\Db\Sql\Select::combine
+ */
public function testCombine(): Select
{
$select = new Select();
@@ -543,11 +593,13 @@ public function testCombine(): Select
return $return;
}
- #[Depends('testCombine')]
- #[TestDox('unit test: Test getRawState() returns information populated via combine()')]
- public function testGetRawStateViaCombine(Select $select): void
+ /**
+ * @testdox unit test: Test getRawState() returns information populated via combine()
+ * @covers \Laminas\Db\Sql\Select::getRawState
+ * @depends testCombine
+ */
+ public function testGetRawStateViaCombine(Select $select)
{
- /** @var array $state */
$state = $select->getRawState('combine');
self::assertInstanceOf(Select::class, $state['select']);
self::assertNotSame($select, $state['select']);
@@ -555,8 +607,11 @@ public function testGetRawStateViaCombine(Select $select): void
self::assertEquals('ALL', $state['modifier']);
}
- #[TestDox('unit test: Test reset() resets internal stat of Select object, based on input')]
- public function testReset(): void
+ /**
+ * @testdox unit test: Test reset() resets internal stat of Select object, based on input
+ * @covers \Laminas\Db\Sql\Select::reset
+ */
+ public function testReset()
{
$select = new Select();
@@ -574,24 +629,18 @@ public function testReset(): void
// joins
$select->join('foo', 'id = boo');
- $joins = $select->getRawState(Select::JOINS);
- self::assertInstanceOf(Join::class, $joins);
self::assertEquals(
[['name' => 'foo', 'on' => 'id = boo', 'columns' => ['*'], 'type' => 'inner']],
- $joins->getJoins()
+ $select->getRawState(Select::JOINS)->getJoins()
);
$select->reset(Select::JOINS);
- $emptyJoins = $select->getRawState(Select::JOINS);
- self::assertInstanceOf(Join::class, $emptyJoins);
- self::assertEmpty($emptyJoins->getJoins());
+ self::assertEmpty($select->getRawState(Select::JOINS)->getJoins());
// where
$select->where('foo = bar');
- /** @var Where $where1 */
$where1 = $select->getRawState(Select::WHERE);
self::assertEquals(1, $where1->count());
$select->reset(Select::WHERE);
- /** @var Where $where2 */
$where2 = $select->getRawState(Select::WHERE);
self::assertEquals(0, $where2->count());
self::assertNotSame($where1, $where2);
@@ -604,11 +653,9 @@ public function testReset(): void
// having
$select->having('foo = bar');
- /** @var Having $having1 */
$having1 = $select->getRawState(Select::HAVING);
self::assertEquals(1, $having1->count());
$select->reset(Select::HAVING);
- /** @var Having $having2 */
$having2 = $select->getRawState(Select::HAVING);
self::assertEquals(0, $having2->count());
self::assertNotSame($having1, $having2);
@@ -632,25 +679,30 @@ public function testReset(): void
self::assertEmpty($select->getRawState(Select::ORDER));
}
- #[DataProvider('providerData')]
- #[TestDox('unit test: Test prepareStatement() will produce expected sql and parameters based on
- a variety of provided arguments [uses data provider]')]
+ /**
+ * @testdox unit test: Test prepareStatement() will produce expected sql and parameters based on
+ * a variety of provided arguments [uses data provider]
+ * @covers \Laminas\Db\Sql\Select::prepareStatement
+ * @dataProvider providerData
+ * @param mixed $unused1
+ * @param mixed $unused2
+ */
public function testPrepareStatement(
Select $select,
string $expectedSqlString,
array $expectedParameters,
- mixed $unused1,
- mixed $unused2,
+ $unused1,
+ $unused2,
bool $useNamedParameters = false
- ): void {
+ ) {
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver
- ->expects($this->any())
- ->method('formatParameterName')
- ->willReturnCallback(fn(string $name) => $useNamedParameters ? ':' . $name : '?');
-
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnCallback(
+ function ($name) use ($useNamedParameters) {
+ return $useNamedParameters ? ':' . $name : '?';
+ }
+ ));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
@@ -658,18 +710,22 @@ public function testPrepareStatement(
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$mockStatement->expects($this->any())->method('getParameterContainer')
- ->willReturn($parameterContainer);
+ ->will($this->returnValue($parameterContainer));
$mockStatement->expects($this->any())->method('setSql')->with($this->equalTo($expectedSqlString));
$select->prepareStatement($mockAdapter, $mockStatement);
if ($expectedParameters) {
self::assertEquals($expectedParameters, $parameterContainer->getNamedArray());
+ } else {
+ $this->expectNotToPerformAssertions();
}
}
- #[Group('Laminas-5192')]
- public function testSelectUsingTableIdentifierWithEmptyScheme(): void
+ /**
+ * @group Laminas-5192
+ */
+ public function testSelectUsingTableIdentifierWithEmptyScheme()
{
$select = new Select();
$select->from(new TableIdentifier('foo'));
@@ -681,24 +737,35 @@ public function testSelectUsingTableIdentifierWithEmptyScheme(): void
);
}
- #[DataProvider('providerData')]
- #[TestDox('unit test: Test getSqlString() will produce expected sql and parameters based on
- a variety of provided arguments [uses data provider]')]
- public function testGetSqlString(Select $select, mixed $unused, mixed $unused2, string $expectedSqlString): void
+ /**
+ * @testdox unit test: Test getSqlString() will produce expected sql and parameters based on
+ * a variety of provided arguments [uses data provider]
+ * @covers \Laminas\Db\Sql\Select::getSqlString
+ * @dataProvider providerData
+ * @param mixed $unused
+ * @param mixed $unused2
+ */
+ public function testGetSqlString(Select $select, $unused, $unused2, string $expectedSqlString)
{
self::assertEquals($expectedSqlString, $select->getSqlString(new TrustingSql92Platform()));
}
- #[TestDox('unit test: Test __get() returns expected objects magically')]
- public function testMagicAccessor(): void
+ /**
+ * @testdox unit test: Test __get() returns expected objects magically
+ * @covers \Laminas\Db\Sql\Select::__get
+ */
+ public function testMagicAccessor()
{
$select = new Select();
self::assertInstanceOf(Where::class, $select->where);
}
- #[TestDox('unit test: Test __clone() will clone the where object so that this select can be used
- in multiple contexts')]
- public function testCloning(): void
+ /**
+ * @testdox unit test: Test __clone() will clone the where object so that this select can be used
+ * in multiple contexts
+ * @covers \Laminas\Db\Sql\Select::__clone
+ */
+ public function testCloning()
{
$select = new Select();
$select1 = clone $select;
@@ -713,13 +780,23 @@ public function testCloning(): void
}
/**
- * @throws ReflectionException
- * @return void
+ * @testdox unit test: Text process*() methods will return proper array when internally called,
+ * part of extension API
+ * @dataProvider providerData
+ * @covers \Laminas\Db\Sql\Select::processSelect
+ * @covers \Laminas\Db\Sql\Select::processJoins
+ * @covers \Laminas\Db\Sql\Select::processWhere
+ * @covers \Laminas\Db\Sql\Select::processGroup
+ * @covers \Laminas\Db\Sql\Select::processHaving
+ * @covers \Laminas\Db\Sql\Select::processOrder
+ * @covers \Laminas\Db\Sql\Select::processLimit
+ * @covers \Laminas\Db\Sql\Select::processOffset
+ * @covers \Laminas\Db\Sql\Select::processCombine
+ * @param mixed $unused
+ * @param mixed $unused2
+ * @param mixed $unused3
*/
- #[DataProvider('providerData')]
- #[TestDox('unit test: Text process*() methods will return proper array when internally called,
- part of extension API')]
- public function testProcessMethods(Select $select, mixed $unused, mixed $unused2, mixed $unused3, array $internalTests)
+ public function testProcessMethods(Select $select, $unused, $unused2, $unused3, array $internalTests)
{
if (! $internalTests) {
$this->expectNotToPerformAssertions();
@@ -727,20 +804,14 @@ public function testProcessMethods(Select $select, mixed $unused, mixed $unused2
}
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$parameterContainer = new ParameterContainer();
$sr = new ReflectionObject($select);
- /**
- * @var string $method
- * @var array $expected
- */
foreach ($internalTests as $method => $expected) {
$mr = $sr->getMethod($method);
- /** @psalm-suppress UnusedMethodCall */
$mr->setAccessible(true);
- /** @psalm-suppress MixedAssignment */
$return = $mr->invokeArgs($select, [new Sql92(), $mockDriver, $parameterContainer]);
self::assertEquals($expected, $return);
}
@@ -751,12 +822,12 @@ public function testProcessMethods(Select $select, mixed $unused, mixed $unused2
* 0: Select,
* 1: string,
* 2: array,
- * 3: string,
+ * 3 string,
* 4: array,
* 5: bool,
- * }>
+ * }
*/
- public static function providerData(): array
+ public function providerData(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
// basic table
@@ -1073,7 +1144,7 @@ public static function providerData(): array
// join with expression in ON part
$select31 = new Select();
- $select31->from('foo')->join('zac', new Predicate\Expression('(m = n AND c.x) BETWEEN x AND y.z'));
+ $select31->from('foo')->join('zac', new Expression('(m = n AND c.x) BETWEEN x AND y.z'));
$sqlPrep31 = // same
$sqlStr31 = 'SELECT "foo".*, "zac".* FROM "foo" INNER JOIN "zac" ON (m = n AND c.x) BETWEEN x AND y.z';
$internalTests31 = [
@@ -1137,13 +1208,14 @@ public static function providerData(): array
new Predicate\Operator('id', '=', 3),
new Predicate\Operator('number', '>', 20),
]));
- $sqlPrep36 = 'SELECT "foo".*, "tableA".*, "tableB".*, "tableC".* FROM "foo"'
+ $sqlPrep36 = 'SELECT "foo".*, "tableA".*, "tableB".*, "tableC".* FROM "foo"'
. ' INNER JOIN "tableA" ON "id" = :join1part1 INNER JOIN "tableB" ON "id" = :join2part1 '
. 'INNER JOIN "tableC" ON "id" = :join3part1 AND "number" > :join3part2';
- $sqlStr36 = 'SELECT "foo".*, "tableA".*, "tableB".*, "tableC".* FROM "foo" '
+ $sqlStr36 = 'SELECT "foo".*, "tableA".*, "tableB".*, "tableC".* FROM "foo" '
. 'INNER JOIN "tableA" ON "id" = \'1\' INNER JOIN "tableB" ON "id" = \'2\' '
. 'INNER JOIN "tableC" ON "id" = \'3\' AND "number" > \'20\'';
- $internalTests36 = [];
+ $internalTests36 = [];
+ $useNamedParams36 = true;
/**
* @link https://github.com/zendframework/zf2/pull/2714
@@ -1409,7 +1481,7 @@ public static function providerData(): array
[$select33, $sqlPrep33, [], $sqlStr33, $internalTests33, false],
[$select34, $sqlPrep34, [], $sqlStr34, $internalTests34, false],
[$select35, $sqlPrep35, [], $sqlStr35, $internalTests35, false],
- [$select36, $sqlPrep36, [], $sqlStr36, $internalTests36, true],
+ [$select36, $sqlPrep36, [], $sqlStr36, $internalTests36, $useNamedParams36],
[$select37, $sqlPrep37, [], $sqlStr37, $internalTests37, false],
[$select38, $sqlPrep38, [], $sqlStr38, $internalTests38, false],
[$select39, $sqlPrep39, [], $sqlStr39, $internalTests39, false],
diff --git a/test/unit/Sql/SqlFunctionalTest.php b/test/unit/Sql/SqlFunctionalTest.php
index 35dba7167..7245cf808 100644
--- a/test/unit/Sql/SqlFunctionalTest.php
+++ b/test/unit/Sql/SqlFunctionalTest.php
@@ -4,24 +4,17 @@
use Laminas\Db\Adapter;
use Laminas\Db\Adapter\Driver\DriverInterface;
-use Laminas\Db\Adapter\Driver\StatementInterface;
-use Laminas\Db\Adapter\ParameterContainer;
-use Laminas\Db\Adapter\StatementContainer;
use Laminas\Db\Sql;
+use Laminas\Db\Sql\AbstractSql;
use Laminas\Db\Sql\Ddl\Column\Column;
use Laminas\Db\Sql\Ddl\CreateTable;
use Laminas\Db\Sql\Delete;
use Laminas\Db\Sql\Expression;
use Laminas\Db\Sql\Insert;
use Laminas\Db\Sql\Platform\PlatformDecoratorInterface;
-use Laminas\Db\Sql\PreparableSqlInterface;
use Laminas\Db\Sql\Select;
-use Laminas\Db\Sql\SqlInterface;
-use Laminas\Db\Sql\TableIdentifier;
use Laminas\Db\Sql\Update;
use LaminasTest\Db\TestAsset;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function array_merge;
@@ -29,21 +22,48 @@
use function is_string;
/**
- * @method Select select(string|array|null $sqlString)
- * @method Update update(TableIdentifier|null|string $sqlString)
- * @method Delete delete(TableIdentifier|null|string $sqlString)
- * @method Insert insert(TableIdentifier|null|string $sqlString)
- * @method CreateTable createTable(null|string|TableIdentifier $sqlString)
- * @method Column createColumn(null|string $sqlString)
+ * @method Select select(null|string $table)
+ * @method Update update(null|string $table)
+ * @method Delete delete(null|string $table)
+ * @method Insert insert(null|string $table)
+ * @method CreateTable createTable(null|string $table)
+ * @method Column createColumn(null|string $name)
*/
-final class SqlFunctionalTest extends TestCase
+class SqlFunctionalTest extends TestCase
{
- protected static function dataProviderCommonProcessMethods(): array
+ /**
+ * @psalm-return array
+ * },
+ * MySql: {
+ * string: string,
+ * prepare: string,
+ * parameters: array
+ * },
+ * Oracle: {
+ * string: string,
+ * prepare: string,
+ * parameters: array
+ * },
+ * SqlServer: {
+ * string: string,
+ * prepare: string,
+ * parameters: array
+ * }
+ * }
+ * }>
+ */
+ protected function dataProviderCommonProcessMethods(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
return [
'Select::processOffset()' => [
- 'sqlObject' => self::select('foo')->offset(10),
+ 'sqlObject' => $this->select('foo')->offset(10),
'expected' => [
'sql92' => [
'string' => 'SELECT "foo".* FROM "foo" OFFSET \'10\'',
@@ -68,7 +88,7 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Select::processLimit()' => [
- 'sqlObject' => self::select('foo')->limit(10),
+ 'sqlObject' => $this->select('foo')->limit(10),
'expected' => [
'sql92' => [
'string' => 'SELECT "foo".* FROM "foo" LIMIT \'10\'',
@@ -93,7 +113,7 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Select::processLimitOffset()' => [
- 'sqlObject' => self::select('foo')->limit(10)->offset(5),
+ 'sqlObject' => $this->select('foo')->limit(10)->offset(5),
'expected' => [
'sql92' => [
'string' => 'SELECT "foo".* FROM "foo" LIMIT \'10\' OFFSET \'5\'',
@@ -119,11 +139,11 @@ protected static function dataProviderCommonProcessMethods(): array
],
// Github issue https://github.com/zendframework/zend-db/issues/98
'Select::processJoinNoJoinedColumns()' => [
- 'sqlObject' => self::select('my_table')
+ 'sqlObject' => $this->select('my_table')
->join(
'joined_table2',
'my_table.id = joined_table2.id',
- []
+ $columns = []
)
->join(
'joined_table3',
@@ -150,8 +170,8 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Select::processJoin()' => [
- 'sqlObject' => self::select('a')
- ->join(['b' => self::select('c')->where(['cc' => 10])], 'd=e')->where(['x' => 20]),
+ 'sqlObject' => $this->select('a')
+ ->join(['b' => $this->select('c')->where(['cc' => 10])], 'd=e')->where(['x' => 20]),
'expected' => [
'sql92' => [
'string' => 'SELECT "a".*, "b".* FROM "a" INNER JOIN (SELECT "c".* FROM "c" WHERE "cc" = \'10\') AS "b" ON "d"="e" WHERE "x" = \'20\'',
@@ -176,11 +196,11 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Ddl::CreateTable::processColumns()' => [
- 'sqlObject' => self::createTable('foo')
- ->addColumn(self::createColumn('col1')
+ 'sqlObject' => $this->createTable('foo')
+ ->addColumn($this->createColumn('col1')
->setOption('identity', true)
->setOption('comment', 'Comment1'))
- ->addColumn(self::createColumn('col2')
+ ->addColumn($this->createColumn('col2')
->setOption('identity', true)
->setOption('comment', 'Comment2')),
'expected' => [
@@ -191,7 +211,7 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Ddl::CreateTable::processTable()' => [
- 'sqlObject' => self::createTable('foo')->setTemporary(true),
+ 'sqlObject' => $this->createTable('foo')->setTemporary(true),
'expected' => [
'sql92' => "CREATE TEMPORARY TABLE \"foo\" ( \n)",
'MySql' => "CREATE TEMPORARY TABLE `foo` ( \n)",
@@ -200,12 +220,14 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Select::processSubSelect()' => [
- 'sqlObject' => self::select([
- 'a' => self::select([
- 'b' => self::select('c')->where(['cc' => 'CC']),
- ])
+ 'sqlObject' => $this
+ ->select([
+ 'a' => $this
+ ->select([
+ 'b' => $this->select('c')->where(['cc' => 'CC']),
+ ])
->where(['bb' => 'BB']),
- ])
+ ])
->where(['aa' => 'AA']),
'expected' => [
'sql92' => [
@@ -231,7 +253,7 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Delete::processSubSelect()' => [
- 'sqlObject' => self::delete('foo')->where(['x' => self::select('foo')->where(['x' => 'y'])]),
+ 'sqlObject' => $this->delete('foo')->where(['x' => $this->select('foo')->where(['x' => 'y'])]),
'expected' => [
'sql92' => [
'string' => 'DELETE FROM "foo" WHERE "x" = (SELECT "foo".* FROM "foo" WHERE "x" = \'y\')',
@@ -256,7 +278,7 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Update::processSubSelect()' => [
- 'sqlObject' => self::update('foo')->set(['x' => self::select('foo')]),
+ 'sqlObject' => $this->update('foo')->set(['x' => $this->select('foo')]),
'expected' => [
'sql92' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo")',
'MySql' => 'UPDATE `foo` SET `x` = (SELECT `foo`.* FROM `foo`)',
@@ -265,7 +287,7 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Insert::processSubSelect()' => [
- 'sqlObject' => self::insert('foo')->select(self::select('foo')->where(['x' => 'y'])),
+ 'sqlObject' => $this->insert('foo')->select($this->select('foo')->where(['x' => 'y'])),
'expected' => [
'sql92' => [
'string' => 'INSERT INTO "foo" SELECT "foo".* FROM "foo" WHERE "x" = \'y\'',
@@ -290,8 +312,8 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Update::processExpression()' => [
- 'sqlObject' => self::update('foo')->set(
- ['x' => new Sql\Expression('?', [self::select('foo')->where(['x' => 'y'])])]
+ 'sqlObject' => $this->update('foo')->set(
+ ['x' => new Sql\Expression('?', [$this->select('foo')->where(['x' => 'y'])])]
),
'expected' => [
'sql92' => [
@@ -317,7 +339,7 @@ protected static function dataProviderCommonProcessMethods(): array
],
],
'Update::processJoins()' => [
- 'sqlObject' => self::update('foo')->set(['x' => 'y'])->where(['xx' => 'yy'])->join(
+ 'sqlObject' => $this->update('foo')->set(['x' => 'y'])->where(['xx' => 'yy'])->join(
'bar',
'bar.barId = foo.barId'
),
@@ -340,11 +362,34 @@ protected static function dataProviderCommonProcessMethods(): array
// phpcs:enable Generic.Files.LineLength.TooLong
}
- protected static function dataProviderDecorators(): array
+ /**
+ * @psalm-return array,
+ * string: string
+ * },
+ * MySql: array{
+ * decorators: array,
+ * string: string
+ * },
+ * Oracle: array{
+ * decorators: array,
+ * string: string
+ * },
+ * SqlServer: array{
+ * decorators: array,
+ * string: string
+ * }
+ * }
+ * }>
+ */
+ protected function dataProviderDecorators(): array
{
return [
'RootDecorators::Select' => [
- 'sqlObject' => self::select('foo')->where(['x' => self::select('bar')]),
+ 'sqlObject' => $this->select('foo')->where(['x' => $this->select('bar')]),
'expected' => [
'sql92' => [
'decorators' => [
@@ -375,7 +420,7 @@ protected static function dataProviderDecorators(): array
// phpcs:disable Generic.Files.LineLength.TooLong
/* TODO - should be implemented
'RootDecorators::Insert' => array(
- 'sqlObject' => self::insert('foo')->select(self::select()),
+ 'sqlObject' => $this->insert('foo')->select($this->select()),
'expected' => array(
'sql92' => array(
'decorators' => array(
@@ -408,7 +453,7 @@ protected static function dataProviderDecorators(): array
),
),
'RootDecorators::Delete' => array(
- 'sqlObject' => self::delete('foo')->where(array('x'=>self::select('foo'))),
+ 'sqlObject' => $this->delete('foo')->where(array('x'=>$this->select('foo'))),
'expected' => array(
'sql92' => array(
'decorators' => array(
@@ -441,7 +486,7 @@ protected static function dataProviderDecorators(): array
),
),
'RootDecorators::Update' => array(
- 'sqlObject' => self::update('foo')->where(array('x'=>self::select('foo'))),
+ 'sqlObject' => $this->update('foo')->where(array('x'=>$this->select('foo'))),
'expected' => array(
'sql92' => array(
'decorators' => array(
@@ -474,7 +519,7 @@ protected static function dataProviderDecorators(): array
),
),
'DecorableExpression()' => array(
- 'sqlObject' => self::update('foo')->where(array('x'=>new Sql\Expression('?', array(self::select('foo'))))),
+ 'sqlObject' => $this->update('foo')->where(array('x'=>new Sql\Expression('?', array($this->select('foo'))))),
'expected' => array(
'sql92' => array(
'decorators' => array(
@@ -510,20 +555,44 @@ protected static function dataProviderDecorators(): array
];
}
- public static function dataProvider(): array
+ /**
+ * @psalm-return array
+ * },
+ * MySql: array{
+ * string: string,
+ * prepare: string,
+ * parameters: array
+ * },
+ * Oracle: array{
+ * string: string,
+ * prepare: string,
+ * parameters: array
+ * },
+ * SqlServer: array{
+ * string: string,
+ * prepare: string,
+ * parameters: array
+ * },
+ * }
+ * }>
+ */
+ public function dataProvider(): array
{
$data = array_merge(
- self::dataProviderCommonProcessMethods(),
- self::dataProviderDecorators()
+ $this->dataProviderCommonProcessMethods(),
+ $this->dataProviderDecorators()
);
$res = [];
foreach ($data as $index => $test) {
- self::assertIsArray($test);
- $testExpected = $test['expected'] ?? [];
- self::assertIsArray($testExpected);
- /** @psalm-suppress MixedAssignment */
- foreach ($testExpected as $platform => $expected) {
+ foreach ($test['expected'] as $platform => $expected) {
$res[$index . '->' . $platform] = [
'sqlObject' => $test['sqlObject'],
'platform' => $platform,
@@ -531,64 +600,54 @@ public static function dataProvider(): array
];
}
}
-
return $res;
}
/**
- * @param PreparableSqlInterface|SqlInterface $sqlObject
- * @param string $platform
- * @param array|string $expected
+ * @param type $sqlObject
+ * @param type $platform
+ * @param type $expected
+ * @dataProvider dataProvider
*/
- #[DataProvider('dataProvider')]
- public function test(PreparableSqlInterface|SqlInterface $sqlObject, string $platform, string|array $expected): void
+ public function test($sqlObject, $platform, $expected)
{
$sql = new Sql\Sql($this->resolveAdapter($platform));
if (is_array($expected) && isset($expected['decorators'])) {
- /** @var PlatformDecoratorInterface|array $decorator */
foreach ($expected['decorators'] as $type => $decorator) {
- self::assertIsString($type);
- $decorator = $this->resolveDecorator($decorator);
- $this->assertInstanceOf(PlatformDecoratorInterface::class, $decorator);
-
- $platform = $sql->getSqlPlatform();
- $this->assertNotNull($platform);
- $platform->setTypeDecorator($type, $decorator);
+ $sql->getSqlPlatform()->setTypeDecorator($type, $this->resolveDecorator($decorator));
}
}
- $expectedString = is_string($expected) ? $expected : (string) $expected['string'];
- if ($expectedString !== '') {
- self::assertInstanceOf(SqlInterface::class, $sqlObject);
+ $expectedString = is_string($expected) ? $expected : ($expected['string'] ?? null);
+ if ($expectedString) {
$actual = $sql->buildSqlString($sqlObject);
self::assertEquals($expectedString, $actual, "getSqlString()");
}
if (is_array($expected) && isset($expected['prepare'])) {
- self::assertInstanceOf(PreparableSqlInterface::class, $sqlObject);
- /** @var StatementInterface|StatementContainer $actual */
$actual = $sql->prepareStatementForSqlObject($sqlObject);
self::assertEquals($expected['prepare'], $actual->getSql(), "prepareStatement()");
if (isset($expected['parameters'])) {
- $parametersContainer = $actual->getParameterContainer();
- self::assertInstanceOf(ParameterContainer::class, $parametersContainer);
- $actual = $parametersContainer->getNamedArray();
+ $actual = $actual->getParameterContainer()->getNamedArray();
self::assertSame($expected['parameters'], $actual, "parameterContainer()");
}
}
}
- protected function resolveDecorator(
- PlatformDecoratorInterface|array $decorator
- ): PlatformDecoratorInterface|MockObject|null {
+ /**
+ * @param array|Sql\Platform\PlatformDecoratorInterface $decorator
+ * @psalm-param array{0: class-string, 1: * string}|Sql\Platform\PlatformDecoratorInterface $decorator
+ * @return null|PlatformDecoratorInterface
+ * @psalm-return null|PlatformDecoratorInterface|PlatformDecoratorInterface&MockObject
+ */
+ protected function resolveDecorator($decorator)
+ {
if (is_array($decorator)) {
- /** @var class-string $classString */
- $classString = $decorator[0];
- $decoratorMock = $this->getMockBuilder($classString)
- ->onlyMethods(['buildSqlString'])
+ $decoratorMock = $this->getMockBuilder($decorator[0])
+ ->setMethods(['buildSqlString'])
->setConstructorArgs([null])
->getMock();
- $decoratorMock->expects($this->any())->method('buildSqlString')->willReturn($decorator[1]);
+ $decoratorMock->expects($this->any())->method('buildSqlString')->will($this->returnValue($decorator[1]));
return $decoratorMock;
}
@@ -601,48 +660,53 @@ protected function resolveDecorator(
protected function resolveAdapter(string $platform): Adapter\Adapter
{
- $platform = match ($platform) {
- 'sql92' => new TestAsset\TrustingSql92Platform(),
- 'MySql' => new TestAsset\TrustingMysqlPlatform(),
- 'Oracle' => new TestAsset\TrustingOraclePlatform(),
- 'SqlServer' => new TestAsset\TrustingSqlServerPlatform(),
- default => null,
- };
+ switch ($platform) {
+ case 'sql92':
+ $platform = new TestAsset\TrustingSql92Platform();
+ break;
+ case 'MySql':
+ $platform = new TestAsset\TrustingMysqlPlatform();
+ break;
+ case 'Oracle':
+ $platform = new TestAsset\TrustingOraclePlatform();
+ break;
+ case 'SqlServer':
+ $platform = new TestAsset\TrustingSqlServerPlatform();
+ break;
+ default:
+ $platform = null;
+ }
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
- $mockDriver->expects($this->any())->method('createStatement')->willReturnCallback(fn() => new Adapter\StatementContainer());
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnCallback(function () {
+ return new Adapter\StatementContainer();
+ }));
return new Adapter\Adapter($mockDriver, $platform);
}
- protected static function select(string|array|null $sqlString): Sql\Select
- {
- return new Sql\Select($sqlString);
- }
-
- protected static function delete(string|TableIdentifier|null $sqlString): Sql\Delete
- {
- return new Sql\Delete($sqlString);
- }
-
- protected static function update(string|TableIdentifier|null $sqlString): Sql\Update
- {
- return new Sql\Update($sqlString);
- }
-
- protected static function insert(string|TableIdentifier|null $sqlString): Sql\Insert
- {
- return new Sql\Insert($sqlString);
- }
-
- protected static function createTable(string|TableIdentifier $sqlString): Sql\Ddl\CreateTable
- {
- return new Sql\Ddl\CreateTable($sqlString);
- }
-
- protected static function createColumn(?string $sqlString): Sql\Ddl\Column\Column
+ /**
+ * @param string $name
+ * @param array $arguments
+ * @return AbstractSql
+ */
+ public function __call($name, $arguments)
{
- return new Sql\Ddl\Column\Column($sqlString);
+ $arg0 = $arguments[0] ?? null;
+ switch ($name) {
+ case 'select':
+ return new Sql\Select($arg0);
+ case 'delete':
+ return new Sql\Delete($arg0);
+ case 'update':
+ return new Sql\Update($arg0);
+ case 'insert':
+ return new Sql\Insert($arg0);
+ case 'createTable':
+ return new Sql\Ddl\CreateTable($arg0);
+ case 'createColumn':
+ return new Sql\Ddl\Column\Column($arg0);
+ }
}
}
diff --git a/test/unit/Sql/SqlTest.php b/test/unit/Sql/SqlTest.php
index a79c00955..0dddbcae0 100644
--- a/test/unit/Sql/SqlTest.php
+++ b/test/unit/Sql/SqlTest.php
@@ -14,62 +14,48 @@
use Laminas\Db\Sql\Sql;
use Laminas\Db\Sql\Update;
use LaminasTest\Db\TestAsset;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use TypeError;
-#[CoversMethod(Sql::class, '__construct')]
-#[CoversMethod(Sql::class, 'select')]
-#[CoversMethod(Sql::class, 'insert')]
-#[CoversMethod(Sql::class, 'update')]
-#[CoversMethod(Sql::class, 'delete')]
-#[CoversMethod(Sql::class, 'prepareStatementForSqlObject')]
-final class SqlTest extends TestCase
+class SqlTest extends TestCase
{
- protected MockObject&Adapter $mockAdapter;
+ /** @var Adapter&MockObject */
+ protected $mockAdapter;
/**
* Sql object
+ *
+ * @var Sql
*/
- protected Sql $sql;
+ protected $sql;
- /**
- * @throws Exception
- */
- #[Override]
protected function setUp(): void
{
// mock the adapter, driver, and parts
- $mockResult = $this->createMock(ResultInterface::class);
-
- $mockStatement = $this->createMock(StatementInterface::class);
- $mockStatement->expects($this->any())->method('execute')->willReturn($mockResult::class);
-
- $mockConnection = $this->getMockBuilder(ConnectionInterface::class)->onlyMethods([])->getMock();
-
- $mockDriver = $this->getMockBuilder(DriverInterface::class)->onlyMethods([])->getMock();
- $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement);
- $mockDriver->expects($this->any())->method('getConnection')->willReturn($mockConnection);
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockResult = $this->getMockBuilder(ResultInterface::class)->getMock();
+ $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
+ $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
+ $mockConnection = $this->getMockBuilder(ConnectionInterface::class)->getMock();
+ $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
+ $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
// setup mock adapter
$this->mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
- ->setConstructorArgs([
- $mockDriver,
- new TestAsset\TrustingSql92Platform(),
- ])
+ ->setMethods()
+ ->setConstructorArgs([$mockDriver, new TestAsset\TrustingSql92Platform()])
->getMock();
$this->sql = new Sql($this->mockAdapter, 'foo');
}
+ /**
+ * @covers \Laminas\Db\Sql\Sql::__construct
+ */
// @codingStandardsIgnoreStart
- public function test__construct(): void
+ public function test__construct()
{
// @codingStandardsIgnoreEnd
$sql = new Sql($this->mockAdapter);
@@ -80,11 +66,13 @@ public function test__construct(): void
self::assertSame('foo', $sql->getTable());
$this->expectException(TypeError::class);
- /** @psalm-suppress NullArgument - ensure an exception is thrown */
$sql->setTable(null);
}
- public function testSelect(): void
+ /**
+ * @covers \Laminas\Db\Sql\Sql::select
+ */
+ public function testSelect()
{
$select = $this->sql->select();
self::assertInstanceOf(Select::class, $select);
@@ -97,7 +85,10 @@ public function testSelect(): void
$this->sql->select('bar');
}
- public function testInsert(): void
+ /**
+ * @covers \Laminas\Db\Sql\Sql::insert
+ */
+ public function testInsert()
{
$insert = $this->sql->insert();
self::assertInstanceOf(Insert::class, $insert);
@@ -110,7 +101,10 @@ public function testInsert(): void
$this->sql->insert('bar');
}
- public function testUpdate(): void
+ /**
+ * @covers \Laminas\Db\Sql\Sql::update
+ */
+ public function testUpdate()
{
$update = $this->sql->update();
self::assertInstanceOf(Update::class, $update);
@@ -123,7 +117,10 @@ public function testUpdate(): void
$this->sql->update('bar');
}
- public function testDelete(): void
+ /**
+ * @covers \Laminas\Db\Sql\Sql::delete
+ */
+ public function testDelete()
{
$delete = $this->sql->delete();
@@ -137,7 +134,10 @@ public function testDelete(): void
$this->sql->delete('bar');
}
- public function testPrepareStatementForSqlObject(): void
+ /**
+ * @covers \Laminas\Db\Sql\Sql::prepareStatementForSqlObject
+ */
+ public function testPrepareStatementForSqlObject()
{
$insert = $this->sql->insert()->columns(['foo'])->values(['foo' => 'bar']);
$stmt = $this->sql->prepareStatementForSqlObject($insert);
@@ -145,10 +145,9 @@ public function testPrepareStatementForSqlObject(): void
}
/**
- * @throws Exception
+ * @group 6890
*/
- #[Group('6890')]
- public function testForDifferentAdapters(): void
+ public function testForDifferentAdapters()
{
$adapterSql92 = $this->getAdapterForPlatform('sql92');
$adapterMySql = $this->getAdapterForPlatform('MySql');
@@ -162,14 +161,7 @@ public function testForDifferentAdapters(): void
'SELECT "foo".* FROM "foo" OFFSET \'10\'',
$this->sql->buildSqlString($select)
);
-
- $stmt = $this
- ->mockAdapter
- ->getDriver()
- ->createStatement();
-
- /** @var MockObject&StatementInterface $stmt */
- $stmt->expects($this->any())->method('setSql')
+ $this->mockAdapter->getDriver()->createStatement()->expects($this->any())->method('setSql')
->with($this->equalTo('SELECT "foo".* FROM "foo" OFFSET ?'));
$this->sql->prepareStatementForSqlObject($select);
@@ -178,12 +170,7 @@ public function testForDifferentAdapters(): void
'SELECT "foo".* FROM "foo" OFFSET \'10\'',
$this->sql->buildSqlString($select, $adapterSql92)
);
- $stmt = $adapterSql92
- ->getDriver()
- ->createStatement();
-
- /** @var MockObject&StatementInterface $stmt */
- $stmt->expects($this->any())->method('setSql')
+ $adapterSql92->getDriver()->createStatement()->expects($this->any())->method('setSql')
->with($this->equalTo('SELECT "foo".* FROM "foo" OFFSET ?'));
$this->sql->prepareStatementForSqlObject($select, null, $adapterSql92);
@@ -192,12 +179,7 @@ public function testForDifferentAdapters(): void
'SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET 10',
$this->sql->buildSqlString($select, $adapterMySql)
);
- $stmt = $adapterMySql
- ->getDriver()
- ->createStatement();
-
- /** @var MockObject&StatementInterface $stmt */
- $stmt->expects($this->any())->method('setSql')
+ $adapterMySql->getDriver()->createStatement()->expects($this->any())->method('setSql')
->with($this->equalTo('SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET ?'));
$this->sql->prepareStatementForSqlObject($select, null, $adapterMySql);
@@ -206,14 +188,8 @@ public function testForDifferentAdapters(): void
'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b ) WHERE b_rownum > (10)',
$this->sql->buildSqlString($select, $adapterOracle)
);
-
- $stmt = $adapterOracle
- ->getDriver()
- ->createStatement();
-
// @codingStandardsIgnoreStart
- /** @var MockObject&StatementInterface $stmt */
- $stmt->expects($this->any())->method('setSql')
+ $adapterOracle->getDriver()->createStatement()->expects($this->any())->method('setSql')
->with($this->equalTo('SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b ) WHERE b_rownum > (:offset)'));
// @codingStandardsIgnoreEnd
$this->sql->prepareStatementForSqlObject($select, null, $adapterOracle);
@@ -223,13 +199,7 @@ public function testForDifferentAdapters(): void
'WHERE [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__LAMINAS_ROW_NUMBER] BETWEEN 10+1 AND 0+10',
$this->sql->buildSqlString($select, $adapterSqlServer)
);
-
- $stmt = $adapterSqlServer
- ->getDriver()
- ->createStatement();
-
- /** @var MockObject&StatementInterface $stmt */
- $stmt->expects($this->any())->method('setSql')
+ $adapterSqlServer->getDriver()->createStatement()->expects($this->any())->method('setSql')
->with($this->stringContains(
'WHERE [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__LAMINAS_ROW_NUMBER] BETWEEN ?+1 AND ?+?'
));
@@ -239,26 +209,32 @@ public function testForDifferentAdapters(): void
/**
* Data provider
*
- * @throws Exception
+ * @param string $platform
+ * @return Adapter
*/
- protected function getAdapterForPlatform(string $platform): Adapter
+ protected function getAdapterForPlatform($platform)
{
- $platform = match ($platform) {
- 'sql92' => new TestAsset\TrustingSql92Platform(),
- 'MySql' => new TestAsset\TrustingMysqlPlatform(),
- 'Oracle' => new TestAsset\TrustingOraclePlatform(),
- 'SqlServer' => new TestAsset\TrustingSqlServerPlatform(),
- default => null,
- };
-
- $mockResult = $this->createMock(ResultInterface::class);
-
- $mockStatement = $this->createMock(StatementInterface::class);
- $mockStatement->expects($this->any())->method('execute')->willReturn($mockResult::class);
-
- $mockDriver = $this->getMockBuilder(DriverInterface::class)->onlyMethods([])->getMock();
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
- $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement);
+ switch ($platform) {
+ case 'sql92':
+ $platform = new TestAsset\TrustingSql92Platform();
+ break;
+ case 'MySql':
+ $platform = new TestAsset\TrustingMysqlPlatform();
+ break;
+ case 'Oracle':
+ $platform = new TestAsset\TrustingOraclePlatform();
+ break;
+ case 'SqlServer':
+ $platform = new TestAsset\TrustingSqlServerPlatform();
+ break;
+ default:
+ $platform = null;
+ }
+
+ $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
+ $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
return new Adapter($mockDriver, $platform);
}
diff --git a/test/unit/Sql/TableIdentifierTest.php b/test/unit/Sql/TableIdentifierTest.php
index 81eacf9f2..889842cd0 100644
--- a/test/unit/Sql/TableIdentifierTest.php
+++ b/test/unit/Sql/TableIdentifierTest.php
@@ -4,9 +4,6 @@
use Laminas\Db\Sql\Exception\InvalidArgumentException;
use Laminas\Db\Sql\TableIdentifier;
-use LaminasTest\Db\TestAsset\ObjectToString;
-use PHPUnit\Framework\Attributes\CoversClass;
-use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use stdClass;
use TypeError;
@@ -14,88 +11,98 @@
use function array_merge;
/**
- * Tests for {@see TableIdentifier}
+ * Tests for {@see \Laminas\Db\Sql\TableIdentifier}
+ *
+ * @covers \Laminas\Db\Sql\TableIdentifier
*/
-#[CoversClass(TableIdentifier::class)]
-final class TableIdentifierTest extends TestCase
+class TableIdentifierTest extends TestCase
{
- public function testGetTable(): void
+ public function testGetTable()
{
$tableIdentifier = new TableIdentifier('foo');
self::assertSame('foo', $tableIdentifier->getTable());
}
- public function testGetDefaultSchema(): void
+ public function testGetDefaultSchema()
{
$tableIdentifier = new TableIdentifier('foo');
self::assertNull($tableIdentifier->getSchema());
}
- public function testGetSchema(): void
+ public function testGetSchema()
{
$tableIdentifier = new TableIdentifier('foo', 'bar');
self::assertSame('bar', $tableIdentifier->getSchema());
}
- public function testGetTableFromObjectStringCast(): void
+ public function testGetTableFromObjectStringCast()
{
- $table = new ObjectToString('castResult');
+ $table = $this->getMockBuilder('stdClass')->setMethods(['__toString'])->getMock();
+
+ $table->expects($this->once())->method('__toString')->will($this->returnValue('castResult'));
+
$tableIdentifier = new TableIdentifier((string) $table);
self::assertSame('castResult', $tableIdentifier->getTable());
self::assertSame('castResult', $tableIdentifier->getTable());
}
- /**
- * @todo Review test to see if relevant?
- */
- public function testGetSchemaFromObjectStringCast(): void
+ public function testGetSchemaFromObjectStringCast()
{
- $schema = new ObjectToString('castResult');
+ $schema = $this->getMockBuilder('stdClass')->setMethods(['__toString'])->getMock();
+
+ $schema->expects($this->once())->method('__toString')->will($this->returnValue('castResult'));
+
$tableIdentifier = new TableIdentifier('foo', (string) $schema);
self::assertSame('castResult', $tableIdentifier->getSchema());
self::assertSame('castResult', $tableIdentifier->getSchema());
}
- #[DataProvider('invalidTableProvider')]
- public function testRejectsInvalidTable(mixed $invalidTable): void
+ /**
+ * @dataProvider invalidTableProvider
+ * @param mixed $invalidTable
+ */
+ public function testRejectsInvalidTable($invalidTable)
{
$this->expectException($invalidTable === '' ? InvalidArgumentException::class : TypeError::class);
- /** @psalm-suppress MixedArgument */
+
new TableIdentifier($invalidTable);
}
- #[DataProvider('invalidSchemaProvider')]
- public function testRejectsInvalidSchema(mixed $invalidSchema): void
+ /**
+ * @dataProvider invalidSchemaProvider
+ * @param mixed $invalidSchema
+ */
+ public function testRejectsInvalidSchema($invalidSchema)
{
$this->expectException($invalidSchema === '' ? InvalidArgumentException::class : TypeError::class);
- /** @psalm-suppress MixedArgument */
+
new TableIdentifier('foo', $invalidSchema);
}
/**
* Data provider
*
- * @return array[]
+ * @return mixed[][]
*/
- public static function invalidTableProvider(): array
+ public function invalidTableProvider()
{
return array_merge(
[[null]],
- self::invalidSchemaProvider()
+ $this->invalidSchemaProvider()
);
}
/**
* Data provider
*
- * @return array[]
+ * @return mixed[][]
*/
- public static function invalidSchemaProvider(): array
+ public function invalidSchemaProvider()
{
return [
[''],
diff --git a/test/unit/Sql/UpdateTest.php b/test/unit/Sql/UpdateTest.php
index 289f0c53a..ae5fadf91 100644
--- a/test/unit/Sql/UpdateTest.php
+++ b/test/unit/Sql/UpdateTest.php
@@ -14,53 +14,44 @@
use Laminas\Db\Sql\Predicate\IsNull;
use Laminas\Db\Sql\Predicate\Literal;
use Laminas\Db\Sql\Predicate\Operator;
-use Laminas\Db\Sql\Predicate\PredicateSet;
use Laminas\Db\Sql\TableIdentifier;
use Laminas\Db\Sql\Update;
use Laminas\Db\Sql\Where;
use LaminasTest\Db\DeprecatedAssertionsTrait;
use LaminasTest\Db\TestAsset\TrustingSql92Platform;
use LaminasTest\Db\TestAsset\UpdateIgnore;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\CoversNothing;
-use PHPUnit\Framework\Attributes\Group;
-use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
-use ReflectionException;
-
-#[CoversMethod(Update::class, 'table')]
-#[CoversMethod(Update::class, '__construct')]
-#[CoversMethod(Update::class, 'set')]
-#[CoversMethod(Update::class, 'where')]
-#[CoversMethod(Update::class, 'getRawState')]
-#[CoversMethod(Update::class, 'prepareStatement')]
-#[CoversMethod(Update::class, 'getSqlString')]
-#[CoversMethod(Update::class, '__get')]
-#[CoversMethod(Update::class, '__clone')]
-#[CoversMethod(Update::class, 'join')]
-final class UpdateTest extends TestCase
+
+class UpdateTest extends TestCase
{
use DeprecatedAssertionsTrait;
- protected Update $update;
+ /** @var Update */
+ protected $update;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
$this->update = new Update();
}
/**
- * @throws ReflectionException
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
*/
- public function testTable(): void
+ protected function tearDown(): void
{
- $this->update->table('foo');
+ }
+
+ /**
+ * @covers \Laminas\Db\Sql\Update::table
+ */
+ public function testTable()
+ {
+ $this->update->table('foo', 'bar');
self::assertEquals('foo', $this->readAttribute($this->update, 'table'));
$tableIdentifier = new TableIdentifier('foo', 'bar');
@@ -69,27 +60,33 @@ public function testTable(): void
}
/**
- * @throws ReflectionException
+ * @covers \Laminas\Db\Sql\Update::__construct
*/
- public function testConstruct(): void
+ public function testConstruct()
{
$update = new Update('foo');
self::assertEquals('foo', $this->readAttribute($update, 'table'));
}
- public function testSet(): void
+ /**
+ * @covers \Laminas\Db\Sql\Update::set
+ */
+ public function testSet()
{
$this->update->set(['foo' => 'bar']);
self::assertEquals(['foo' => 'bar'], $this->update->getRawState('set'));
}
- public function testSortableSet(): void
+ /**
+ * @covers \Laminas\Db\Sql\Update::set
+ */
+ public function testSortableSet()
{
$this->update->set([
'two' => 'с_two',
'three' => 'с_three',
]);
- $this->update->set(['one' => 'с_one'], '10');
+ $this->update->set(['one' => 'с_one'], 10);
self::assertEquals(
[
@@ -102,60 +99,59 @@ public function testSortableSet(): void
}
/**
- * @throws ReflectionException
+ * @covers \Laminas\Db\Sql\Update::where
*/
- public function testWhere(): void
+ public function testWhere()
{
$this->update->where('x = y');
$this->update->where(['foo > ?' => 5]);
$this->update->where(['id' => 2]);
- $this->update->where(['a = b'], PredicateSet::OP_OR);
+ $this->update->where(['a = b'], Where::OP_OR);
$this->update->where(['c1' => null]);
$this->update->where(['c2' => [1, 2, 3]]);
$this->update->where([new IsNotNull('c3')]);
$where = $this->update->where;
$predicates = $this->readAttribute($where, 'predicates');
+ self::assertEquals('AND', $predicates[0][0]);
+ self::assertInstanceOf(Literal::class, $predicates[0][1]);
- self::assertIsArray($predicates);
-
- self::assertEquals('AND', $predicates[0][0] ?? '');
- self::assertInstanceOf(Literal::class, $predicates[0][1] ?? null);
-
- self::assertEquals('AND', $predicates[1][0] ?? '');
- self::assertInstanceOf(\Laminas\Db\Sql\Predicate\Expression::class, $predicates[1][1] ?? null);
+ self::assertEquals('AND', $predicates[1][0]);
+ self::assertInstanceOf(\Laminas\Db\Sql\Predicate\Expression::class, $predicates[1][1]);
- self::assertEquals('AND', $predicates[2][0] ?? '');
- self::assertInstanceOf(Operator::class, $predicates[2][1] ?? null);
+ self::assertEquals('AND', $predicates[2][0]);
+ self::assertInstanceOf(Operator::class, $predicates[2][1]);
- self::assertEquals('OR', $predicates[3][0] ?? '');
- self::assertInstanceOf(Literal::class, $predicates[3][1] ?? null);
+ self::assertEquals('OR', $predicates[3][0]);
+ self::assertInstanceOf(Literal::class, $predicates[3][1]);
- self::assertEquals('AND', $predicates[4][0] ?? '');
- self::assertInstanceOf(IsNull::class, $predicates[4][1] ?? null);
+ self::assertEquals('AND', $predicates[4][0]);
+ self::assertInstanceOf(IsNull::class, $predicates[4][1]);
- self::assertEquals('AND', $predicates[5][0] ?? '');
- self::assertInstanceOf(In::class, $predicates[5][1] ?? null);
+ self::assertEquals('AND', $predicates[5][0]);
+ self::assertInstanceOf(In::class, $predicates[5][1]);
- self::assertEquals('AND', $predicates[6][0] ?? '');
- self::assertInstanceOf(IsNotNull::class, $predicates[6][1] ?? null);
+ self::assertEquals('AND', $predicates[6][0]);
+ self::assertInstanceOf(IsNotNull::class, $predicates[6][1]);
$where = new Where();
$this->update->where($where);
self::assertSame($where, $this->update->where);
- $this->update->where(function (Where $what) use ($where): void {
+ $this->update->where(function ($what) use ($where) {
self::assertSame($where, $what);
});
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Predicate cannot be null');
- /** @psalm-suppress NullArgument - Ensure exception is thrown */
$this->update->where(null);
}
- #[Group('Laminas-240')]
- public function testPassingMultipleKeyValueInWhereClause(): void
+ /**
+ * @group Laminas-240
+ * @covers \Laminas\Db\Sql\Update::where
+ */
+ public function testPassingMultipleKeyValueInWhereClause()
{
$update = clone $this->update;
$update->table('table');
@@ -167,33 +163,39 @@ public function testPassingMultipleKeyValueInWhereClause(): void
);
}
- public function testGetRawState(): void
+ /**
+ * @covers \Laminas\Db\Sql\Update::getRawState
+ */
+ public function testGetRawState()
{
$this->update->table('foo')
->set(['bar' => 'baz'])
->where('x = y');
self::assertEquals('foo', $this->update->getRawState('table'));
- self::assertTrue($this->update->getRawState('emptyWhereProtection'));
+ self::assertEquals(true, $this->update->getRawState('emptyWhereProtection'));
self::assertEquals(['bar' => 'baz'], $this->update->getRawState('set'));
self::assertInstanceOf(Where::class, $this->update->getRawState('where'));
}
- public function testPrepareStatement(): void
+ /**
+ * @covers \Laminas\Db\Sql\Update::prepareStatement
+ */
+ public function testPrepareStatement()
{
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('UPDATE "foo" SET "bar" = ?, "boo" = NOW() WHERE x = y'));
@@ -206,18 +208,18 @@ public function testPrepareStatement(): void
// with TableIdentifier
$this->update = new Update();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('UPDATE "sch"."foo" SET "bar" = ?, "boo" = NOW() WHERE x = y'));
@@ -228,7 +230,10 @@ public function testPrepareStatement(): void
$this->update->prepareStatement($mockAdapter, $mockStatement);
}
- public function testGetSqlString(): void
+ /**
+ * @covers \Laminas\Db\Sql\Update::getSqlString
+ */
+ public function testGetSqlString()
{
$this->update->table('foo')
->set(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null])
@@ -251,9 +256,11 @@ public function testGetSqlString(): void
);
}
- #[Group('6768')]
- #[Group('6773')]
- public function testGetSqlStringForFalseUpdateValueParameter(): void
+ /**
+ * @group 6768
+ * @group 6773
+ */
+ public function testGetSqlStringForFalseUpdateValueParameter()
{
$this->update = new Update();
$this->update->table(new TableIdentifier('foo', 'sch'))
@@ -265,20 +272,28 @@ public function testGetSqlStringForFalseUpdateValueParameter(): void
);
}
- public function testGetUpdate(): void
+ /**
+ * @covers \Laminas\Db\Sql\Update::__get
+ */
+ public function testGetUpdate()
{
$getWhere = $this->update->__get('where');
self::assertInstanceOf(Where::class, $getWhere);
}
- public function testGetUpdateFails(): void
+ /**
+ * @covers \Laminas\Db\Sql\Update::__get
+ */
+ public function testGetUpdateFails()
{
- /** @psalm-suppress UndefinedThisPropertyFetch - Ensure non-existent property returns null */
$getWhat = $this->update->__get('what');
self::assertNull($getWhat);
}
- public function testCloneUpdate(): void
+ /**
+ * @covers \Laminas\Db\Sql\Update::__clone
+ */
+ public function testCloneUpdate()
{
$update1 = clone $this->update;
$update1->table('foo')
@@ -297,24 +312,26 @@ public function testCloneUpdate(): void
);
}
- #[CoversNothing]
- public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement(): void
+ /**
+ * @coversNothing
+ */
+ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement()
{
$updateIgnore = new UpdateIgnore();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('getPrepareType')->willReturn('positional');
- $mockDriver->expects($this->any())->method('formatParameterName')->willReturn('?');
+ $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
+ $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$pContainer = new ParameterContainer([]);
- $mockStatement->expects($this->any())->method('getParameterContainer')->willReturn($pContainer);
+ $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
- $mockStatement->expects($this->once())
+ $mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('UPDATE IGNORE "foo" SET "bar" = ?, "boo" = NOW() WHERE x = y'));
@@ -325,8 +342,10 @@ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareSt
$updateIgnore->prepareStatement($mockAdapter, $mockStatement);
}
- #[CoversNothing]
- public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString(): void
+ /**
+ * @coversNothing
+ */
+ public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString()
{
$this->update = new UpdateIgnore();
@@ -351,7 +370,10 @@ public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlStr
);
}
- public function testJoin(): void
+ /**
+ * @covers \Laminas\Db\Sql\Update::where
+ */
+ public function testJoin()
{
$this->update->table('Document');
$this->update->set(['x' => 'y'])
@@ -378,7 +400,7 @@ public function testJoin(): void
* Important when we're updating fields that are existing in several tables in one query.
* The same test as above but here we will specify table in update params
*/
- public function testJoinMultiUpdate(): void
+ public function testJoinMultiUpdate()
{
$this->update->table('Document');
$this->update->set(['Documents.x' => 'y'])
@@ -399,8 +421,11 @@ public function testJoinMultiUpdate(): void
);
}
- #[TestDox('unit test: Test join() returns Update object (is chainable)')]
- public function testJoinChainable(): void
+ /**
+ * @testdox unit test: Test join() returns Update object (is chainable)
+ * @covers \Laminas\Db\Sql\Update::join
+ */
+ public function testJoinChainable()
{
$return = $this->update->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT);
self::assertSame($this->update, $return);
diff --git a/test/unit/TableGateway/AbstractTableGatewayTest.php b/test/unit/TableGateway/AbstractTableGatewayTest.php
index 69a21994a..b5b04d0ec 100644
--- a/test/unit/TableGateway/AbstractTableGatewayTest.php
+++ b/test/unit/TableGateway/AbstractTableGatewayTest.php
@@ -15,109 +15,86 @@
use Laminas\Db\Sql\Update;
use Laminas\Db\TableGateway\AbstractTableGateway;
use Laminas\Db\TableGateway\Feature\FeatureSet;
-use Override;
-use PHPUnit\Framework\Attributes\CoversMethod;
+use PHPUnit\Framework\MockObject\Generator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
-#[CoversMethod(AbstractTableGateway::class, 'getTable')]
-#[CoversMethod(AbstractTableGateway::class, 'getAdapter')]
-#[CoversMethod(AbstractTableGateway::class, 'getSql')]
-#[CoversMethod(AbstractTableGateway::class, 'getResultSetPrototype')]
-#[CoversMethod(AbstractTableGateway::class, 'select')]
-#[CoversMethod(AbstractTableGateway::class, 'selectWith')]
-#[CoversMethod(AbstractTableGateway::class, 'executeSelect')]
-#[CoversMethod(AbstractTableGateway::class, 'insert')]
-#[CoversMethod(AbstractTableGateway::class, 'insertWith')]
-#[CoversMethod(AbstractTableGateway::class, 'executeInsert')]
-#[CoversMethod(AbstractTableGateway::class, 'update')]
-#[CoversMethod(AbstractTableGateway::class, 'updateWith')]
-#[CoversMethod(AbstractTableGateway::class, 'executeUpdate')]
-#[CoversMethod(AbstractTableGateway::class, 'delete')]
-#[CoversMethod(AbstractTableGateway::class, 'deleteWith')]
-#[CoversMethod(AbstractTableGateway::class, 'executeDelete')]
-#[CoversMethod(AbstractTableGateway::class, 'getLastInsertValue')]
-#[CoversMethod(AbstractTableGateway::class, '__get')]
-#[CoversMethod(AbstractTableGateway::class, '__clone')]
-final class AbstractTableGatewayTest extends TestCase
+class AbstractTableGatewayTest extends TestCase
{
- protected MockObject&Adapter $mockAdapter;
- protected MockObject&Sql\Sql $mockSql;
- protected AbstractTableGateway&MockObject $table;
- protected FeatureSet&MockObject $mockFeatureSet;
- protected MockObject&Select $mockSelect;
- protected MockObject&Insert $mockInsert;
- protected MockObject&Update $mockUpdate;
- protected MockObject&Delete $mockDelete;
+ /** @var Generator */
+ protected $mockAdapter;
+
+ /** @var Generator */
+ protected $mockSql;
+
+ /** @var AbstractTableGateway */
+ protected $table;
+
+ /** @var FeatureSet&MockObject */
+ protected $mockFeatureSet;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- #[Override]
protected function setUp(): void
{
// mock the adapter, driver, and parts
$mockResult = $this->getMockBuilder(ResultInterface::class)->getMock();
- $mockResult->expects($this->any())->method('getAffectedRows')->willReturn(5);
+ $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(5));
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
- $mockStatement->expects($this->any())->method('execute')->willReturn($mockResult);
+ $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
$mockConnection = $this->getMockBuilder(ConnectionInterface::class)->getMock();
- $mockConnection->expects($this->any())->method('getLastGeneratedValue')->willReturn(10);
+ $mockConnection->expects($this->any())->method('getLastGeneratedValue')->will($this->returnValue(10));
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement);
- $mockDriver->expects($this->any())->method('getConnection')->willReturn($mockConnection);
-
- $this->mockSelect = $this
- ->getMockBuilder(Select::class)
- ->onlyMethods(['where', 'getRawState'])
- ->setConstructorArgs(['foo'])
- ->getMock();
-
- $this->mockInsert = $this
- ->getMockBuilder(Insert::class)
- ->onlyMethods(['prepareStatement', 'values'])
- ->setConstructorArgs(['foo'])
- ->getMock();
-
- $this->mockUpdate = $this
- ->getMockBuilder(Update::class)
- ->onlyMethods(['where', 'join'])
- ->setConstructorArgs(['foo'])
- ->getMock();
-
- $this->mockDelete = $this->getMockBuilder(Delete::class)
- ->onlyMethods(['where'])
- ->setConstructorArgs(['foo'])
- ->getMock();
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
+ $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
$this->mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
- $this->mockSql = $this->getMockBuilder(Sql\Sql::class)
- ->onlyMethods(['select', 'insert', 'update', 'delete'])
+ $this->mockSql = $this->getMockBuilder(\Laminas\Db\Sql\Sql::class)
+ ->setMethods(['select', 'insert', 'update', 'delete'])
->setConstructorArgs([$this->mockAdapter, 'foo'])
->getMock();
- $this->mockSql->expects($this->any())->method('select')->willReturn($this->mockSelect);
- $this->mockSql->expects($this->any())->method('insert')->willReturn($this->mockInsert);
- $this->mockSql->expects($this->any())->method('update')->willReturn($this->mockUpdate);
- $this->mockSql->expects($this->any())->method('delete')->willReturn($this->mockDelete);
+ $this->mockSql->expects($this->any())->method('select')->will($this->returnValue(
+ $this->getMockBuilder(Select::class)
+ ->setMethods(['where', 'getRawState'])
+ ->setConstructorArgs(['foo'])
+ ->getMock()
+ ));
+ $this->mockSql->expects($this->any())->method('insert')->will($this->returnValue(
+ $this->getMockBuilder(Insert::class)
+ ->setMethods(['prepareStatement', 'values'])
+ ->setConstructorArgs(['foo'])
+ ->getMock()
+ ));
+ $this->mockSql->expects($this->any())->method('update')->will($this->returnValue(
+ $this->getMockBuilder(Update::class)
+ ->setMethods(['where', 'join'])
+ ->setConstructorArgs(['foo'])
+ ->getMock()
+ ));
+ $this->mockSql->expects($this->any())->method('delete')->will($this->returnValue(
+ $this->getMockBuilder(Delete::class)
+ ->setMethods(['where'])
+ ->setConstructorArgs(['foo'])
+ ->getMock()
+ ));
$this->mockFeatureSet = $this->getMockBuilder(FeatureSet::class)->getMock();
- $this->table = $this
- ->getMockBuilder(AbstractTableGateway::class)
- ->onlyMethods([])
- ->getMock();
-
+ $this->table = $this->getMockForAbstractClass(
+ AbstractTableGateway::class
+ //array('getTable')
+ );
$tgReflection = new ReflectionClass(AbstractTableGateway::class);
foreach ($tgReflection->getProperties() as $tgPropReflection) {
- /** @psalm-suppress UnusedMethodCall */
$tgPropReflection->setAccessible(true);
switch ($tgPropReflection->getName()) {
case 'table':
@@ -136,32 +113,55 @@ protected function setUp(): void
$tgPropReflection->setValue($this->table, $this->mockFeatureSet);
break;
}
- /** @psalm-suppress UnusedMethodCall */
- $tgPropReflection->setAccessible(false);
}
}
- public function testGetTable(): void
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown(): void
+ {
+ }
+
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getTable
+ */
+ public function testGetTable()
{
self::assertEquals('foo', $this->table->getTable());
}
- public function testGetAdapter(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getAdapter
+ */
+ public function testGetAdapter()
{
self::assertSame($this->mockAdapter, $this->table->getAdapter());
}
- public function testGetSql(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getSql
+ */
+ public function testGetSql()
{
- self::assertInstanceOf(Sql\Sql::class, $this->table->getSql());
+ self::assertInstanceOf(\Laminas\Db\Sql\Sql::class, $this->table->getSql());
}
- public function testGetSelectResultPrototype(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getResultSetPrototype
+ */
+ public function testGetSelectResultPrototype()
{
self::assertInstanceOf(ResultSet::class, $this->table->getResultSetPrototype());
}
- public function testSelectWithNoWhere(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::select
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::selectWith
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeSelect
+ */
+ public function testSelectWithNoWhere()
{
$resultSet = $this->table->select();
@@ -170,15 +170,21 @@ public function testSelectWithNoWhere(): void
self::assertNotSame($this->table->getResultSetPrototype(), $resultSet);
}
- public function testSelectWithWhereString(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::select
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::selectWith
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeSelect
+ */
+ public function testSelectWithWhereString()
{
- $mockSelect = $this->mockSelect;
+ $mockSelect = $this->mockSql->select();
+
$mockSelect->expects($this->any())
->method('getRawState')
- ->willReturn([
+ ->will($this->returnValue([
'table' => $this->table->getTable(),
'columns' => [],
- ]);
+ ]));
// assert select::from() is called
$mockSelect->expects($this->once())
@@ -188,34 +194,57 @@ public function testSelectWithWhereString(): void
$this->table->select('foo');
}
- public function testSelectWithArrayTable(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::select
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::selectWith
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeSelect
+ *
+ * This is a test for the case when a valid $select is built using an aliased table name, then used
+ * with AbstractTableGateway::selectWith (or AbstractTableGateway::select).
+ *
+ * $myTable = new MyTable(...);
+ * $sql = new \Laminas\Db\Sql\Sql(...);
+ * $select = $sql->select()->from(array('t' => 'mytable'));
+ *
+ * // Following fails, with Fatal error: Uncaught exception 'RuntimeException' with message
+ * 'The table name of the provided select object must match that of the table' unless fix is provided.
+ * $myTable->selectWith($select);
+ */
+ public function testSelectWithArrayTable()
{
// Case 1
- $select1 = $this->getMockBuilder(Select::class)->onlyMethods(['getRawState'])->getMock();
+
+ $select1 = $this->getMockBuilder(Select::class)->setMethods(['getRawState'])->getMock();
$select1->expects($this->once())
->method('getRawState')
- ->willReturn([
+ ->will($this->returnValue([
'table' => 'foo', // Standard table name format, valid according to Select::from()
'columns' => null,
- ]);
+ ]));
$return = $this->table->selectWith($select1);
- $this->assertInstanceOf(ResultSet::class, $return);
+ self::assertNotNull($return);
// Case 2
- $select1 = $this->getMockBuilder(Select::class)->onlyMethods(['getRawState'])->getMock();
+
+ $select1 = $this->getMockBuilder(Select::class)->setMethods(['getRawState'])->getMock();
$select1->expects($this->once())
->method('getRawState')
- ->willReturn([
+ ->will($this->returnValue([
'table' => ['f' => 'foo'], // Alias table name format, valid according to Select::from()
'columns' => null,
- ]);
+ ]));
$return = $this->table->selectWith($select1);
- $this->assertInstanceOf(ResultSet::class, $return);
+ self::assertNotNull($return);
}
- public function testInsert(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::insert
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::insertWith
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeInsert
+ */
+ public function testInsert()
{
- $mockInsert = $this->mockInsert;
+ $mockInsert = $this->mockSql->insert();
$mockInsert->expects($this->once())
->method('prepareStatement')
@@ -229,9 +258,14 @@ public function testInsert(): void
self::assertEquals(5, $affectedRows);
}
- public function testUpdate(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::update
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::updateWith
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeUpdate
+ */
+ public function testUpdate()
{
- $mockUpdate = $this->mockUpdate;
+ $mockUpdate = $this->mockSql->update();
// assert select::from() is called
$mockUpdate->expects($this->once())
@@ -242,9 +276,14 @@ public function testUpdate(): void
self::assertEquals(5, $affectedRows);
}
- public function testUpdateWithJoin(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::update
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::updateWith
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeUpdate
+ */
+ public function testUpdateWithJoin()
{
- $mockUpdate = $this->mockUpdate;
+ $mockUpdate = $this->mockSql->update();
$joins = [
[
@@ -267,9 +306,14 @@ public function testUpdateWithJoin(): void
self::assertEquals(5, $affectedRows);
}
- public function testUpdateWithJoinDefaultType(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::update
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::updateWith
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeUpdate
+ */
+ public function testUpdateWithJoinDefaultType()
{
- $mockUpdate = $this->mockUpdate;
+ $mockUpdate = $this->mockSql->update();
$joins = [
[
@@ -291,17 +335,27 @@ public function testUpdateWithJoinDefaultType(): void
self::assertEquals(5, $affectedRows);
}
- public function testUpdateWithNoCriteria(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::update
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::updateWith
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeUpdate
+ */
+ public function testUpdateWithNoCriteria()
{
- $this->mockUpdate;
+ $mockUpdate = $this->mockSql->update();
$affectedRows = $this->table->update(['foo' => 'bar']);
self::assertEquals(5, $affectedRows);
}
- public function testDelete(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::delete
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::deleteWith
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeDelete
+ */
+ public function testDelete()
{
- $mockDelete = $this->mockDelete;
+ $mockDelete = $this->mockSql->delete();
// assert select::from() is called
$mockDelete->expects($this->once())
@@ -312,22 +366,21 @@ public function testDelete(): void
self::assertEquals(5, $affectedRows);
}
- public function testGetLastInsertValue(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getLastInsertValue
+ */
+ public function testGetLastInsertValue()
{
$this->table->insert(['foo' => 'bar']);
self::assertEquals(10, $this->table->getLastInsertValue());
}
- public function testInitializeBuildsAResultSet(): void
+ public function testInitializeBuildsAResultSet()
{
- $stub = $this
- ->getMockBuilder(AbstractTableGateway::class)
- ->onlyMethods([])
- ->getMock();
+ $stub = $this->getMockForAbstractClass(AbstractTableGateway::class);
$tgReflection = new ReflectionClass(AbstractTableGateway::class);
foreach ($tgReflection->getProperties() as $tgPropReflection) {
- /** @psalm-suppress UnusedMethodCall */
$tgPropReflection->setAccessible(true);
switch ($tgPropReflection->getName()) {
case 'table':
@@ -346,8 +399,11 @@ public function testInitializeBuildsAResultSet(): void
$this->assertInstanceOf(ResultSet::class, $stub->getResultSetPrototype());
}
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::__get
+ */
// @codingStandardsIgnoreStart
- public function test__get(): void
+ public function test__get()
{
// @codingStandardsIgnoreEnd
$this->table->insert(['foo']); // trigger last insert id update
@@ -357,8 +413,11 @@ public function test__get(): void
//self::assertEquals('foo', $this->table->table);
}
+ /**
+ * @covers \Laminas\Db\TableGateway\AbstractTableGateway::__clone
+ */
// @codingStandardsIgnoreStart
- public function test__clone(): void
+ public function test__clone()
{
// @codingStandardsIgnoreEnd
$cTable = clone $this->table;
diff --git a/test/unit/TableGateway/Feature/EventFeatureTest.php b/test/unit/TableGateway/Feature/EventFeatureTest.php
index e6952840f..db8422209 100644
--- a/test/unit/TableGateway/Feature/EventFeatureTest.php
+++ b/test/unit/TableGateway/Feature/EventFeatureTest.php
@@ -10,108 +10,108 @@
use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Update;
use Laminas\Db\TableGateway\Feature\EventFeature;
-use Laminas\Db\TableGateway\Feature\EventFeatureEventsInterface;
use Laminas\Db\TableGateway\TableGateway;
use Laminas\EventManager\EventManager;
-use Override;
-use PHPUnit\Framework\MockObject\Exception;
-use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-final class EventFeatureTest extends TestCase
+class EventFeatureTest extends TestCase
{
- protected EventManager $eventManager;
+ /** @var EventManager */
+ protected $eventManager;
- protected EventFeature $feature;
+ /** @var EventFeature */
+ protected $feature;
- protected EventFeature\TableGatewayEvent $event;
+ /** @var EventFeature\TableGatewayEvent */
+ protected $event;
- protected TableGateway&MockObject $tableGateway;
+ /** @var TableGateway */
+ protected $tableGateway;
- public function testGetEventManager(): void
+ protected function setUp(): void
+ {
+ $this->eventManager = new EventManager();
+ $this->event = new EventFeature\TableGatewayEvent();
+ $this->feature = new EventFeature($this->eventManager, $this->event);
+ $this->tableGateway = $this->getMockForAbstractClass(TableGateway::class, [], '', false);
+ $this->feature->setTableGateway($this->tableGateway);
+
+ // typically runs before everything else
+ $this->feature->preInitialize();
+ }
+
+ public function testGetEventManager()
{
self::assertSame($this->eventManager, $this->feature->getEventManager());
}
- public function testGetEvent(): void
+ public function testGetEvent()
{
self::assertSame($this->event, $this->feature->getEvent());
}
- public function testPreInitialize(): void
+ public function testPreInitialize()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_PRE_INITIALIZE,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_PRE_INITIALIZE, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->preInitialize();
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_PRE_INITIALIZE, $event->getName());
+ self::assertEquals(EventFeature::EVENT_PRE_INITIALIZE, $event->getName());
}
- public function testPostInitialize(): void
+ public function testPostInitialize()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_POST_INITIALIZE,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_POST_INITIALIZE, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->postInitialize();
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_POST_INITIALIZE, $event->getName());
+ self::assertEquals(EventFeature::EVENT_POST_INITIALIZE, $event->getName());
}
- public function testPreSelect(): void
+ public function testPreSelect()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_PRE_SELECT,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_PRE_SELECT, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->preSelect($select = $this->getMockBuilder(Select::class)->getMock());
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_PRE_SELECT, $event->getName());
+ self::assertEquals(EventFeature::EVENT_PRE_SELECT, $event->getName());
self::assertSame($select, $event->getParam('select'));
}
- public function testPostSelect(): void
+ public function testPostSelect()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_POST_SELECT,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_POST_SELECT, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->postSelect(
$stmt = $this->getMockBuilder(StatementInterface::class)->getMock(),
@@ -120,46 +120,40 @@ function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): voi
);
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_POST_SELECT, $event->getName());
+ self::assertEquals(EventFeature::EVENT_POST_SELECT, $event->getName());
self::assertSame($stmt, $event->getParam('statement'));
self::assertSame($result, $event->getParam('result'));
self::assertSame($resultset, $event->getParam('result_set'));
}
- public function testPreInsert(): void
+ public function testPreInsert()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_PRE_INSERT,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_PRE_INSERT, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->preInsert($insert = $this->getMockBuilder(Insert::class)->getMock());
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_PRE_INSERT, $event->getName());
+ self::assertEquals(EventFeature::EVENT_PRE_INSERT, $event->getName());
self::assertSame($insert, $event->getParam('insert'));
}
- public function testPostInsert(): void
+ public function testPostInsert()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_POST_INSERT,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_POST_INSERT, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->postInsert(
$stmt = $this->getMockBuilder(StatementInterface::class)->getMock(),
@@ -167,45 +161,39 @@ function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): voi
);
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_POST_INSERT, $event->getName());
+ self::assertEquals(EventFeature::EVENT_POST_INSERT, $event->getName());
self::assertSame($stmt, $event->getParam('statement'));
self::assertSame($result, $event->getParam('result'));
}
- public function testPreUpdate(): void
+ public function testPreUpdate()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_PRE_UPDATE,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_PRE_UPDATE, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->preUpdate($update = $this->getMockBuilder(Update::class)->getMock());
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_PRE_UPDATE, $event->getName());
+ self::assertEquals(EventFeature::EVENT_PRE_UPDATE, $event->getName());
self::assertSame($update, $event->getParam('update'));
}
- public function testPostUpdate(): void
+ public function testPostUpdate()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_POST_UPDATE,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_POST_UPDATE, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->postUpdate(
$stmt = $this->getMockBuilder(StatementInterface::class)->getMock(),
@@ -213,45 +201,39 @@ function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): voi
);
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_POST_UPDATE, $event->getName());
+ self::assertEquals(EventFeature::EVENT_POST_UPDATE, $event->getName());
self::assertSame($stmt, $event->getParam('statement'));
self::assertSame($result, $event->getParam('result'));
}
- public function testPreDelete(): void
+ public function testPreDelete()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_PRE_DELETE,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_PRE_DELETE, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->preDelete($delete = $this->getMockBuilder(Delete::class)->getMock());
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_PRE_DELETE, $event->getName());
+ self::assertEquals(EventFeature::EVENT_PRE_DELETE, $event->getName());
self::assertSame($delete, $event->getParam('delete'));
}
- public function testPostDelete(): void
+ public function testPostDelete()
{
$closureHasRun = false;
/** @var EventFeature\TableGatewayEvent $event */
$event = null;
- $this->eventManager->attach(
- EventFeatureEventsInterface::EVENT_POST_DELETE,
- function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): void {
- $event = $e;
- $closureHasRun = true;
- }
- );
+ $this->eventManager->attach(EventFeature::EVENT_POST_DELETE, function ($e) use (&$closureHasRun, &$event) {
+ $event = $e;
+ $closureHasRun = true;
+ });
$this->feature->postDelete(
$stmt = $this->getMockBuilder(StatementInterface::class)->getMock(),
@@ -259,24 +241,8 @@ function (EventFeature\TableGatewayEvent $e) use (&$closureHasRun, &$event): voi
);
self::assertTrue($closureHasRun);
self::assertInstanceOf(TableGateway::class, $event->getTarget());
- self::assertEquals(EventFeatureEventsInterface::EVENT_POST_DELETE, $event->getName());
+ self::assertEquals(EventFeature::EVENT_POST_DELETE, $event->getName());
self::assertSame($stmt, $event->getParam('statement'));
self::assertSame($result, $event->getParam('result'));
}
-
- /**
- * @throws Exception
- */
- #[Override]
- protected function setUp(): void
- {
- $this->eventManager = new EventManager();
- $this->event = new EventFeature\TableGatewayEvent();
- $this->feature = new EventFeature($this->eventManager, $this->event);
- $this->tableGateway = $this->getMockBuilder(TableGateway::class)->disableOriginalConstructor()->onlyMethods([])->getMock();
- $this->feature->setTableGateway($this->tableGateway);
-
- // typically runs before everything else
- $this->feature->preInitialize();
- }
}
diff --git a/test/unit/TableGateway/Feature/FeatureSetTest.php b/test/unit/TableGateway/Feature/FeatureSetTest.php
index 6549d89ff..7a2be0fca 100644
--- a/test/unit/TableGateway/Feature/FeatureSetTest.php
+++ b/test/unit/TableGateway/Feature/FeatureSetTest.php
@@ -16,40 +16,42 @@
use Laminas\Db\TableGateway\Feature\MasterSlaveFeature;
use Laminas\Db\TableGateway\Feature\MetadataFeature;
use Laminas\Db\TableGateway\Feature\SequenceFeature;
-use PHPUnit\Framework\Attributes\CoversMethod;
-use PHPUnit\Framework\Attributes\Group;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
-#[CoversMethod(FeatureSet::class, 'canCallMagicCall')]
-#[CoversMethod(FeatureSet::class, 'callMagicCall')]
-final class FeatureSetTest extends TestCase
+class FeatureSetTest extends TestCase
{
/**
* @cover FeatureSet::addFeature
- * @throws Exception
+ * @group Laminas-4993
*/
- #[Group('Laminas-4993')]
- public function testAddFeatureThatFeatureDoesNotHaveTableGatewayButFeatureSetHas(): void
+ public function testAddFeatureThatFeatureDoesNotHaveTableGatewayButFeatureSetHas()
{
$mockMasterAdapter = $this->getMockBuilder(AdapterInterface::class)->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement);
- $mockMasterAdapter->expects($this->any())->method('getDriver')->willReturn($mockDriver);
- $mockMasterAdapter->expects($this->any())->method('getPlatform')->willReturn(new Sql92());
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue(
+ $mockStatement
+ ));
+ $mockMasterAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver));
+ $mockMasterAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue(
+ new Sql92()
+ ));
$mockSlaveAdapter = $this->getMockBuilder(AdapterInterface::class)->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement);
- $mockSlaveAdapter->expects($this->any())->method('getDriver')->willReturn($mockDriver);
- $mockSlaveAdapter->expects($this->any())->method('getPlatform')->willReturn(new Sql92());
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue(
+ $mockStatement
+ ));
+ $mockSlaveAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver));
+ $mockSlaveAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue(
+ new Sql92()
+ ));
- $tableGatewayMock = $this->getMockBuilder(AbstractTableGateway::class)->onlyMethods([])->getMock();
+ $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class);
//feature doesn't have tableGateway, but FeatureSet has
$feature = new MasterSlaveFeature($mockSlaveAdapter);
@@ -62,21 +64,20 @@ public function testAddFeatureThatFeatureDoesNotHaveTableGatewayButFeatureSetHas
/**
* @cover FeatureSet::addFeature
- * @throws Exception
+ * @group Laminas-4993
*/
- #[Group('Laminas-4993')]
- public function testAddFeatureThatFeatureHasTableGatewayButFeatureSetDoesNotHave(): void
+ public function testAddFeatureThatFeatureHasTableGatewayButFeatureSetDoesNotHave()
{
- $tableGatewayMock = $this->getMockBuilder(AbstractTableGateway::class)->onlyMethods([])->getMock();
+ $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class);
$metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock();
- $metadataMock->expects($this->any())->method('getColumnNames')->willReturn(['id', 'name']);
+ $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name']));
$constraintObject = new ConstraintObject('id_pk', 'table');
$constraintObject->setColumns(['id']);
$constraintObject->setType('PRIMARY KEY');
- $metadataMock->expects($this->any())->method('getConstraints')->willReturn([$constraintObject]);
+ $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject]));
//feature have tableGateway, but FeatureSet doesn't has
$feature = new MetadataFeature($metadataMock);
@@ -86,7 +87,10 @@ public function testAddFeatureThatFeatureHasTableGatewayButFeatureSetDoesNotHave
self::assertInstanceOf(FeatureSet::class, $featureSet->addFeature($feature));
}
- public function testCanCallMagicCallReturnsTrueForAddedMethodOfAddedFeature(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\Feature\FeatureSet::canCallMagicCall
+ */
+ public function testCanCallMagicCallReturnsTrueForAddedMethodOfAddedFeature()
{
$feature = new SequenceFeature('id', 'table_sequence');
$featureSet = new FeatureSet();
@@ -98,7 +102,10 @@ public function testCanCallMagicCallReturnsTrueForAddedMethodOfAddedFeature(): v
);
}
- public function testCanCallMagicCallReturnsFalseForAddedMethodOfAddedFeature(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\Feature\FeatureSet::canCallMagicCall
+ */
+ public function testCanCallMagicCallReturnsFalseForAddedMethodOfAddedFeature()
{
$feature = new SequenceFeature('id', 'table_sequence');
$featureSet = new FeatureSet();
@@ -110,7 +117,10 @@ public function testCanCallMagicCallReturnsFalseForAddedMethodOfAddedFeature():
);
}
- public function testCanCallMagicCallReturnsFalseWhenNoFeaturesHaveBeenAdded(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\Feature\FeatureSet::canCallMagicCall
+ */
+ public function testCanCallMagicCallReturnsFalseWhenNoFeaturesHaveBeenAdded()
{
$featureSet = new FeatureSet();
self::assertFalse(
@@ -118,18 +128,21 @@ public function testCanCallMagicCallReturnsFalseWhenNoFeaturesHaveBeenAdded(): v
);
}
- public function testCallMagicCallSucceedsForValidMethodOfAddedFeature(): void
+ /**
+ * @covers \Laminas\Db\TableGateway\Feature\FeatureSet::callMagicCall
+ */
+ public function testCallMagicCallSucceedsForValidMethodOfAddedFeature()
{
$sequenceName = 'table_sequence';
$platformMock = $this->getMockBuilder(Postgresql::class)->getMock();
$platformMock->expects($this->any())
- ->method('getName')->willReturn('PostgreSQL');
+ ->method('getName')->will($this->returnValue('PostgreSQL'));
$resultMock = $this->getMockBuilder(Result::class)->getMock();
$resultMock->expects($this->any())
->method('current')
- ->willReturn(['currval' => 1]);
+ ->will($this->returnValue(['currval' => 1]));
$statementMock = $this->getMockBuilder(StatementInterface::class)->getMock();
$statementMock->expects($this->any())
@@ -137,15 +150,15 @@ public function testCallMagicCallSucceedsForValidMethodOfAddedFeature(): void
->with('SELECT CURRVAL(\'' . $sequenceName . '\')');
$statementMock->expects($this->any())
->method('execute')
- ->willReturn($resultMock);
+ ->will($this->returnValue($resultMock));
$adapterMock = $this->getMockBuilder(Adapter::class)
->disableOriginalConstructor()
->getMock();
$adapterMock->expects($this->any())
- ->method('getPlatform')->willReturn($platformMock);
+ ->method('getPlatform')->will($this->returnValue($platformMock));
$adapterMock->expects($this->any())
- ->method('createStatement')->willReturn($statementMock);
+ ->method('createStatement')->will($this->returnValue($statementMock));
$tableGatewayMock = $this->getMockBuilder(AbstractTableGateway::class)
->disableOriginalConstructor()
@@ -153,7 +166,6 @@ public function testCallMagicCallSucceedsForValidMethodOfAddedFeature(): void
$reflectionClass = new ReflectionClass(AbstractTableGateway::class);
$reflectionProperty = $reflectionClass->getProperty('adapter');
- /** @psalm-suppress UnusedMethodCall */
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($tableGatewayMock, $adapterMock);
@@ -161,6 +173,6 @@ public function testCallMagicCallSucceedsForValidMethodOfAddedFeature(): void
$feature->setTableGateway($tableGatewayMock);
$featureSet = new FeatureSet();
$featureSet->addFeature($feature);
- self::assertEquals(1, $featureSet->callMagicCall('lastSequenceId', []));
+ self::assertEquals(1, $featureSet->callMagicCall('lastSequenceId', null));
}
}
diff --git a/test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php b/test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php
index d18f17964..3e78b310e 100644
--- a/test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php
+++ b/test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php
@@ -9,90 +9,86 @@
use Laminas\Db\ResultSet\ResultSet;
use Laminas\Db\TableGateway\Feature\MasterSlaveFeature;
use Laminas\Db\TableGateway\TableGateway;
-use Override;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-final class MasterSlaveFeatureTest extends TestCase
+class MasterSlaveFeatureTest extends TestCase
{
- protected MockObject&AdapterInterface $mockMasterAdapter;
- protected MockObject&AdapterInterface $mockSlaveAdapter;
- protected MockObject&StatementInterface $mockStatement;
- protected MasterSlaveFeature $feature;
- protected TableGateway&MockObject $table;
+ /** @var AdapterInterface&MockObject */
+ protected $mockMasterAdapter;
- #[Override]
- protected function setUp(): void
- {
- $this->mockMasterAdapter = $this->getMockBuilder(AdapterInterface::class)->onlyMethods([])->getMock();
- $this->mockSlaveAdapter = $this->getMockBuilder(AdapterInterface::class)->onlyMethods([])->getMock();
- $this->mockStatement = $this->getMockBuilder(StatementInterface::class)->onlyMethods([])->getMock();
+ /** @var AdapterInterface&MockObject */
+ protected $mockSlaveAdapter;
+
+ /** @var MasterSlaveFeature */
+ protected $feature;
- $mockDriver = $this->getMockBuilder(DriverInterface::class)->onlyMethods([])->getMock();
- $mockDriver->expects($this->any())->method('createStatement')->willReturn(clone $this->mockStatement);
- $this->mockMasterAdapter->expects($this->any())->method('getDriver')->willReturn($mockDriver);
- $this->mockMasterAdapter->expects($this->any())->method('getPlatform')->willReturn(new Sql92());
+ /** @var TableGateway&MockObject */
+ protected $table;
- $mockDriver = $this->getMockBuilder(DriverInterface::class)->onlyMethods([])->getMock();
- $mockDriver->expects($this->any())->method('createStatement')->willReturn(clone $this->mockStatement);
- $this->mockSlaveAdapter->expects($this->any())->method('getDriver')->willReturn($mockDriver);
- $this->mockSlaveAdapter->expects($this->any())->method('getPlatform')->willReturn(new Sql92());
+ protected function setUp(): void
+ {
+ $this->mockMasterAdapter = $this->getMockBuilder(AdapterInterface::class)->getMock();
+
+ $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
+ $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue(
+ $mockStatement
+ ));
+ $this->mockMasterAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver));
+ $this->mockMasterAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue(
+ new Sql92()
+ ));
+
+ $this->mockSlaveAdapter = $this->getMockBuilder(AdapterInterface::class)->getMock();
+
+ $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
+ $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue(
+ $mockStatement
+ ));
+ $this->mockSlaveAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver));
+ $this->mockSlaveAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue(
+ new Sql92()
+ ));
$this->feature = new MasterSlaveFeature($this->mockSlaveAdapter);
}
- /**
- * @throws Exception
- */
- public function testPostInitialize(): void
+ public function testPostInitialize()
{
- $this->getMockBuilder(TableGateway::class)->setConstructorArgs(['foo', $this->mockMasterAdapter, $this->feature])->onlyMethods([])->getMock();
+ $this->getMockForAbstractClass(
+ TableGateway::class,
+ ['foo', $this->mockMasterAdapter, $this->feature]
+ );
// postInitialize is run
self::assertSame($this->mockSlaveAdapter, $this->feature->getSlaveSql()->getAdapter());
}
- /**
- * @throws Exception
- */
- public function testPreSelect(): void
+ public function testPreSelect()
{
- $this->expectNotToPerformAssertions();
-
- $table = $this
- ->getMockBuilder(TableGateway::class)
- ->setConstructorArgs(['foo', $this->mockMasterAdapter, $this->feature])
- ->onlyMethods([])->getMock();
-
- $stmt = $this
- ->mockSlaveAdapter
- ->getDriver()
- ->createStatement();
-
- /** @var MockObject&StatementInterface $stmt */
- $stmt
- ->expects($this->once())
- ->method('execute')
- ->willReturn($this->getMockBuilder(ResultSet::class)->onlyMethods([])->getMock());
+ $table = $this->getMockForAbstractClass(
+ TableGateway::class,
+ ['foo', $this->mockMasterAdapter, $this->feature]
+ );
+
+ $this->mockSlaveAdapter->getDriver()->createStatement()
+ ->expects($this->once())->method('execute')->will($this->returnValue(
+ $this->getMockBuilder(ResultSet::class)->getMock()
+ ));
$table->select('foo = bar');
}
- /**
- * @throws Exception
- */
- public function testPostSelect(): void
+ public function testPostSelect()
{
- $table = $this->getMockBuilder(TableGateway::class)->setConstructorArgs(['foo', $this->mockMasterAdapter, $this->feature])->onlyMethods([])->getMock();
- $stmt = $this
- ->mockSlaveAdapter
- ->getDriver()
- ->createStatement();
-
- /** @var MockObject&StatementInterface $stmt */
- $stmt
- ->expects($this->once())
- ->method('execute')
- ->willReturn($this->getMockBuilder(ResultSet::class)->onlyMethods([])->getMock());
+ $table = $this->getMockForAbstractClass(
+ TableGateway::class,
+ ['foo', $this->mockMasterAdapter, $this->feature]
+ );
+ $this->mockSlaveAdapter->getDriver()->createStatement()
+ ->expects($this->once())->method('execute')->will($this->returnValue(
+ $this->getMockBuilder(ResultSet::class)->getMock()
+ ));
$masterSql = $table->getSql();
$table->select('foo = bar');
diff --git a/test/unit/TableGateway/Feature/MetadataFeatureTest.php b/test/unit/TableGateway/Feature/MetadataFeatureTest.php
index 0b385a77d..201c209c7 100644
--- a/test/unit/TableGateway/Feature/MetadataFeatureTest.php
+++ b/test/unit/TableGateway/Feature/MetadataFeatureTest.php
@@ -8,28 +8,25 @@
use Laminas\Db\Metadata\Object\ViewObject;
use Laminas\Db\TableGateway\AbstractTableGateway;
use Laminas\Db\TableGateway\Feature\MetadataFeature;
-use PHPUnit\Framework\Attributes\Group;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
-final class MetadataFeatureTest extends TestCase
+class MetadataFeatureTest extends TestCase
{
/**
- * @throws Exception
+ * @group integration-test
*/
- #[Group('integration-test')]
- public function testPostInitialize(): void
+ public function testPostInitialize()
{
- $tableGatewayMock = $this->getMockBuilder(AbstractTableGateway::class)->onlyMethods([])->getMock();
+ $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class);
$metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock();
- $metadataMock->expects($this->any())->method('getColumnNames')->willReturn(['id', 'name']);
+ $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name']));
$constraintObject = new ConstraintObject('id_pk', 'table');
$constraintObject->setColumns(['id']);
$constraintObject->setType('PRIMARY KEY');
- $metadataMock->expects($this->any())->method('getConstraints')->willReturn([$constraintObject]);
+ $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject]));
$feature = new MetadataFeature($metadataMock);
$feature->setTableGateway($tableGatewayMock);
@@ -38,35 +35,30 @@ public function testPostInitialize(): void
self::assertEquals(['id', 'name'], $tableGatewayMock->getColumns());
}
- /**
- * @throws Exception
- */
- public function testPostInitializeRecordsPrimaryKeyColumnToSharedMetadata(): void
+ public function testPostInitializeRecordsPrimaryKeyColumnToSharedMetadata()
{
/** @var AbstractTableGateway $tableGatewayMock */
- $tableGatewayMock = $this->getMockBuilder(AbstractTableGateway::class)->onlyMethods([])->getMock();
+ $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class);
$metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock();
- $metadataMock->expects($this->any())->method('getColumnNames')->willReturn(['id', 'name']);
+ $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name']));
$metadataMock->expects($this->any())
->method('getTable')
- ->willReturn(new TableObject('foo'));
+ ->will($this->returnValue(new TableObject('foo')));
$constraintObject = new ConstraintObject('id_pk', 'table');
$constraintObject->setColumns(['id']);
$constraintObject->setType('PRIMARY KEY');
- $metadataMock->expects($this->any())->method('getConstraints')->willReturn([$constraintObject]);
+ $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject]));
$feature = new MetadataFeature($metadataMock);
$feature->setTableGateway($tableGatewayMock);
$feature->postInitialize();
$r = new ReflectionProperty(MetadataFeature::class, 'sharedData');
- /** @psalm-suppress UnusedMethodCall */
$r->setAccessible(true);
$sharedData = $r->getValue($feature);
- self::assertIsArray($sharedData);
self::assertTrue(
isset($sharedData['metadata']['primaryKey']),
'Shared data must have metadata entry for primary key'
@@ -74,54 +66,46 @@ public function testPostInitializeRecordsPrimaryKeyColumnToSharedMetadata(): voi
self::assertSame($sharedData['metadata']['primaryKey'], 'id');
}
- /**
- * @throws Exception
- */
- public function testPostInitializeRecordsListOfColumnsInPrimaryKeyToSharedMetadata(): void
+ public function testPostInitializeRecordsListOfColumnsInPrimaryKeyToSharedMetadata()
{
/** @var AbstractTableGateway $tableGatewayMock */
- $tableGatewayMock = $this->getMockBuilder(AbstractTableGateway::class)->onlyMethods([])->getMock();
+ $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class);
$metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock();
- $metadataMock->expects($this->any())->method('getColumnNames')->willReturn(['id', 'name']);
+ $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name']));
$metadataMock->expects($this->any())
->method('getTable')
- ->willReturn(new TableObject('foo'));
+ ->will($this->returnValue(new TableObject('foo')));
$constraintObject = new ConstraintObject('id_pk', 'table');
$constraintObject->setColumns(['composite', 'id']);
$constraintObject->setType('PRIMARY KEY');
- $metadataMock->expects($this->any())->method('getConstraints')->willReturn([$constraintObject]);
+ $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject]));
$feature = new MetadataFeature($metadataMock);
$feature->setTableGateway($tableGatewayMock);
$feature->postInitialize();
$r = new ReflectionProperty(MetadataFeature::class, 'sharedData');
- /** @psalm-suppress UnusedMethodCall */
$r->setAccessible(true);
$sharedData = $r->getValue($feature);
- self::assertIsArray($sharedData);
self::assertTrue(
isset($sharedData['metadata']['primaryKey']),
'Shared data must have metadata entry for primary key'
);
- self::assertEquals(['composite', 'id'], $sharedData['metadata']['primaryKey']);
+ self::assertEquals($sharedData['metadata']['primaryKey'], ['composite', 'id']);
}
- /**
- * @throws Exception
- */
- public function testPostInitializeSkipsPrimaryKeyCheckIfNotTable(): void
+ public function testPostInitializeSkipsPrimaryKeyCheckIfNotTable()
{
/** @var AbstractTableGateway $tableGatewayMock */
- $tableGatewayMock = $this->getMockBuilder(AbstractTableGateway::class)->onlyMethods([])->getMock();
+ $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class);
$metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock();
- $metadataMock->expects($this->any())->method('getColumnNames')->willReturn(['id', 'name']);
+ $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name']));
$metadataMock->expects($this->any())
->method('getTable')
- ->willReturn(new ViewObject('foo'));
+ ->will($this->returnValue(new ViewObject('foo')));
$metadataMock->expects($this->never())->method('getConstraints');
diff --git a/test/unit/TableGateway/Feature/SequenceFeatureTest.php b/test/unit/TableGateway/Feature/SequenceFeatureTest.php
index cccdf4dc0..abe66af1b 100644
--- a/test/unit/TableGateway/Feature/SequenceFeatureTest.php
+++ b/test/unit/TableGateway/Feature/SequenceFeatureTest.php
@@ -8,78 +8,76 @@
use Laminas\Db\Adapter\Platform\PlatformInterface;
use Laminas\Db\TableGateway\Feature\SequenceFeature;
use Laminas\Db\TableGateway\TableGateway;
-use Override;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
-final class SequenceFeatureTest extends TestCase
+class SequenceFeatureTest extends TestCase
{
- protected SequenceFeature $feature;
+ /** @var SequenceFeature */
+ protected $feature;
- protected TableGateway $tableGateway;
+ /** @var TableGateway */
+ protected $tableGateway;
/** @var string primary key name */
- protected string $primaryKeyField = 'id';
+ protected $primaryKeyField = 'id';
/** @var string sequence name */
- protected static string $sequenceName = 'table_sequence';
+ protected $sequenceName = 'table_sequence';
- #[Override]
protected function setUp(): void
{
- $this->feature = new SequenceFeature($this->primaryKeyField, self::$sequenceName);
+ $this->feature = new SequenceFeature($this->primaryKeyField, $this->sequenceName);
}
/**
- * @throws Exception
+ * @dataProvider nextSequenceIdProvider
*/
- #[DataProvider('nextSequenceIdProvider')]
- public function testNextSequenceId(string $platformName, string $statementSql): void
+ public function testNextSequenceId(string $platformName, string $statementSql)
{
$platform = $this->createMock(PlatformInterface::class);
$platform->expects($this->any())
->method('getName')
- ->willReturn($platformName);
+ ->will($this->returnValue($platformName));
$platform->expects($this->any())
->method('quoteIdentifier')
- ->willReturn(self::$sequenceName);
+ ->will($this->returnValue($this->sequenceName));
$adapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods(['getPlatform', 'createStatement'])
+ ->setMethods(['getPlatform', 'createStatement'])
->disableOriginalConstructor()
->getMock();
$adapter->expects($this->any())
->method('getPlatform')
- ->willReturn($platform);
+ ->will($this->returnValue($platform));
$result = $this->createMock(ResultInterface::class);
$result->expects($this->any())
->method('current')
- ->willReturn(['nextval' => 2]);
+ ->will($this->returnValue(['nextval' => 2]));
$statement = $this->createMock(StatementInterface::class);
$statement->expects($this->any())
->method('execute')
- ->willReturn($result);
+ ->will($this->returnValue($result));
$statement->expects($this->any())
->method('prepare')
->with($statementSql);
$adapter->expects($this->once())
->method('createStatement')
- ->willReturn($statement);
- $this->tableGateway = $this
- ->getMockBuilder(TableGateway::class)
- ->setConstructorArgs(['table', $adapter])
- ->onlyMethods([])
- ->getMock();
+ ->will($this->returnValue($statement));
+ $this->tableGateway = $this->getMockForAbstractClass(
+ TableGateway::class,
+ ['table', $adapter],
+ '',
+ true
+ );
$this->feature->setTableGateway($this->tableGateway);
$this->feature->nextSequenceId();
}
/** @psalm-return array */
- public static function nextSequenceIdProvider(): array
+ public function nextSequenceIdProvider(): array
{
return [
- ['PostgreSQL', 'SELECT NEXTVAL(\'"' . self::$sequenceName . '"\')'],
- ['Oracle', 'SELECT ' . self::$sequenceName . '.NEXTVAL as "nextval" FROM dual'],
+ ['PostgreSQL', 'SELECT NEXTVAL(\'"' . $this->sequenceName . '"\')'],
+ ['Oracle', 'SELECT ' . $this->sequenceName . '.NEXTVAL as "nextval" FROM dual'],
];
}
}
diff --git a/test/unit/TableGateway/TableGatewayTest.php b/test/unit/TableGateway/TableGatewayTest.php
index 95c780362..b0894f4c7 100644
--- a/test/unit/TableGateway/TableGatewayTest.php
+++ b/test/unit/TableGateway/TableGatewayTest.php
@@ -17,34 +17,28 @@
use Laminas\Db\TableGateway\Feature;
use Laminas\Db\TableGateway\Feature\FeatureSet;
use Laminas\Db\TableGateway\TableGateway;
-use Override;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-/**
- * @psalm-type AliasedTable = array{alias: string|TableIdentifier}
- */
-final class TableGatewayTest extends TestCase
+class TableGatewayTest extends TestCase
{
- protected Adapter&MockObject $mockAdapter;
+ /** @var Adapter&MockObject */
+ protected $mockAdapter;
- #[Override]
protected function setUp(): void
{
// mock the adapter, driver, and parts
$mockResult = $this->getMockBuilder(ResultInterface::class)->getMock();
$mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock();
- $mockStatement->expects($this->any())->method('execute')->willReturn($mockResult);
+ $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
$mockConnection = $this->getMockBuilder(ConnectionInterface::class)->getMock();
$mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock();
- $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement);
- $mockDriver->expects($this->any())->method('getConnection')->willReturn($mockConnection);
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
+ $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
// setup mock adapter
$this->mockAdapter = $this->getMockBuilder(Adapter::class)
- ->onlyMethods([])
+ ->setMethods()
->setConstructorArgs([$mockDriver])
->getMock();
}
@@ -52,7 +46,7 @@ protected function setUp(): void
/**
* Beside other tests checks for plain string table identifier
*/
- public function testConstructor(): void
+ public function testConstructor()
{
// constructor with only required args
$table = new TableGateway(
@@ -84,16 +78,17 @@ public function testConstructor(): void
// constructor expects exception
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Table name must be a string or an instance of Laminas\Db\Sql\TableIdentifier');
- /** @psalm-suppress NullArgument - Testing incorrect constructor */
new TableGateway(
null,
$this->mockAdapter
);
}
- #[Group('6726')]
- #[Group('6740')]
- public function testTableAsString(): void
+ /**
+ * @group 6726
+ * @group 6740
+ */
+ public function testTableAsString()
{
$ti = 'fooTable.barSchema';
// constructor with only required args
@@ -105,9 +100,11 @@ public function testTableAsString(): void
self::assertEquals($ti, $table->getTable());
}
- #[Group('6726')]
- #[Group('6740')]
- public function testTableAsTableIdentifierObject(): void
+ /**
+ * @group 6726
+ * @group 6740
+ */
+ public function testTableAsTableIdentifierObject()
{
$ti = new TableIdentifier('fooTable', 'barSchema');
// constructor with only required args
@@ -119,9 +116,11 @@ public function testTableAsTableIdentifierObject(): void
self::assertEquals($ti, $table->getTable());
}
- #[Group('6726')]
- #[Group('6740')]
- public function testTableAsAliasedTableIdentifierObject(): void
+ /**
+ * @group 6726
+ * @group 6740
+ */
+ public function testTableAsAliasedTableIdentifierObject()
{
// phpcs:disable WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCaps
$aliasedTI = ['foo' => new TableIdentifier('fooTable', 'barSchema')];
@@ -136,12 +135,12 @@ public function testTableAsAliasedTableIdentifierObject(): void
}
/**
- * @psalm-return array{
- * 'identifier-alias': list{array{U: TableIdentifier}, TableIdentifier},
- * 'simple-alias': list{array{U: string}, string}
- * }
+ * @psalm-return array,
+ * 1: string|TableIdentifier
+ * }>
*/
- public static function aliasedTables(): array
+ public function aliasedTables(): array
{
$identifier = new TableIdentifier('Users');
return [
@@ -151,11 +150,12 @@ public static function aliasedTables(): array
}
/**
- * @param AliasedTable $tableValue
+ * @group 7311
+ * @dataProvider aliasedTables
+ * @param array $tableValue
+ * @param string|TableIdentifier $expected
*/
- #[DataProvider('aliasedTables')]
- #[Group('7311')]
- public function testInsertShouldResetTableToUnaliasedTable(array $tableValue, string|TableIdentifier $expected): void
+ public function testInsertShouldResetTableToUnaliasedTable(array $tableValue, $expected)
{
$insert = new Insert();
$insert->into($tableValue);
@@ -164,17 +164,16 @@ public function testInsertShouldResetTableToUnaliasedTable(array $tableValue, st
->getMock();
$result->expects($this->once())
->method('getAffectedRows')
- ->willReturn(1);
+ ->will($this->returnValue(1));
$statement = $this->getMockBuilder(StatementInterface::class)
->getMock();
$statement->expects($this->once())
->method('execute')
- ->willReturn($result);
+ ->will($this->returnValue($result));
- $statementExpectation = function (Insert $insert) use ($expected, $statement): MockObject&StatementInterface {
+ $statementExpectation = function ($insert) use ($expected, $statement) {
$state = $insert->getRawState();
- $this->assertIsArray($state);
self::assertSame($expected, $state['table']);
return $statement;
};
@@ -184,14 +183,14 @@ public function testInsertShouldResetTableToUnaliasedTable(array $tableValue, st
->getMock();
$sql->expects($this->atLeastOnce())
->method('getTable')
- ->willReturn($tableValue);
+ ->will($this->returnValue($tableValue));
$sql->expects($this->once())
->method('insert')
- ->willReturn($insert);
+ ->will($this->returnValue($insert));
$sql->expects($this->once())
->method('prepareStatementForSqlObject')
->with($this->equalTo($insert))
- ->willReturnCallback($statementExpectation);
+ ->will($this->returnCallback($statementExpectation));
$table = new TableGateway(
$tableValue,
@@ -201,24 +200,24 @@ public function testInsertShouldResetTableToUnaliasedTable(array $tableValue, st
$sql
);
- $table->insert([
+ $result = $table->insert([
'foo' => 'FOO',
]);
$state = $insert->getRawState();
- $this->assertIsArray($state);
- $this->assertIsArray($state['table']);
- $this->assertEquals(
+ self::assertIsArray($state['table']);
+ self::assertEquals(
$tableValue,
$state['table']
);
}
/**
- * @param AliasedTable $tableValue
+ * @dataProvider aliasedTables
+ * @param array $tableValue
+ * @param string|TableIdentifier $expected
*/
- #[DataProvider('aliasedTables')]
- public function testUpdateShouldResetTableToUnaliasedTable(array $tableValue, string|TableIdentifier $expected): void
+ public function testUpdateShouldResetTableToUnaliasedTable(array $tableValue, $expected)
{
$update = new Update();
$update->table($tableValue);
@@ -227,18 +226,17 @@ public function testUpdateShouldResetTableToUnaliasedTable(array $tableValue, st
->getMock();
$result->expects($this->once())
->method('getAffectedRows')
- ->willReturn(1);
+ ->will($this->returnValue(1));
$statement = $this->getMockBuilder(StatementInterface::class)
->getMock();
$statement->expects($this->once())
->method('execute')
- ->willReturn($result);
+ ->will($this->returnValue($result));
- $statementExpectation = function (Update $update) use ($expected, $statement): MockObject&StatementInterface {
+ $statementExpectation = function ($update) use ($expected, $statement) {
$state = $update->getRawState();
- $this->assertIsArray($state);
- $this->assertSame($expected, $state['table']);
+ self::assertSame($expected, $state['table']);
return $statement;
};
@@ -247,14 +245,14 @@ public function testUpdateShouldResetTableToUnaliasedTable(array $tableValue, st
->getMock();
$sql->expects($this->atLeastOnce())
->method('getTable')
- ->willReturn($tableValue);
+ ->will($this->returnValue($tableValue));
$sql->expects($this->once())
->method('update')
- ->willReturn($update);
+ ->will($this->returnValue($update));
$sql->expects($this->once())
->method('prepareStatementForSqlObject')
->with($this->equalTo($update))
- ->willReturnCallback($statementExpectation);
+ ->will($this->returnCallback($statementExpectation));
$table = new TableGateway(
$tableValue,
@@ -264,26 +262,26 @@ public function testUpdateShouldResetTableToUnaliasedTable(array $tableValue, st
$sql
);
- $table->update([
+ $result = $table->update([
'foo' => 'FOO',
], [
'bar' => 'BAR',
]);
$state = $update->getRawState();
- $this->assertIsArray($state);
- $this->assertIsArray($state['table']);
- $this->assertEquals(
+ self::assertIsArray($state['table']);
+ self::assertEquals(
$tableValue,
$state['table']
);
}
/**
- * @param AliasedTable $tableValue
+ * @dataProvider aliasedTables
+ * @param array $tableValue
+ * @param string|TableIdentifier $expected
*/
- #[DataProvider('aliasedTables')]
- public function testDeleteShouldResetTableToUnaliasedTable(array $tableValue, string|TableIdentifier $expected): void
+ public function testDeleteShouldResetTableToUnaliasedTable(array $tableValue, $expected)
{
$delete = new Delete();
$delete->from($tableValue);
@@ -292,18 +290,17 @@ public function testDeleteShouldResetTableToUnaliasedTable(array $tableValue, st
->getMock();
$result->expects($this->once())
->method('getAffectedRows')
- ->willReturn(1);
+ ->will($this->returnValue(1));
$statement = $this->getMockBuilder(StatementInterface::class)
->getMock();
$statement->expects($this->once())
->method('execute')
- ->willReturn($result);
+ ->will($this->returnValue($result));
- $statementExpectation = function (Delete $delete) use ($expected, $statement): MockObject&StatementInterface {
+ $statementExpectation = function ($delete) use ($expected, $statement) {
$state = $delete->getRawState();
- $this->assertIsArray($state);
- $this->assertSame($expected, $state['table']);
+ self::assertSame($expected, $state['table']);
return $statement;
};
@@ -312,14 +309,14 @@ public function testDeleteShouldResetTableToUnaliasedTable(array $tableValue, st
->getMock();
$sql->expects($this->atLeastOnce())
->method('getTable')
- ->willReturn($tableValue);
+ ->will($this->returnValue($tableValue));
$sql->expects($this->once())
->method('delete')
- ->willReturn($delete);
+ ->will($this->returnValue($delete));
$sql->expects($this->once())
->method('prepareStatementForSqlObject')
->with($this->equalTo($delete))
- ->willReturnCallback($statementExpectation);
+ ->will($this->returnCallback($statementExpectation));
$table = new TableGateway(
$tableValue,
@@ -329,15 +326,13 @@ public function testDeleteShouldResetTableToUnaliasedTable(array $tableValue, st
$sql
);
- $table->delete([
+ $result = $table->delete([
'foo' => 'FOO',
]);
$state = $delete->getRawState();
-
- $this->assertIsArray($state);
- $this->assertIsArray($state['table']);
- $this->assertEquals(
+ self::assertIsArray($state['table']);
+ self::assertEquals(
$tableValue,
$state['table']
);
diff --git a/test/unit/TestAsset/ConnectionWrapper.php b/test/unit/TestAsset/ConnectionWrapper.php
index 3b19ecdaa..907ab1ceb 100644
--- a/test/unit/TestAsset/ConnectionWrapper.php
+++ b/test/unit/TestAsset/ConnectionWrapper.php
@@ -7,14 +7,15 @@
/**
* Test asset class used only by {@see \LaminasTest\Db\Adapter\Driver\Pdo\ConnectionTransactionsTest}
*/
-final class ConnectionWrapper extends Connection
+class ConnectionWrapper extends Connection
{
public function __construct()
{
$this->resource = new PdoStubDriver('foo', 'bar', 'baz');
}
- public function getNestedTransactionsCount(): int
+ /** @return int */
+ public function getNestedTransactionsCount()
{
return $this->nestedTransactionsCount;
}
diff --git a/test/unit/TestAsset/DeleteDecorator.php b/test/unit/TestAsset/DeleteDecorator.php
index c2fe688c8..0e19e94b0 100644
--- a/test/unit/TestAsset/DeleteDecorator.php
+++ b/test/unit/TestAsset/DeleteDecorator.php
@@ -4,15 +4,16 @@
use Laminas\Db\Sql;
-final class DeleteDecorator extends Sql\Delete implements Sql\Platform\PlatformDecoratorInterface
+class DeleteDecorator extends Sql\Delete implements Sql\Platform\PlatformDecoratorInterface
{
- protected ?object $subject;
+ /** @var null|object */
+ protected $subject;
/**
* @param null|object $subject
* @return $this Provides a fluent interface
*/
- public function setSubject($subject): static
+ public function setSubject($subject)
{
$this->subject = $subject;
return $this;
diff --git a/test/unit/TestAsset/DeleteIgnore.php b/test/unit/TestAsset/DeleteIgnore.php
index 90d521826..07300367e 100644
--- a/test/unit/TestAsset/DeleteIgnore.php
+++ b/test/unit/TestAsset/DeleteIgnore.php
@@ -7,7 +7,7 @@
use Laminas\Db\Adapter\Platform\PlatformInterface;
use Laminas\Db\Sql\Delete;
-final class DeleteIgnore extends Delete
+class DeleteIgnore extends Delete
{
public const SPECIFICATION_DELETE = 'deleteIgnore';
@@ -17,11 +17,12 @@ final class DeleteIgnore extends Delete
self::SPECIFICATION_WHERE => 'WHERE %1$s',
];
+ /** @return string */
protected function processdeleteIgnore(
PlatformInterface $platform,
?DriverInterface $driver = null,
?ParameterContainer $parameterContainer = null
- ): string {
+ ) {
return parent::processDelete($platform, $driver, $parameterContainer);
}
}
diff --git a/test/unit/TestAsset/InsertDecorator.php b/test/unit/TestAsset/InsertDecorator.php
index e41981d2f..f73b748de 100644
--- a/test/unit/TestAsset/InsertDecorator.php
+++ b/test/unit/TestAsset/InsertDecorator.php
@@ -4,15 +4,16 @@
use Laminas\Db\Sql;
-final class InsertDecorator extends Sql\Insert implements Sql\Platform\PlatformDecoratorInterface
+class InsertDecorator extends Sql\Insert implements Sql\Platform\PlatformDecoratorInterface
{
- protected ?object $subject;
+ /** @var null|object */
+ protected $subject;
/**
* @param null|object $subject
* @return $this Provides a fluent interface
*/
- public function setSubject($subject): static
+ public function setSubject($subject)
{
$this->subject = $subject;
return $this;
diff --git a/test/unit/TestAsset/ObjectToString.php b/test/unit/TestAsset/ObjectToString.php
deleted file mode 100644
index 5a219d730..000000000
--- a/test/unit/TestAsset/ObjectToString.php
+++ /dev/null
@@ -1,17 +0,0 @@
-value;
- }
-}
diff --git a/test/unit/TestAsset/PdoStubDriver.php b/test/unit/TestAsset/PdoStubDriver.php
index 7f226548f..74bb537af 100644
--- a/test/unit/TestAsset/PdoStubDriver.php
+++ b/test/unit/TestAsset/PdoStubDriver.php
@@ -4,7 +4,7 @@
use PDO;
-final class PdoStubDriver extends PDO
+class PdoStubDriver extends PDO
{
public function beginTransaction(): bool
{
@@ -17,10 +17,11 @@ public function commit(): bool
}
/**
+ * @param string $dsn
* @param string $user
* @param string $password
*/
- public function __construct(string $dsn, $user, $password)
+ public function __construct($dsn, $user, $password)
{
}
diff --git a/test/unit/TestAsset/Replace.php b/test/unit/TestAsset/Replace.php
index 761d26d5b..cf903ced1 100644
--- a/test/unit/TestAsset/Replace.php
+++ b/test/unit/TestAsset/Replace.php
@@ -7,7 +7,7 @@
use Laminas\Db\Adapter\Platform\PlatformInterface;
use Laminas\Db\Sql\Insert;
-final class Replace extends Insert
+class Replace extends Insert
{
public const SPECIFICATION_INSERT = 'replace';
@@ -17,11 +17,12 @@ final class Replace extends Insert
self::SPECIFICATION_SELECT => 'REPLACE INTO %1$s %2$s %3$s',
];
+ /** @return null|string */
protected function processreplace(
PlatformInterface $platform,
?DriverInterface $driver = null,
?ParameterContainer $parameterContainer = null
- ): ?string {
+ ) {
return parent::processInsert($platform, $driver, $parameterContainer);
}
}
diff --git a/test/unit/TestAsset/SelectDecorator.php b/test/unit/TestAsset/SelectDecorator.php
index 7a74ba79b..004f0dc38 100644
--- a/test/unit/TestAsset/SelectDecorator.php
+++ b/test/unit/TestAsset/SelectDecorator.php
@@ -4,15 +4,16 @@
use Laminas\Db\Sql;
-final class SelectDecorator extends Sql\Select implements Sql\Platform\PlatformDecoratorInterface
+class SelectDecorator extends Sql\Select implements Sql\Platform\PlatformDecoratorInterface
{
- protected ?object $subject;
+ /** @var null|object */
+ protected $subject;
/**
* @param null|object $subject
* @return $this Provides a fluent interface
*/
- public function setSubject($subject): static
+ public function setSubject($subject)
{
$this->subject = $subject;
return $this;
diff --git a/test/unit/TestAsset/TemporaryResultSet.php b/test/unit/TestAsset/TemporaryResultSet.php
index 75de570ae..dda88d576 100644
--- a/test/unit/TestAsset/TemporaryResultSet.php
+++ b/test/unit/TestAsset/TemporaryResultSet.php
@@ -4,6 +4,6 @@
use Laminas\Db\ResultSet\ResultSet;
-final class TemporaryResultSet extends ResultSet
+class TemporaryResultSet extends ResultSet
{
}
diff --git a/test/unit/TestAsset/TrustingMysqlPlatform.php b/test/unit/TestAsset/TrustingMysqlPlatform.php
index 93ac43e6b..3b4bbbe44 100644
--- a/test/unit/TestAsset/TrustingMysqlPlatform.php
+++ b/test/unit/TestAsset/TrustingMysqlPlatform.php
@@ -4,12 +4,13 @@
use Laminas\Db\Adapter\Platform\Mysql;
-final class TrustingMysqlPlatform extends Mysql
+class TrustingMysqlPlatform extends Mysql
{
/**
* @param string $value
+ * @return string
*/
- public function quoteValue($value): string
+ public function quoteValue($value)
{
return $this->quoteTrustedValue($value);
}
diff --git a/test/unit/TestAsset/TrustingOraclePlatform.php b/test/unit/TestAsset/TrustingOraclePlatform.php
index 5b8cba66e..84477192d 100644
--- a/test/unit/TestAsset/TrustingOraclePlatform.php
+++ b/test/unit/TestAsset/TrustingOraclePlatform.php
@@ -4,12 +4,13 @@
use Laminas\Db\Adapter\Platform\Oracle;
-final class TrustingOraclePlatform extends Oracle
+class TrustingOraclePlatform extends Oracle
{
/**
* @param string $value
+ * @return string
*/
- public function quoteValue($value): string
+ public function quoteValue($value)
{
return $this->quoteTrustedValue($value);
}
diff --git a/test/unit/TestAsset/TrustingSql92Platform.php b/test/unit/TestAsset/TrustingSql92Platform.php
index 9dffdb519..71541841b 100644
--- a/test/unit/TestAsset/TrustingSql92Platform.php
+++ b/test/unit/TestAsset/TrustingSql92Platform.php
@@ -4,12 +4,12 @@
use Laminas\Db\Adapter\Platform\Sql92;
-final class TrustingSql92Platform extends Sql92
+class TrustingSql92Platform extends Sql92
{
/**
* {@inheritDoc}
*/
- public function quoteValue($value): string
+ public function quoteValue($value)
{
return $this->quoteTrustedValue($value);
}
diff --git a/test/unit/TestAsset/TrustingSqlServerPlatform.php b/test/unit/TestAsset/TrustingSqlServerPlatform.php
index ece667fd2..0f986e1bc 100644
--- a/test/unit/TestAsset/TrustingSqlServerPlatform.php
+++ b/test/unit/TestAsset/TrustingSqlServerPlatform.php
@@ -4,12 +4,13 @@
use Laminas\Db\Adapter\Platform\SqlServer;
-final class TrustingSqlServerPlatform extends SqlServer
+class TrustingSqlServerPlatform extends SqlServer
{
/**
* @param string $value
+ * @return string
*/
- public function quoteValue($value): string
+ public function quoteValue($value)
{
return $this->quoteTrustedValue($value);
}
diff --git a/test/unit/TestAsset/UpdateDecorator.php b/test/unit/TestAsset/UpdateDecorator.php
index 1e7cfffd3..fa1762bcd 100644
--- a/test/unit/TestAsset/UpdateDecorator.php
+++ b/test/unit/TestAsset/UpdateDecorator.php
@@ -4,15 +4,16 @@
use Laminas\Db\Sql;
-final class UpdateDecorator extends Sql\Update implements Sql\Platform\PlatformDecoratorInterface
+class UpdateDecorator extends Sql\Update implements Sql\Platform\PlatformDecoratorInterface
{
- protected ?object $subject;
+ /** @var null|object $subject */
+ protected $subject;
/**
* @param null|object $subject
* @return $this Provides a fluent interface
*/
- public function setSubject($subject): static
+ public function setSubject($subject)
{
$this->subject = $subject;
return $this;
diff --git a/test/unit/TestAsset/UpdateIgnore.php b/test/unit/TestAsset/UpdateIgnore.php
index d95a8a089..1837b56b7 100644
--- a/test/unit/TestAsset/UpdateIgnore.php
+++ b/test/unit/TestAsset/UpdateIgnore.php
@@ -7,16 +7,8 @@
use Laminas\Db\Adapter\Platform\PlatformInterface;
use Laminas\Db\Sql\Update;
-/**
- * @psalm-return UpdateIgnore&static
- */
-final class UpdateIgnore extends Update
+class UpdateIgnore extends Update
{
- /**
- * Override specification update for testing
- *
- * @psalm-suppress InvalidClassConstantType
- */
public const SPECIFICATION_UPDATE = 'updateIgnore';
/** @var array */
@@ -26,11 +18,12 @@ final class UpdateIgnore extends Update
self::SPECIFICATION_WHERE => 'WHERE %1$s',
];
+ /** @return string */
protected function processupdateIgnore(
PlatformInterface $platform,
?DriverInterface $driver = null,
?ParameterContainer $parameterContainer = null
- ): string {
+ ) {
return parent::processUpdate($platform, $driver, $parameterContainer);
}
}