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

Fix for #35 and new integration test #304

Merged
merged 17 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 26 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,71 @@ env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="satooshi/php-coveralls"
- TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME=localhost
- TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD=
- TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME=localhost

matrix:
include:
- php: 5.6
env:
- DEPS=lowest
- php: 5.6
services:
- mysql
env:
- DEPS=locked
- LEGACY_DEPS="phpunit/phpunit"
- TEST_INTEGRATION=true
- TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL=true
- php: 5.6
env:
- DEPS=latest
- php: 7.0
env:
- DEPS=lowest
- php: 7.0
services:
- mysql
env:
- DEPS=locked
- LEGACY_DEPS="phpunit/phpunit"
- TEST_INTEGRATION=true
- TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL=true
- php: 7.0
env:
- DEPS=latest
- php: 7.1
env:
- DEPS=lowest
- php: 7.1
services:
- mysql
env:
- DEPS=locked
- CS_CHECK=true
- TEST_COVERAGE=true
- TEST_INTEGRATION=true
- TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL=true
- php: 7.1
env:
- DEPS=latest
- php: 7.2
env:
- DEPS=lowest
- php: 7.2
services:
- mysql
env:
- DEPS=locked
- TEST_INTEGRATION=true
- TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL=true
- php: 7.2
services:
- postgresql
addons:
postgresql: "9.6"
env:
- DEPS=locked
- TEST_INTEGRATION=true
- TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL=true
- php: 7.2
env:
- DEPS=latest
Expand All @@ -69,11 +91,10 @@ install:
- stty cols 120 && composer show

before_script:
- .ci/mysql_fixtures_travis.sh
- .ci/pgsql_fixtures.sh

script:
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $TEST_INTEGRATION == 'true' ]]; then composer test-integration ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi

after_script:
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"test/autoload.php"
],
"psr-4": {
"ZendTest\\Db\\": "test/"
"ZendTest\\Db\\": "test/unit",
"ZendIntegrationTest\\Db\\": "test/integration"
}
},
"config": {
Expand All @@ -64,8 +65,9 @@
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test": "phpunit --colors=always --testsuite \"unit test\"",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"test-integration" : "phpunit --colors=always --testsuite \"integration test\"",
"upload-coverage": "coveralls -v"
}
}
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ruleset name="Zend Framework coding standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml" />
<rule ref="PSR1.Files.SideEffects">
<exclude-pattern>*/test/Adapter/Driver/IbmDb2/StatementTest.php</exclude-pattern>
<exclude-pattern>*/test/unit/Adapter/Driver/IbmDb2/StatementTest.php</exclude-pattern>
</rule>

<!-- Paths to check -->
Expand Down
19 changes: 11 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="zend-db Test Suite">
<directory>./test</directory>
<testsuite name="unit test">
<directory>./test/unit</directory>
</testsuite>
<testsuite name="integration test">
<directory>./test/integration</directory>
</testsuite>
</testsuites>

Expand All @@ -19,7 +22,7 @@
</filter>

<listeners>
<listener class="ZendTest\Db\IntegrationTestListener" file="./test/IntegrationTestListener.php" />
<listener class="ZendIntegrationTest\Db\IntegrationTestListener" file="./test/integration/IntegrationTestListener.php" />
</listeners>

<php>
Expand All @@ -29,9 +32,9 @@

<!-- Integration Test Variables -->
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL" value="false" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME" value="192.168.20.20" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_USERNAME" value="root" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD" value="Password123" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME" value="localhost" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_USERNAME" value="travis" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD" value="" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE" value="zenddb_test" />

<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV" value="false" />
Expand All @@ -53,9 +56,9 @@
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_IBMDB2_DATABASE" value="" />

<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL" value="false" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME" value="192.168.20.20" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME" value="localhost" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_USERNAME" value="postgres" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_PASSWORD" value="postgres" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_PASSWORD" value="" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_DATABASE" value="zenddb_test" />

<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_SQLITE_MEMORY" value="true" />
Expand Down
9 changes: 8 additions & 1 deletion src/Sql/Insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
namespace Zend\Db\Sql;

use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Pdo\Pdo;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Platform\PlatformInterface;

class Insert extends AbstractPreparableSql
{
/**#@+
/**
* Constants
*
* @const
Expand Down Expand Up @@ -180,10 +181,16 @@ protected function processInsert(

$columns = [];
$values = [];
$i = 0;

foreach ($this->columns as $column => $value) {
$columns[] = $platform->quoteIdentifier($column);
if (is_scalar($value) && $parameterContainer) {
// use incremental value instead of column name for PDO
// @see https://github.com/zendframework/zend-db/issues/35
if ($driver instanceof Pdo) {
$column = 'c_' . $i++;
}
$values[] = $driver->formatParameterName($column);
$parameterContainer->offsetSet($column, $value);
} else {
Expand Down
7 changes: 7 additions & 0 deletions src/Sql/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Platform\PlatformInterface;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Pdo\Pdo;
use Zend\Stdlib\PriorityList;

/**
Expand Down Expand Up @@ -186,9 +187,15 @@ protected function processSet(
ParameterContainer $parameterContainer = null
) {
$setSql = [];
$i = 0;
foreach ($this->set as $column => $value) {
$prefix = $platform->quoteIdentifier($column) . ' = ';
if (is_scalar($value) && $parameterContainer) {
// use incremental value instead of column name for PDO
// @see https://github.com/zendframework/zend-db/issues/35
if ($driver instanceof Pdo) {
$column = 'c_' . $i++;
}
$setSql[] = $prefix . $driver->formatParameterName($column);
$parameterContainer->offsetSet($column, $value);
} else {
Expand Down
32 changes: 0 additions & 32 deletions test/Adapter/Platform/SqlServerIntegrationTest.php

This file was deleted.

Loading