From a957818aad4fbfa433e2d2074f3066d060170b63 Mon Sep 17 00:00:00 2001 From: ZVanoZ Date: Fri, 24 Sep 2021 17:15:59 +0300 Subject: [PATCH] #214 @fix: "MySQL integration test fail in section testNamedParameters"/change code style by phpcs and "laminas/laminas-coding-standard" --- phpcs.xml | 20 ++++++++ .../Adapter/Driver/Pdo/Mysql/QueryTest.php | 47 ++++++++++--------- 2 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 phpcs.xml diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..fcef203d --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + src + test + + + + \ No newline at end of file diff --git a/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php b/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php index bcc72e16..10142bca 100644 --- a/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php +++ b/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php @@ -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; @@ -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); @@ -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() { @@ -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); } /** @@ -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()); } } @@ -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); } @@ -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()); } } @@ -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); } @@ -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()); } } @@ -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); } - }