Skip to content

Commit

Permalink
Fix object builder tests (#1251)
Browse files Browse the repository at this point in the history
Fix object builder tests for entities having fields of array, boolean,
enum and LOB type.
  • Loading branch information
cristianoc72 authored and marcj committed Aug 22, 2016
1 parent 4ad2536 commit d03278e
Show file tree
Hide file tree
Showing 48 changed files with 1,324 additions and 513 deletions.
142 changes: 120 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,136 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- hhvm
- 7.0
- nightly

env:
- DB=agnostic #only database agnostic tests
- DB=mysql DB_USER=root #only database tests against mysql
- DB=pgsql DB_USER=postgres DB_NAME=postgres #only database tests against postgresql
- DB=agnostic #only database agnostic tests
- DB=mysql
- DB=sqlite

before_script:
# Composer
- wget http://getcomposer.org/composer.phar
- php composer.phar install --prefer-source
install:
- rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
- composer install

- if [ "$DB" != 'agnostic' ]; then ./tests/bin/setup.$DB.sh; fi # setup only for integration tests
before_script:
- if [[ $DB != 'agnostic' && $DB != 'sqlite' ]]; then ./tests/bin/setup.$DB.sh; fi

script:
- ./tests/bin/phpunit.$DB.sh;
- ./vendor/bin/phpunit -v -c tests/$DB.phpunit.xml;


matrix:
fast_finish: true
allow_failures:
- php: hhvm
include:
- php: 5.5
env: DB=mysql MARIADB=5.5
addons:
mariadb: 5.5
- php: 5.6
env: DB=mysql MARIADB=5.5
addons:
mariadb: 5.5
- php: 7.0
env: DB=mysql MARIADB=5.5
addons:
mariadb: 5.5

- php: 5.5
env: DB=mysql MARIADB=10.0
addons:
mariadb: 10.0
- php: 5.6
env: DB=mysql MARIADB=10.0
addons:
mariadb: 10.0
- php: 7.0
env: DB=mysql MARIADB=10.0
addons:
mariadb: 10.0

# - php: 5.5
# env: DB=mysql MARIADB=10.1
# addons:
# mariadb: 10.1
# - php: 5.6
# env: DB=mysql MARIADB=10.1
# addons:
# mariadb: 10.1
# - php: 7.0
# env: DB=mysql MARIADB=10.1
# addons:
# mariadb: 10.1

- php: 5.5
env: DB=pgsql POSTGRES=9.1
addons:
postgresql: 9.1
- php: 5.6
env: DB=pgsql POSTGRES=9.1
addons:
postgresql: 9.1
- php: 7.0
env: DB=pgsql POSTGRES=9.1
addons:
postgresql: 9.1

- php: 5.5
env: DB=pgsql POSTGRES=9.2
addons:
postgresql: 9.2
- php: 5.6
exclude:
- php: hhvm
env: DB=pgsql DB_USER=postgres DB_NAME=postgres # driver currently unsupported by HHVM
- php: hhvm
env: DB=sqlite # some issues at the moment

#after_script:
# - php vendor/bin/coveralls -v
env: DB=pgsql POSTGRES=9.2
addons:
postgresql: 9.2
- php: 7.0
env: DB=pgsql POSTGRES=9.2
addons:
postgresql: 9.2

- php: 5.5
env: DB=pgsql POSTGRES=9.3
addons:
postgresql: 9.3
- php: 5.6
env: DB=pgsql POSTGRES=9.3
addons:
postgresql: 9.3
- php: 7.0
env: DB=pgsql POSTGRES=9.3
addons:
postgresql: 9.3

- php: 5.5
env: DB=pgsql POSTGRES=9.4
addons:
postgresql: 9.4
- php: 5.6
env: DB=pgsql POSTGRES=9.4
addons:
postgresql: 9.4
- php: 7.0
env: DB=pgsql POSTGRES=9.4
addons:
postgresql: 9.4

allow_failures:
- php: nightly

fast_finish: true

# cache vendors
cache:
directories:
- vendor
- $HOME/.composer/cache

# This triggers builds to run on the new TravisCI infrastructure.
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false

notifications:
webhooks:
- http://propel.jarves.io/build.php
- https://webhooks.gitter.im/e/206efe76e183f9ade489
5 changes: 2 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ machine:
DB_USER: ubuntu
DB_NAME: circle_test
php:
version: 5.4.9
version: 5.5.9
dependencies:
pre:
- sed -i 's/^;//' ~/.phpenv/versions/$(phpenv global)/etc/conf.d/xdebug.ini
- echo "memory_limit=520M" > ~/.phpenv/versions/$(phpenv global)/etc/conf.d/memlimit.ini
- if [ "$CIRCLE_NODE_INDEX" = "1" ]; then ./tests/bin/setup.mysql.sh; fi
- if [ "$CIRCLE_NODE_INDEX" = "2" ]; then ./tests/bin/setup.pgsql.sh; fi
- if [ "$CIRCLE_NODE_INDEX" = "3" ]; then ./tests/bin/setup.sqlite.sh; fi

notify:
webhooks:
Expand All @@ -20,5 +19,5 @@ notify:

test:
override:
- ./tests/bin/phpunit.circleci.sh:
- ./tests/bin/circleci.sh:
parallel: true
34 changes: 13 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>

Expand All @@ -17,6 +16,19 @@
</testsuite>
</testsuites>

<groups>
<exclude>
<group>pgsql</group>
<group>mysql</group>
</exclude>
</groups>

<php>
<env name="DB" value="mysql"/> <!-- mysql, sqlite, pgsql -->
<env name="DB_USER" value=""/>
<env name="DB_PW" value=""/>
</php>

<logging>
<!--<log type="coverage-php" target="tests/clover.cov"/>-->
<!--<log type="coverage-html" target="tests/coverage-report" charset="UTF-8"
Expand All @@ -26,26 +38,6 @@
<filter>
<whitelist>
<directory>src/Propel/</directory>
<exclude>
<directory>src/Propel/Generator/Builder/SQL/Mssql</directory>
<directory>src/Propel/Generator/Builder/SQL/Oracle</directory>
<directory>src/Propel/Generator/Builder/SQL/Sqlsrv</directory>

<file>src/Propel/Generator/Platform/MssqlPlatform.php</file>
<file>src/Propel/Generator/Platform/OraclePlatform.php</file>
<file>src/Propel/Generator/Platform/SqlsrvPlatform.php</file>

<file>src/Propel/Generator/Reverse/MssqlSchemaParser.php</file>
<file>src/Propel/Generator/Reverse/OracleSchemaParser.php</file>
<file>src/Propel/Generator/Reverse/SqlsrvSchemaParser.php</file>

<directory>src/Propel/Runtime/Adapter/MSSQL</directory>
<file>src/Propel/Runtime/Adapter/Pdo/MssqlAdapter.php</file>
<file>src/Propel/Runtime/Adapter/Pdo/OracleAdapter.php</file>
<file>src/Propel/Runtime/Adapter/Pdo/SqlsrvAdapter.php</file>

<file>src/Propel/Runtime/Adapter/Pdo/SqlsrvAdapter.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
4 changes: 4 additions & 0 deletions src/Propel/Common/Config/XmlToArrayConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static function convert($xmlToParse)
protected static function simpleXmlToArray($xml)
{
$ar = array();

foreach ($xml->children() as $k => $v) {
// recurse the child
$child = self::simpleXmlToArray($v);
Expand All @@ -96,6 +97,9 @@ protected static function simpleXmlToArray($xml)
// then we will name the current key after that id
$k = self::getConvertedXmlValue($av);
} else {
if ('' === $child) {
$child = [];
}
// otherwise, just add the attribute like a child element
$child[$ak] = self::getConvertedXmlValue($av);
}
Expand Down
19 changes: 15 additions & 4 deletions src/Propel/Common/Types/SQL/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Propel\Generator\Model\Field;
use Propel\Generator\Model\PropelTypes;
use Propel\Runtime\Map\FieldMap;
use Propel\Runtime\Util\PropelDateTime;

class DateTimeType extends AbstractType
{
Expand All @@ -25,7 +26,10 @@ public function decorateGetterMethod(PhpMethod $method, Field $field)
$method->setBody($body);
}

public function databaseToProperty($value, FieldMap $fieldMap)
/**
* {@inheritdoc}
*/
public function propertyToDatabase($value, FieldMap $fieldMap)
{
if ($value instanceof \DateTime) {
$format = 'U';
Expand All @@ -46,8 +50,15 @@ public function databaseToProperty($value, FieldMap $fieldMap)
return $value;
}

public function propertyToDatabase($value, FieldMap $fieldMap)
/**
* {@inheritdoc}
*/
public function databaseToProperty($value, FieldMap $fieldMap)
{
return $this->databaseToProperty($value, $fieldMap);
if (!($value instanceof \DateTime)) {
$value = PropelDateTime::newInstance($value);
}

return $value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function process()
$behavior = $this->getBehavior();
$entityName = $this->getEntity()->getFullClassName();

$col = '';
$col = [];

if ($behavior->useScope()) {

Expand Down
3 changes: 2 additions & 1 deletion src/Propel/Generator/Behavior/Sortable/SortableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function objectBuilderModification(ObjectBuilder $builder)

if ($this->useScope()) {
$this->applyComponent('Object\OldScope', $builder);

if ('scope_value' !== $this->getParameter('scope_field')) {
$this->applyComponent('Object\ScopeAccessorMethod', $builder);
}
Expand Down Expand Up @@ -194,6 +194,7 @@ public function generateScopePhp()

$methodSignature = [];
$buildScope = [];
$buildScopeVars = [];

foreach ($this->getScopes() as $idx => $scope) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public function buildClass()
$this->definition = new PhpTrait($this->getFullClassName());

if ($this->isAddGenericMutators()) {
$this->applyComponent('ActiveRecordTrait\\BooleanAccessorMethods');
$this->applyComponent('ActiveRecordTrait\\GetPropelConfigurationMethod');
$this->applyComponent('ActiveRecordTrait\\ReloadMethod');
$this->applyComponent('ActiveRecordTrait\\SaveMethod');
$this->applyComponent('ActiveRecordTrait\\IsNewMethod');
$this->applyComponent('ActiveRecordTrait\\DeleteMethod');
}


if ($this->isAddGenericMutators()) {
$this->applyComponent('ActiveRecordTrait\\GenericMutatorMethods');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Propel\Generator\Builder\Om\Component\ActiveRecordTrait;

use Propel\Generator\Builder\Om\Component\BuildComponent;
use Propel\Generator\Model\Field;

/**
* Add boolean accessors (`isXxx` or `hasXxx`) to ActiveRecord trait.
*
* @author Cristiano Cinotti <cristianocinotti@gmail.com>
* @package Propel\Generator\Builder\Om\Component\ActiveRecordTrait
*/
class BooleanAccessorMethods extends BuildComponent
{
public function process()
{
foreach ($this->getBuilder()->getEntity()->getFields() as $field) {
if ($field->isBooleanType()) {
$this->addMethod($this->getBooleanAccessorName($field), $field->getAccessorVisibility())
->setDescription("Get the value of `{$field->getName()}` field")
->setType('bool')
->setBody("return \$this->{$field->getName()};")
;
}
}
}

/**
* Returns the name to be used as boolean accessor name
*
* @param Field $field
* @return string
*/
protected function getBooleanAccessorName(Field $field)
{
$name = $field->getCamelCaseName();
if (!preg_match('/^(?:is|has)(?=[A-Z])/', $name)) {
$name = 'is' . ucfirst($name);
}
return $name;
}
}
Loading

0 comments on commit d03278e

Please sign in to comment.