Skip to content

Commit

Permalink
laminas#214 @fix: "MySQL integration test fail in section testNamedPa…
Browse files Browse the repository at this point in the history
…rameters"/change code style by phpcs and "laminas/laminas-coding-standard"
  • Loading branch information
ZVanoZ committed Sep 24, 2021
1 parent b460583 commit a957818
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
20 changes: 20 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
47 changes: 24 additions & 23 deletions test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo\Mysql;

use Exception;
use Laminas\Db\Adapter\Driver\Pdo\Result as PdoResult;
use Laminas\Db\Adapter\Driver\ResultInterface;
use Laminas\Db\Adapter\Driver\StatementInterface;
use Laminas\Db\Adapter\Exception\RuntimeException;
use Laminas\Db\ResultSet\ResultSet;
use Laminas\Db\Sql\Sql;
Expand Down Expand Up @@ -47,7 +49,7 @@ public function testQuery(string $query, array $params, array $expected)
$this->assertInstanceOf(ResultSet::class, $result);
$current = $result->current();
// test as array value
$this->assertEquals($expected, (array)$current);
$this->assertEquals($expected, (array) $current);
// test as object value
foreach ($expected as $key => $value) {
$this->assertEquals($value, $current->$key);
Expand Down Expand Up @@ -76,9 +78,11 @@ public function testSelectWithNotPermittedBindParamName()
* -- 0 ":c_0" "name" varchar(255)
* -- 1 ":c_1" "value" varchar(255)
* -- 2 ":where1" "id" int
*
* @see https://github.com/laminas/laminas-db/issues/47
* @see https://github.com/laminas/laminas-db/issues/214
* @return \Laminas\Db\Adapter\Driver\StatementInterface
*
* @return StatementInterface
*/
protected function getStatementForTestBinding()
{
Expand All @@ -88,14 +92,12 @@ protected function getStatementForTestBinding()
*/
$update = $sql->update('test');
$update->set([
'name' => ':name',
'name' => ':name',
'value' => ':value',
])->where([
'id' => ':id'
'id' => ':id',
]);
$stmt = $sql->prepareStatementForSqlObject($update);

return $stmt;
return $sql->prepareStatementForSqlObject($update);
}

/**
Expand All @@ -108,12 +110,12 @@ public function testBindParamByIndexIsFail()
try {
//positional parameters - is invalid
$stmt->execute([
1, //FAIL -- 0 ":c_0" "name" varchar(255)
1, // FAIL -- 0 ":c_0" "name" varchar(255)
'foo', //OK -- 1 ":c_1" "value" varchar(255)
'bar', //FAIL -- 2 ":where1" "id" int
]);
$this->assertTrue(false, __METHOD__, "/Fail. Extect exception.");
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertTrue(true, __METHOD__, "/Success. We have an exception: " . $e->getMessage());
}
}
Expand All @@ -128,7 +130,7 @@ public function testBindParamByIndexIsSuccess()
$result = $stmt->execute([
'bar', //OK -- 0 ":c_0" "name" varchar(255)
'foo', //OK -- 1 ":c_1" "value" varchar(255)
1, //OK -- 2 ":where1" "id" int
1, // OK -- 2 ":where1" "id" int
]);
$this->assertInstanceOf(ResultInterface::class, $result);
}
Expand All @@ -143,12 +145,12 @@ public function testBindParamByNameIsFail()
try {
//"mapped" named parameters
$stmt->execute([
'c_0' => 1, //FAIL -- 0 ":c_0" "name" varchar(255)
'c_1' => 'foo', //OK -- 1 ":c_1" "value" varchar(255)
'c_0' => 1, // FAIL -- 0 ":c_0" "name" varchar(255)
'c_1' => 'foo', //OK -- 1 ":c_1" "value" varchar(255)
'where1' => 'bar', //FAIL -- 2 ":where1" "id" int
]);
$this->assertTrue(false, __METHOD__, "/Fail. Extect exception.");
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertTrue(true, __METHOD__, "/Success. We have an exception: " . $e->getMessage());
}
}
Expand All @@ -161,9 +163,9 @@ public function testBindParamByNameIsSuccess()
$stmt = $this->getStatementForTestBinding();
//"mapped" named parameters
$result = $stmt->execute([
'c_0' => 'bar', //OK -- 0 ":c_0" "name" varchar(255)
'c_1' => 'foo', //OK -- 1 ":c_1" "value" varchar(255)
'where1' => 1, //OK -- 2 ":where1" "id" int
'c_0' => 'bar', //OK -- 0 ":c_0" "name" varchar(255)
'c_1' => 'foo', //OK -- 1 ":c_1" "value" varchar(255)
'where1' => 1, // OK -- 2 ":where1" "id" int
]);
$this->assertInstanceOf(ResultInterface::class, $result);
}
Expand All @@ -178,12 +180,12 @@ public function testBindParamByFieldNameIsFail()
try {
//real named parameters
$stmt->execute([
'name' => 1, //FAIL -- 0 ":c_0" "name" varchar(255)
'value' => 'foo', //OK -- 1 ":c_1" "value" varchar(255)
'id' => 'bar', //FAIL -- 2 ":where1" "id" int
'name' => 1, // FAIL -- 0 ":c_0" "name" varchar(255)
'value' => 'foo', //OK -- 1 ":c_1" "value" varchar(255)
'id' => 'bar', //FAIL -- 2 ":where1" "id" int
]);
$this->assertTrue(false, __METHOD__, "/Fail. Extect exception.");
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertTrue(true, __METHOD__, "/Success. We have an exception: " . $e->getMessage());
}
}
Expand All @@ -196,11 +198,10 @@ public function testBindParamByFieldNameIsSuccess()
$stmt = $this->getStatementForTestBinding();
//real named parameters
$result = $stmt->execute([
'name' => 'bar', //OK -- 0 ":c_0" "name" varchar(255)
'name' => 'bar', //OK -- 0 ":c_0" "name" varchar(255)
'value' => 'foo', //OK -- 1 ":c_1" "value" varchar(255)
'id' => 1, //OK -- 2 ":where1" "id" int
'id' => 1, // OK -- 2 ":where1" "id" int
]);
$this->assertInstanceOf(ResultInterface::class, $result);
}

}

0 comments on commit a957818

Please sign in to comment.