Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for SQL errors after updating to propel1.6 #662

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
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
34 changes: 4 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
language: php
dist: trusty

branches:
only:
- 1.6
- master
- gh-pages
- php7.4

php:
- 5.4
- 5.5
- hhvm
services: docker

env:
- DB=mysql DB_USER=root

before_script:
# MySQL
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS test; DROP SCHEMA IF EXISTS second_hand_books; DROP SCHEMA IF EXISTS contest; DROP DATABASE IF EXISTS reverse_bookstore; DROP SCHEMA IF EXISTS bookstore_schemas; SET FOREIGN_KEY_CHECKS = 1;'; fi"
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE test; CREATE SCHEMA bookstore_schemas; CREATE SCHEMA contest; CREATE SCHEMA second_hand_books; CREATE DATABASE reverse_bookstore;'; fi"

# Composer
- wget http://getcomposer.org/composer.phar
- php composer.phar install --prefer-source

- ./test/reset_tests.sh

script: vendor/bin/phpunit

matrix:
include:
- php: 5.3
dist: precise
allow_failures:
- php: hhvm
script:
bash docker/run.sh
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "propel/propel1",
"name": "jooola/propel1",
"description": "Propel is an open-source Object-Relational Mapping (ORM) for PHP5.",
"keywords": ["orm", "active record", "mapping", "database", "persistence"],
"homepage": "http://www.propelorm.org/",
Expand All @@ -14,12 +14,15 @@
},
"include-path": ["runtime/lib", "generator/lib"],
"require": {
"php": ">=5.2.4",
"php": "^7.1",
"phing/phing": "~2.4"

},
"require-dev": {
"pear-pear.php.net/PEAR_PackageFileManager2": "@stable",
"phpunit/phpunit": "~4.0||~5.0"
"pear-pear.php.net/pear_packagefilemanager2": "@stable",
"phpunit/phpunit": "^9.0.0",
"phpcompatibility/php-compatibility": "^9.3",
"squizlabs/php_codesniffer": "^3.5"
},
"extra": {
"branch-alias": {
Expand All @@ -32,5 +35,9 @@
"url": "https://pear.php.net"
}
],
"bin": ["generator/bin/propel-gen", "generator/bin/propel-gen.bat"]
"bin": ["generator/bin/propel-gen", "generator/bin/propel-gen.bat"],
"scripts": {
"post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility",
"post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility"
}
}
11 changes: 11 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM thecodingmachine/php:7.4-v3-cli
USER root
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales

RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8

USER docker
ENV LANG en_US.UTF-8

26 changes: 26 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3'
services:
php:
build:
context: .
dockerfile: Dockerfile
working_dir: /usr/src/app
command: phpunit
volumes:
- ../:/usr/src/app
environment:
- PHP_EXTENSIONS=intl pdo_sqlite sqlite3
- STARTUP_COMMAND_1=composer install
- STARTUP_COMMAND_2=bash test/reset_tests.sh

db:
image: percona
command: >
mysqld
--sql-mode="NO_ENGINE_SUBSTITUTION"
--character-set-server="utf8"
--collation-server="utf8_unicode_ci"
--default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
4 changes: 4 additions & 0 deletions docker/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

mysql -u root -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS test; DROP SCHEMA IF EXISTS second_hand_books; DROP SCHEMA IF EXISTS contest; DROP DATABASE IF EXISTS reverse_bookstore; DROP SCHEMA IF EXISTS bookstore_schemas; SET FOREIGN_KEY_CHECKS = 1;'
mysql -u root -e 'CREATE DATABASE test; CREATE SCHEMA bookstore_schemas; CREATE SCHEMA contest; CREATE SCHEMA second_hand_books; CREATE DATABASE reverse_bookstore;'
7 changes: 7 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
cd docker
docker-compose up -d db
sleep 20
docker-compose exec -T db bash < reset.sh
docker-compose build
docker-compose run php
5 changes: 4 additions & 1 deletion generator/lib/builder/om/PHP5ObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,9 @@ protected function addLazyLoaderBody(&$script, Column $col)
try {
\$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$c, \$con);
\$row = \$stmt->fetch(PDO::FETCH_NUM);
if (\$row === false) {
\$row = [null]; // for backward compatibility
}
\$stmt->closeCursor();";
}

Expand Down Expand Up @@ -3284,7 +3287,7 @@ public function isPrimaryKeyNull()
}
$script .= "

return " . join(' && ', $tests) . ";";
return " . implode(' && ', $tests) . ";";
}
$script .= "
}
Expand Down
3 changes: 3 additions & 0 deletions generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ protected function addLazyLoaderBody(&$script, Column $col)
try {
\$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$c, \$con);
\$row = \$stmt->fetch(PDO::FETCH_NUM);
if (\$row === false) {
\$row = [null]; // for backward compatibility
}
\$stmt->closeCursor();";

if ($col->getType() === PropelTypes::CLOB && $this->getPlatform() instanceof OraclePlatform) {
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/builder/om/PHP5PeerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ public static function getPrimaryKeyFromRow(\$row, \$startcol = 0)
if ($table->hasCompositePrimaryKey()) {
$script .= "

return array(" . implode($pks, ', ') . ");";
return array(" . implode(', ', $pks) . ");";
} else {
$script .= "

Expand Down
4 changes: 2 additions & 2 deletions generator/lib/builder/om/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ protected function addFindPk(&$script)
}
$pkType = 'array';
$pkDescription = "
A Primary key composition: " . '[' . join($colNames, ', ') . ']';
A Primary key composition: " . '[' . implode(', ', $colNames) . ']';
$script .= "
* <code>
* \$obj = \$c->findPk(array(" . join($examplePk, ', ') . "), \$con);";
* \$obj = \$c->findPk(array(" . implode(', ', $examplePk) . "), \$con);";
} else {
$pkType = 'mixed';
$script .= "
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/config/GeneratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function getClassname($propname)
// Basically, we want to turn ?.?.?.sqliteDataSQLBuilder into ?.?.?.SqliteDataSQLBuilder
$lastdotpos = strrpos($classpath, '.');
if ($lastdotpos !== false) {
$classpath{$lastdotpos + 1} = strtoupper($classpath{$lastdotpos + 1});
$classpath[$lastdotpos + 1] = strtoupper($classpath[$lastdotpos + 1]);
} else {
// Allows to configure full classname instead of a dot-path notation
if (class_exists($classpath)) {
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/config/QuickGeneratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function parsePseudoIniFile($filepath)
}
foreach ($lines as $line) {
$line = trim($line);
if ($line == "" || $line{0} == '#' || $line{0} == ';') {
if ($line == "" || $line[0] == '#' || $line[0] == ';') {
continue;
}
$pos = strpos($line, '=');
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/model/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function addColumn($data)
}
} else {
$attrib = $data;
$name = $attrib["name"];
$name = $attrib["name"] ?? null;
$this->indexColumns[] = $name;
if (isset($attrib["size"])) {
$this->indexColumnSizes[$name] = $attrib["size"];
Expand Down
5 changes: 3 additions & 2 deletions generator/lib/model/XMLElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @license MIT License
*/

require_once dirname(__FILE__) . '/VendorInfo.php';

/**
* An abstract class for elements represented by XML tags (e.g. Column, Table).
Expand Down Expand Up @@ -109,7 +108,7 @@ protected function getDefaultValueForArray($stringValue)
$values[] = trim($v);
}

$value = implode($values, ' | ');
$value = implode(' | ', $values);
if (empty($value) || ' | ' === $value) {
return null;
}
Expand Down Expand Up @@ -139,6 +138,7 @@ public function addVendorInfo($data)

return $vi;
} else {
require_once dirname(__FILE__) . '/VendorInfo.php';
$vi = new VendorInfo();
$vi->loadFromXML($data);

Expand All @@ -157,6 +157,7 @@ public function getVendorInfoForType($type)
return $this->vendorInfos[$type];
} else {
// return an empty object
require_once dirname(__FILE__) . '/VendorInfo.php';
return new VendorInfo($type);
}
}
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/platform/DefaultPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ public function getPhpArrayString($stringValue)
$values[] = trim($v);
}

$value = implode($values, ' | ');
$value = implode(' | ', $values);
if (empty($value) || ' | ' === $value) {
return null;
}
Expand Down
5 changes: 2 additions & 3 deletions generator/lib/platform/MysqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,8 @@ public function hasSize($sqlType)
*/
public function disconnectedEscapeText($text)
{
// mysql_escape_string doesn't work in PHP >= 5.4
if (version_compare(PHP_VERSION, '5.4', '<') && function_exists('mysql_escape_string')) {
return mysql_escape_string($text);
if (function_exists('mysql_real_escape_string')) {
return mysql_real_escape_string($text);
} else {
return addslashes($text);
}
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/platform/PgsqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public function getModifyColumnDDL(PropelColumnDiff $columnDiff)
foreach ($changedProperties as $key => $property) {
switch ($key) {
case 'defaultValueType':
continue;
continue 2;
case 'size':
case 'type':
case 'scale':
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/task/AbstractPropelDataModelTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ protected function loadDataModels()
foreach ($this->dataModels as $dataModel) {
$validator = new PropelSchemaValidator($dataModel);
if (!$validator->validate()) {
throw new EngineException(sprintf("The database schema contains errors:\n - %s", join("\n - ", $validator->getErrors())));
throw new EngineException(sprintf("The database schema contains errors:\n - %s", implode("\n - ", $validator->getErrors())));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="test/bootstrap.php"
>

Expand Down
7 changes: 6 additions & 1 deletion runtime/lib/Propel.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,12 @@ private static function processDriverOptions($source, &$write_to)
}
$key = constant($key);

$value = $optiondata['value'];
if (is_array($optiondata && isset($optiondata['value']))) {
$value = $optiondata['value'];
} else {
$value = $optiondata;
}

if (is_string($value) && strpos($value, '::') !== false) {
if (!defined($value)) {
throw new PropelException("Invalid PDO option/attribute value specified: " . $value);
Expand Down
8 changes: 4 additions & 4 deletions runtime/lib/adapter/MSSQL/MssqlPropelPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MssqlPropelPDO extends PropelPDO
*
* @return integer
*/
public function beginTransaction()
public function beginTransaction(): bool
{
$return = true;
$opcount = $this->getNestedTransactionCount();
Expand All @@ -49,7 +49,7 @@ public function beginTransaction()
*
* @throws PropelException
*/
public function commit()
public function commit(): bool
{
$return = true;
$opcount = $this->getNestedTransactionCount();
Expand Down Expand Up @@ -78,7 +78,7 @@ public function commit()
*
* @return integer
*/
public function rollBack()
public function rollBack(): bool
{
$return = true;
$opcount = $this->getNestedTransactionCount();
Expand Down Expand Up @@ -132,7 +132,7 @@ public function forceRollBack()
*
* @return integer
*/
public function lastInsertId($seqname = null)
public function lastInsertId($seqname = null): string|false
{
$result = self::query('SELECT SCOPE_IDENTITY()');

Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/collection/PropelArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function toArray($keyColumn = null, $usePrefix = false, $keyType = BasePe
*
* @return array
*/
public function getArrayCopy($keyColumn = null, $usePrefix = false)
public function getArrayCopy($keyColumn = null, $usePrefix = false): array
{
if (null === $keyColumn && false === $usePrefix) {
return parent::getArrayCopy();
Expand Down
8 changes: 4 additions & 4 deletions runtime/lib/collection/PropelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function diff(PropelCollection $collection)
/**
* @return string
*/
public function serialize()
public function serialize(): string
{
$repr = array(
'data' => $this->getArrayCopy(),
Expand All @@ -380,7 +380,7 @@ public function serialize()
*
* @return void
*/
public function unserialize($data)
public function unserialize($data): void
{
$repr = unserialize($data);
$this->exchangeArray($repr['data']);
Expand All @@ -395,7 +395,7 @@ public function unserialize($data)
*
* @return ArrayIterator
*/
public function getIterator()
public function getIterator(): ArrayIterator
{
$this->iterator = new ArrayIterator($this);

Expand Down Expand Up @@ -580,7 +580,7 @@ public function __call($name, $params)
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return (string) $this->exportTo(constant($this->getPeerClass() . '::DEFAULT_STRING_FORMAT'));
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/collection/PropelObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function fromArray($arr)
*
* @return array
*/
public function getArrayCopy($keyColumn = null, $usePrefix = false)
public function getArrayCopy($keyColumn = null, $usePrefix = false): array
{
if (null === $keyColumn && false === $usePrefix) {
return parent::getArrayCopy();
Expand Down
Loading