Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

explicitly display mysqli error #269

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
start tests, mysqli mock not working
ConorSheehan1 committed Oct 23, 2017
commit cdd6541422f7ee1c5724eea4614c1b8d49b93712
56 changes: 56 additions & 0 deletions test/Adapter/Driver/Mysqli/StatementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Db\Adapter\Driver\Mysqli;

use Zend\Db\Adapter\Driver\Mysqli\Statement;

use Zend\Db\Adapter\Driver\Mysqli\Connection;
use Zend\Db\Adapter\Driver\StatementInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Profiler;

class MysliTest extends \PHPUnit_Framework_TestCase
{

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->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());
// }
}
23 changes: 23 additions & 0 deletions test/Adapter/Driver/Mysqli/TestAsset/MysqliMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Db\Adapter\Driver\Mysqli\TestAsset;

class MysqliMock extends \mysqli
{
protected $mockStatement;

public function __construct()
{
// not sure what to do here
// all I really need is mysqli->prepare so line 206 in Statement.php throws the correct exception
// $this->resource = $this->mysqli->prepare($sql);
parent::__construct();
}
}