Skip to content
Extraits de code Groupes Projets
Valider 01a93308 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

refs #8689 started working on PHP 7 support

parent 7be1092d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de avec 286 ajouts et 145 suppressions
......@@ -10,6 +10,7 @@
language: php
php:
- 7
- 5.6
- 5.3.3
# - hhvm
......@@ -43,6 +44,7 @@ matrix:
fast_finish: true
allow_failures:
- php: hhvm
- php: 7
exclude:
# Run test suites separately only on PHP 5.6 with PDO
- php: 5.3.3
......@@ -51,6 +53,8 @@ matrix:
env: TEST_SUITE=IntegrationTests MYSQL_ADAPTER=PDO_MYSQL
- php: 5.3.3
env: TEST_SUITE=AllTests MYSQL_ADAPTER=PDO_MYSQL
- php: 7
env: TEST_SUITE=AllTests MYSQL_ADAPTER=PDO_MYSQL
- php: 5.3.3
env: TEST_SUITE=UnitTests MYSQL_ADAPTER=PDO_MYSQL
- php: hhvm
......@@ -69,6 +73,8 @@ matrix:
env: TEST_SUITE=AllTests MYSQL_ADAPTER=PDO_MYSQL
- php: 5.3.3
env: TEST_SUITE=AllTests MYSQL_ADAPTER=MYSQLI
- php: 7
env: TEST_SUITE=AllTests MYSQL_ADAPTER=MYSQLI
- php: hhvm
env: TEST_SUITE=AllTests MYSQL_ADAPTER=MYSQLI
# Javascript tests need to run only on one PHP version
......@@ -76,11 +82,15 @@ matrix:
env: TEST_SUITE=JavascriptTests MYSQL_ADAPTER=PDO_MYSQL SKIP_COMPOSER_INSTALL=1
- php: hhvm
env: TEST_SUITE=JavascriptTests MYSQL_ADAPTER=PDO_MYSQL SKIP_COMPOSER_INSTALL=1
- php: 7
env: TEST_SUITE=JavascriptTests MYSQL_ADAPTER=PDO_MYSQL SKIP_COMPOSER_INSTALL=1
# AngularJS tests need to run only on one PHP version
- php: 5.3.3
env: TEST_SUITE=AngularJSTests MYSQL_ADAPTER=PDO_MYSQL SKIP_COMPOSER_INSTALL=1
- php: hhvm
env: TEST_SUITE=AngularJSTests MYSQL_ADAPTER=PDO_MYSQL SKIP_COMPOSER_INSTALL=1
- php: 7
env: TEST_SUITE=AngularJSTests MYSQL_ADAPTER=PDO_MYSQL SKIP_COMPOSER_INSTALL=1
sudo: required
......@@ -93,8 +103,8 @@ before_install:
install:
- git fetch -q
- export GENERATE_TRAVIS_YML_COMMAND="php ./tests/travis/generator/main.php generate:travis-yml --core --verbose"
- '[[ "$TRAVIS_JOB_NUMBER" != *.1 || "$TRAVIS_PULL_REQUEST" != "false" ]] || ./tests/travis/autoupdate_travis_yml.sh'
# - export GENERATE_TRAVIS_YML_COMMAND="php ./tests/travis/generator/main.php generate:travis-yml --core --verbose"
# - '[[ "$TRAVIS_JOB_NUMBER" != *.1 || "$TRAVIS_PULL_REQUEST" != "false" ]] || ./tests/travis/autoupdate_travis_yml.sh'
- '[ ! -f ./tests/travis/install_mysql_5.6.sh ] || ./tests/travis/install_mysql_5.6.sh'
......@@ -110,7 +120,7 @@ install:
before_script:
- phpenv config-rm xdebug.ini;
- if [[ "$TRAVIS_PHP_VERSION" != 7* ]]; then phpenv config-rm xdebug.ini; fi
# add always_populate_raw_post_data=-1 to php.ini
- echo "always_populate_raw_post_data=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
......
......@@ -58,7 +58,7 @@
},
"require-dev": {
"aws/aws-sdk-php": "2.7.1",
"phpunit/phpunit": "~4.1",
"phpunit/phpunit": "~4.8",
"facebook/xhprof": "dev-master",
"phpseclib/phpseclib": "~0.3.8",
"symfony/var-dumper": "~2.6.0",
......
Ce diff est replié.
......@@ -16,13 +16,21 @@ namespace Piwik\Composer;
*/
class ScriptHandler
{
private static function isPhp7orLater()
{
return version_compare('7.0.0-dev', PHP_VERSION) < 1;
}
public static function cleanXhprof()
{
if (! is_dir('vendor/facebook/xhprof/extension')) {
return;
}
passthru('misc/composer/clean-xhprof.sh');
if (!self::isPhp7orLater()) {
// doesn't work with PHP 7 at the moment
passthru('misc/composer/clean-xhprof.sh');
}
}
public static function buildXhprof()
......@@ -31,6 +39,9 @@ class ScriptHandler
return;
}
passthru('misc/composer/build-xhprof.sh');
if (!self::isPhp7orLater()) {
passthru('misc/composer/clean-xhprof.sh');
}
}
}
......@@ -39,7 +39,13 @@ class Adapter
$className = self::getAdapterClassName($adapterName);
$adapter = new $className($dbInfos);
// make sure not to pass any references otherwise they will modify $dbInfos
$infos = array();
foreach ($dbInfos as $key => $val) {
$infos[$key] = $val;
}
$adapter = new $className($infos);
if ($connect) {
$adapter->getConnection();
......
......@@ -24,7 +24,10 @@ class ExceptionHandler
set_exception_handler(array('Piwik\ExceptionHandler', 'handleException'));
}
public static function handleException(Exception $exception)
/**
* @param Exception $exception
*/
public static function handleException($exception)
{
if (Common::isPhpCliMode()) {
self::dieWithCliError($exception);
......@@ -33,7 +36,10 @@ class ExceptionHandler
self::dieWithHtmlErrorPage($exception);
}
public static function dieWithCliError(Exception $exception)
/**
* @param Exception $exception
*/
public static function dieWithCliError($exception)
{
$message = $exception->getMessage();
......@@ -54,7 +60,10 @@ class ExceptionHandler
exit(1);
}
public static function dieWithHtmlErrorPage(Exception $exception)
/**
* @param Exception $exception
*/
public static function dieWithHtmlErrorPage($exception)
{
Common::sendHeader('Content-Type: text/html; charset=utf-8');
......@@ -63,7 +72,10 @@ class ExceptionHandler
exit(1);
}
private static function getErrorResponse(Exception $ex)
/**
* @param Exception $ex
*/
private static function getErrorResponse($ex)
{
$debugTrace = $ex->getTraceAsString();
......
......@@ -309,7 +309,7 @@ abstract class VisitDimension extends Dimension
}
}
usort($instances, array('self', 'sortByRequiredFields'));
$instances = self::sortDimensions($instances);
$cache->save($cacheId, $instances);
}
......@@ -319,20 +319,53 @@ abstract class VisitDimension extends Dimension
/**
* @ignore
* @param VisitDimension[] $dimensions
*/
public static function sortByRequiredFields($a, $b)
public static function sortDimensions($dimensions)
{
$fields = $a->getRequiredVisitFields();
$sorted = array();
$exists = array();
// we first handle all the once without dependency
foreach ($dimensions as $index => $dimension) {
$fields = $dimension->getRequiredVisitFields();
if (empty($fields)) {
$sorted[] = $dimension;
$exists[] = $dimension->getColumnName();
unset($dimensions[$index]);
}
}
if (empty($fields)) {
return -1;
// find circular references
// and remove dependencies whose column cannot be resolved because it is not installed / does not exist / is defined by core
$depenencies = array();
foreach ($dimensions as $dimension) {
$depenencies[$dimension->getColumnName()] = $dimension->getRequiredVisitFields();
}
if (in_array($b->columnName, $fields)) {
return 1;
foreach ($depenencies as $column => $fields) {
foreach ($fields as $key => $field) {
if (empty($depenencies[$field]) && !in_array($field, $exists)) {
// we cannot resolve that dependency as it does not exist
unset($depenencies[$column][$key]);
} elseif (!empty($depenencies[$field]) && in_array($column, $depenencies[$field])) {
throw new Exception("Circular reference detected for required field $field in dimension $column");
}
}
}
while (count($dimensions) > 0) {
foreach ($dimensions as $key => $dimension) {
$fields = $depenencies[$dimension->getColumnName()];
if (count(array_intersect($fields, $exists)) === count($fields)) {
$sorted[] = $dimension;
$exists[] = $dimension->getColumnName();
unset($dimensions[$key]);
}
}
}
return 0;
return $sorted;
}
/**
......
......@@ -65,8 +65,9 @@ class PhpSettingsCheck implements Diagnostic
'session.auto_start=0',
);
if ($this->isPhpVersionAtLeast56() && ! defined("HHVM_VERSION")) {
if ($this->isPhpVersionAtLeast56() && ! defined("HHVM_VERSION") && !$this->isPhpVersionAtLeast70()) {
// always_populate_raw_post_data must be -1
// removed in PHP 7
$requiredSettings[] = 'always_populate_raw_post_data=-1';
}
......@@ -77,4 +78,9 @@ class PhpSettingsCheck implements Diagnostic
{
return version_compare(PHP_VERSION, '5.6', '>=');
}
private function isPhpVersionAtLeast70()
{
return version_compare(PHP_VERSION, '7.0.0-dev', '>=');
}
}
......@@ -11,6 +11,7 @@ namespace Piwik\Plugins\Insights\tests;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Plugins\Insights\DataTable\Filter\OrderBy;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
/**
* @group Insights
......@@ -43,7 +44,11 @@ class FilterOrderByTest extends BaseUnitTest
$this->applyOrderByFilter();
$this->assertOrder(array('pos1', 'pos5', 'pos3', 'pos4', 'pos2', 'pos6', 'neg3', 'neg2', 'neg1', 'neg5', 'neg4'));
if (SystemTestCase::isPhp7orLater()) {
$this->assertOrder(array('pos1', 'pos3', 'pos5', 'pos4', 'pos2', 'pos6', 'neg3', 'neg2', 'neg1', 'neg5', 'neg4'));
} else {
$this->assertOrder(array('pos1', 'pos5', 'pos3', 'pos4', 'pos2', 'pos6', 'neg3', 'neg2', 'neg1', 'neg5', 'neg4'));
}
}
public function testOrderByShouldSortDependingOnNbVisitsIfColumnsHaveSameValue()
......
......@@ -104,6 +104,11 @@ abstract class SystemTestCase extends PHPUnit_Framework_TestCase
return strpos(PHP_VERSION, '5.3') === 0;
}
public static function isPhp7orLater()
{
return version_compare('7.0.0-dev', PHP_VERSION) < 1;
}
public static function isMysqli()
{
return getenv('MYSQL_ADAPTER') == 'MYSQLI';
......
......@@ -29,8 +29,14 @@ class PiwikTest extends IntegrationTestCase
(float)-1, (float)0, (float)1, (float)1.5, (float)-1.5, (float)21111, (float)89898, (float)99999999999, (float)-4565656,
(int)-1, (int)0, (int)1, (int)1.5, (int)-1.5, (int)21111, (int)89898, (int)99999999999, (int)-4565656,
'-1', '0', '1', '1.5', '-1.5', '21111', '89898', '99999999999', '-4565656',
'1e3', '0x123', "-1e-2",
'1e3', 0x123, "-1e-2",
);
if (!self::isPhp7orLater()) {
// this seems to be no longer considered valid in PHP 7+
$value[] = '0x123';
}
foreach ($valid as $key => $value) {
$valid[$key] = array($value);
}
......
......@@ -201,7 +201,7 @@ class VisitDimensionTest extends IntegrationTestCase
$this->assertEquals(Segment::TYPE_METRIC, $segments[1]->getType());
}
public function test_sortByRequiredFields_ShouldResolveDependencies()
public function test_sortDimensions_ShouldResolveDependencies()
{
$dimension1 = new FakeVisitDimension();
$dimension1->set('columnName', 'column1');
......@@ -221,7 +221,36 @@ class VisitDimensionTest extends IntegrationTestCase
$instances = array($dimension1, $dimension2, $dimension3, $dimension4);
usort($instances, array('\Piwik\Plugin\Dimension\VisitDimension', 'sortByRequiredFields'));
$instances = VisitDimension::sortDimensions($instances);
$this->assertSame(array($dimension3, $dimension4, $dimension2, $dimension1), $instances);
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Circular reference detected for required field column4 in dimension column2
*/
public function test_sortDimensions_ShouldThrowAnException_IfCircularReferenceDetected()
{
$dimension1 = new FakeVisitDimension();
$dimension1->set('columnName', 'column1');
$dimension1->requiredFields = array('column3');
$dimension2 = new FakeVisitDimension();
$dimension2->set('columnName', 'column2');
$dimension2->requiredFields = array('column3', 'column4');
$dimension3 = new FakeVisitDimension();
$dimension3->set('columnName', 'column3');
$dimension3->requiredFields = array();
$dimension4 = new FakeVisitDimension();
$dimension4->set('columnName', 'column4');
$dimension4->requiredFields = array('column2');
$instances = array($dimension1, $dimension2, $dimension3, $dimension4);
$instances = VisitDimension::sortDimensions($instances);
$this->assertSame(array($dimension3, $dimension4, $dimension2, $dimension1), $instances);
}
......
......@@ -10,6 +10,7 @@ namespace Piwik\Tests\Unit;
use Piwik\Filesystem;
use Piwik\Tests\Framework\Mock\File;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
/**
* @group Core
......@@ -42,6 +43,11 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
{
$input = array('xyz/1.gif', 'x/xyz.gif', 'xxyyzzgg');
$result = Filesystem::sortFilesDescByPathLength($input);
if (SystemTestCase::isPhp7orLater()) {
$input = array('x/xyz.gif', 'xyz/1.gif', 'xxyyzzgg');
}
$this->assertEquals($input, $result);
}
......
......@@ -22,6 +22,8 @@ class DayTest extends BasePeriodTest
new Day('Invalid Date');
} catch (\Exception $e) {
return;
} catch (\Throwable $e) {
return;
}
$this->fail('Expected Exception not raised');
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter