Skip to content

Commit

Permalink
Fixes zendframework#330 current NULL for mysqli
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel authored and weierophinney committed Mar 12, 2019
1 parent 6df64e0 commit dd6b251
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/Adapter/Driver/Mysqli/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class Result implements
protected $nextComplete = false;

/**
* @var bool
* @var mixed
*/
protected $currentData = false;
protected $currentData = null;

/**
*
Expand Down
32 changes: 1 addition & 31 deletions test/integration/Adapter/Driver/Mysqli/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,7 @@
class ConnectionTest extends TestCase
{

protected $variables = [
'hostname' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME',
'username' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_USERNAME',
'password' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD',
'database' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE',
];

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
if (! getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL')) {
$this->markTestSkipped('Mysqli integration test disabled');
}

if (! extension_loaded('mysqli')) {
$this->fail('The phpunit group integration-mysqli was enabled, but the extension is not loaded.');
}

foreach ($this->variables as $name => $value) {
if (! getenv($value)) {
$this->markTestSkipped(sprintf(
'Missing required variable %s from phpunit.xml for this integration test',
$value
));
}
$this->variables[$name] = getenv($value);
}
}
use TraitSetup;

public function testConnectionOk()
{
Expand Down
50 changes: 50 additions & 0 deletions test/integration/Adapter/Driver/Mysqli/TableGatewayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace ZendIntegrationTest\Db\Adapter\Driver\Mysqli;

use PHPUnit\Framework\TestCase;
use Zend\Db\Adapter\Adapter;
use Zend\Db\TableGateway\TableGateway;

class TableGatewayTest extends TestCase
{
use TraitSetup;

/**
* @see https://github.com/zendframework/zend-db/issues/330
*/
public function testSelectWithEmptyCurrentWithBufferResult()
{
$adapter = new Adapter([
'driver' => 'mysqli',
'database' => $this->variables['database'],
'hostname' => $this->variables['hostname'],
'username' => $this->variables['username'],
'password' => $this->variables['password'],
'options' => ['buffer_results' => true]
]);
$tableGateway = new TableGateway('test', $adapter);
$rowset = $tableGateway->select('id = 0');

$this->assertNull($rowset->current());
}

/**
* @see https://github.com/zendframework/zend-db/issues/330
*/
public function testSelectWithEmptyCurrentWithoutBufferResult()
{
$adapter = new Adapter([
'driver' => 'mysqli',
'database' => $this->variables['database'],
'hostname' => $this->variables['hostname'],
'username' => $this->variables['username'],
'password' => $this->variables['password'],
'options' => ['buffer_results' => false]
]);
$tableGateway = new TableGateway('test', $adapter);
$rowset = $tableGateway->select('id = 0');

$this->assertNull($rowset->current());
}
}
43 changes: 43 additions & 0 deletions test/integration/Adapter/Driver/Mysqli/TraitSetup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @see https://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
*/

namespace ZendIntegrationTest\Db\Adapter\Driver\Mysqli;

trait TraitSetup
{
protected $variables = [
'hostname' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME',
'username' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_USERNAME',
'password' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD',
'database' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE',
];

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
if (! getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL')) {
$this->markTestSkipped('Mysqli integration test disabled');
}

if (! extension_loaded('mysqli')) {
$this->fail('The phpunit group integration-mysqli was enabled, but the extension is not loaded.');
}

foreach ($this->variables as $name => $value) {
if (! getenv($value)) {
$this->markTestSkipped(sprintf(
'Missing required variable %s from phpunit.xml for this integration test',
$value
));
}
$this->variables[$name] = getenv($value);
}
}
}

0 comments on commit dd6b251

Please sign in to comment.