From 91dd3d78172600b877069fb2254081d67b2df4cb Mon Sep 17 00:00:00 2001 From: conors_nli Date: Tue, 3 Oct 2017 16:38:02 +0100 Subject: [PATCH 1/3] explicitly include mysqli errorno and error --- src/Adapter/Driver/Mysqli/Statement.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Adapter/Driver/Mysqli/Statement.php b/src/Adapter/Driver/Mysqli/Statement.php index 8a9a629b99..46d04a60f4 100644 --- a/src/Adapter/Driver/Mysqli/Statement.php +++ b/src/Adapter/Driver/Mysqli/Statement.php @@ -206,7 +206,8 @@ public function prepare($sql = null) $this->resource = $this->mysqli->prepare($sql); if (!$this->resource instanceof \mysqli_stmt) { throw new Exception\InvalidQueryException( - 'Statement couldn\'t be produced with sql: ' . $sql, + ' Error #' . $this->mysqli->errno . ': ' . $this->mysqli->error . + '. Statement couldn\'t be produced with sql: ' . $sql, null, new Exception\ErrorException($this->mysqli->error, $this->mysqli->errno) ); From c7f7c957e20356c4b408447b8eb02f864ec0de76 Mon Sep 17 00:00:00 2001 From: conors_nli Date: Wed, 4 Oct 2017 09:25:25 +0100 Subject: [PATCH 2/3] use sprintf instead of concat --- src/Adapter/Driver/Mysqli/Statement.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Adapter/Driver/Mysqli/Statement.php b/src/Adapter/Driver/Mysqli/Statement.php index 46d04a60f4..1b8f5152ef 100644 --- a/src/Adapter/Driver/Mysqli/Statement.php +++ b/src/Adapter/Driver/Mysqli/Statement.php @@ -206,8 +206,10 @@ public function prepare($sql = null) $this->resource = $this->mysqli->prepare($sql); if (!$this->resource instanceof \mysqli_stmt) { throw new Exception\InvalidQueryException( - ' Error #' . $this->mysqli->errno . ': ' . $this->mysqli->error . - '. Statement couldn\'t be produced with sql: ' . $sql, + sprintf( + ' Error #%d: %s. Statement couldn\'t be produced with sql: %s', + $this->mysqli->errno, $this->mysqli->error, $sql + ), null, new Exception\ErrorException($this->mysqli->error, $this->mysqli->errno) ); From cdd6541422f7ee1c5724eea4614c1b8d49b93712 Mon Sep 17 00:00:00 2001 From: conors_nli Date: Mon, 23 Oct 2017 15:17:39 +0100 Subject: [PATCH 3/3] start tests, mysqli mock not working --- test/Adapter/Driver/Mysqli/StatementTest.php | 56 +++++++++++++++++++ .../Driver/Mysqli/TestAsset/MysqliMock.php | 23 ++++++++ 2 files changed, 79 insertions(+) create mode 100644 test/Adapter/Driver/Mysqli/StatementTest.php create mode 100644 test/Adapter/Driver/Mysqli/TestAsset/MysqliMock.php diff --git a/test/Adapter/Driver/Mysqli/StatementTest.php b/test/Adapter/Driver/Mysqli/StatementTest.php new file mode 100644 index 0000000000..292b8db8a2 --- /dev/null +++ b/test/Adapter/Driver/Mysqli/StatementTest.php @@ -0,0 +1,56 @@ +statement = new Statement(); + } + + public function testPrepare() + { + $this->statement->initialize(new TestAsset\MysqliMock()); + $this->assertNull($this->statement->prepare('SELECT 1')); + } + + /** + * intentionally throw exception to test error contains valid string + */ + // public function testMysqliStatementPrepareException(){ + // $this->statement = new Statement(new Connection()); + // // $this->statement->initialize(new mysqli("localhost", "test", "test", "test", 3306)); + + // // $this->_connection = mysqli_connect('localhost', 'root', ''); + // // $this->_execute('USE playpen'); + // $this->statement->setSql('SELECT * FROM test WHERE;'); + // try{ + // $this->statement->prepare(); + // // } catch (InvalidQueryException $e){ + // } catch (Exception $e){ + // fwrite(STDOUT, $e->getMessage()); + // } + // // fwrite(STDOUT, $this->statement->getSql()); + // } +} \ No newline at end of file diff --git a/test/Adapter/Driver/Mysqli/TestAsset/MysqliMock.php b/test/Adapter/Driver/Mysqli/TestAsset/MysqliMock.php new file mode 100644 index 0000000000..946f59e9ea --- /dev/null +++ b/test/Adapter/Driver/Mysqli/TestAsset/MysqliMock.php @@ -0,0 +1,23 @@ +prepare so line 206 in Statement.php throws the correct exception + // $this->resource = $this->mysqli->prepare($sql); + parent::__construct(); + } +} \ No newline at end of file