Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
Cleaning up bootstrap/import files and adding gc_disable() to PHPUnit
Browse files Browse the repository at this point in the history
boostrap files to reduce the likelyhood of a PHP induced segfault during
long running test suites.
  • Loading branch information
LouisLandry committed Oct 17, 2012
1 parent ea743f6 commit eda07a6
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 49 deletions.
37 changes: 26 additions & 11 deletions build/bootstrap.stub.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
<?php
/**
* Prepares a minimalist framework for unit testing.
* Unit test runner bootstrap file for the Joomla Platform. This file becomes the PHAR stub
* when the platform and unit test classes are built into a single deployable archive to be
* used in testing Joomla applications.
*
* Joomla is assumed to include the /unittest/ directory.
* eg, /path/to/joomla/unittest/
* @package Joomla.UnitTest
*
* @package Joomla.UnitTest
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://www.phpunit.de/manual/current/en/installation.html
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://www.phpunit.de/manual/current/en/installation.html
*/

// Setup the Pharsanity!
Phar::interceptFileFuncs();

// Set the Joomla execution flag.
define('_JEXEC', 1);

// Fix magic quotes.
@ini_set('magic_quotes_runtime', 0);

Expand Down Expand Up @@ -72,5 +68,24 @@
// Register the core Joomla test classes.
JLoader::registerPrefix('Test', 'phar://' . __FILE__ . '/core');

/*
* The following classes still depend on `JVersion` so we must load it until they are dealt with.
*
* JInstallerHelper
* JUpdaterCollection
* JUpdaterExtension
* JUpdate
* JFactory
*/
require_once 'phar://' . __FILE__ . '/version.php';

/*
* The PHP garbage collector can be too aggressive in closing circular references before they are no longer needed. This can cause
* segfaults during long, memory-intensive processes such as testing large test suites and collecting coverage data. We explicitly
* disable garbage collection during the execution of PHPUnit processes so that we (hopefully) don't run into these issues going
* forwards. This is only a problem PHP 5.3+.
*/
gc_disable();

// End of the Phar Stub.
__HALT_COMPILER();?>
11 changes: 5 additions & 6 deletions build/changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
*
* php -f run.php
*
* @package Joomla.Examples
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* @package Joomla.Examples
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

// We are a valid Joomla entry point.
define('_JEXEC', 1);

// Setup the path related constants.
define('JPATH_BASE', dirname(__FILE__));

Expand Down Expand Up @@ -311,6 +308,8 @@ protected function getIssues($page)
/**
* Get information about a specific pull request.
*
* @param integer $id The GitHub pull request number.
*
* @return object
*
* @since 12.1
Expand Down
9 changes: 4 additions & 5 deletions build/import.stub.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
/**
* Bootstrap file for the Joomla Platform. This file becomes the PHAR stub when the platform is built
* into a single deployable archive to be used in Joomla applications.
*
* @package Joomla.Platform
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
Expand All @@ -21,13 +24,9 @@
{
define('IS_WIN', ($os === 'WIN') ? true : false);
}
if (!defined('IS_MAC'))
{
define('IS_MAC', ($os === 'MAC') ? true : false);
}
if (!defined('IS_UNIX'))
{
define('IS_UNIX', (($os !== 'MAC') && ($os !== 'WIN')) ? true : false);
define('IS_UNIX', (IS_WIN === false) ? true : false);
}

// Import the platform version library if necessary.
Expand Down
21 changes: 14 additions & 7 deletions libraries/import.legacy.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
/**
* Bootstrap file for the Joomla Platform [with legacy libraries]. Including this file into your application
* will make Joomla Platform libraries [including legacy libraries] available for use.
*
* @package Joomla.Platform
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
Expand Down Expand Up @@ -43,7 +46,11 @@
require_once JPATH_PLATFORM . '/loader.php';
}

class_exists('JLoader') or die;
// Make sure that the Joomla Platform has been successfully loaded.
if (!class_exists('JLoader'))
{
throw new RuntimeException('Joomla Platform not loaded.');
}

// Setup the autoloaders.
JLoader::setup();
Expand All @@ -54,15 +61,15 @@ class_exists('JLoader') or die;
// Import the Joomla Factory.
JLoader::import('joomla.factory');

// Register classes for compatability with PHP 5.3
if (version_compare(PHP_VERSION, '5.4.0', '<'))
{
JLoader::register('JsonSerializable', __DIR__ . '/compat/jsonserializable.php');
}

// Register classes that don't follow one file per class naming conventions.
JLoader::register('JText', JPATH_PLATFORM . '/joomla/language/text.php');
JLoader::register('JRoute', JPATH_PLATFORM . '/joomla/application/route.php');

// Register the folder for the moved JHtml classes
JHtml::addIncludePath(JPATH_PLATFORM . '/legacy/html');

// Register classes for compatability with PHP 5.3
if (version_compare(PHP_VERSION, '5.4.0', '<'))
{
JLoader::register('JsonSerializable', __DIR__ . '/compat/jsonserializable.php');
}
9 changes: 8 additions & 1 deletion libraries/import.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
/**
* Bootstrap file for the Joomla Platform. Including this file into your application will make Joomla
* Platform libraries available for use.
*
* @package Joomla.Platform
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
Expand Down Expand Up @@ -35,7 +38,11 @@
require_once JPATH_PLATFORM . '/loader.php';
}

class_exists('JLoader') or die;
// Make sure that the Joomla Platform has been successfully loaded.
if (!class_exists('JLoader'))
{
throw new RuntimeException('Joomla Platform not loaded.');
}

// Setup the autoloaders.
JLoader::setup();
Expand Down
1 change: 1 addition & 0 deletions packager.test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<file localPath="lib">libraries/import.php</file>
<file localPath="lib">libraries/loader.php</file>
<file localPath="lib">libraries/platform.php</file>
<file localPath="">tests/version.php</file>
<folder recursive="true" localPath="lib/compat">libraries/compat</folder>
<folder recursive="true" localPath="lib/joomla">libraries/joomla</folder>
<folder recursive="true" localPath="lib/phpmailer">libraries/phpmailer</folder>
Expand Down
27 changes: 21 additions & 6 deletions tests/bootstrap.legacy.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php
/**
* Prepares a minimalist framework for unit testing.
*
* Joomla is assumed to include the /unittest/ directory.
* eg, /path/to/joomla/unittest/
* Unit test runner bootstrap file for the Joomla Platform [with legacy libraries].
*
* @package Joomla.UnitTest
*
Expand All @@ -12,8 +9,6 @@
* @link http://www.phpunit.de/manual/current/en/installation.html
*/

define('_JEXEC', 1);

// Fix magic quotes.
@ini_set('magic_quotes_runtime', 0);

Expand Down Expand Up @@ -65,5 +60,25 @@
// Import the platform.
require_once JPATH_PLATFORM . '/import.legacy.php';


// Register the core Joomla test classes.
JLoader::registerPrefix('Test', __DIR__ . '/core');

/*
* The following classes still depend on `JVersion` so we must load it until they are dealt with.
*
* JInstallerHelper
* JUpdaterCollection
* JUpdaterExtension
* JUpdate
* JFactory
*/
require_once __DIR__ . '/version.php';

/*
* The PHP garbage collector can be too aggressive in closing circular references before they are no longer needed. This can cause
* segfaults during long, memory-intensive processes such as testing large test suites and collecting coverage data. We explicitly
* disable garbage collection during the execution of PHPUnit processes so that we (hopefully) don't run into these issues going
* forwards. This is only a problem PHP 5.3+.
*/
gc_disable();
28 changes: 19 additions & 9 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php
/**
* Prepares a minimalist framework for unit testing.
*
* Joomla is assumed to include the /unittest/ directory.
* eg, /path/to/joomla/unittest/
* Unit test runner bootstrap file for the Joomla Platform.
*
* @package Joomla.UnitTest
*
Expand All @@ -12,8 +9,6 @@
* @link http://www.phpunit.de/manual/current/en/installation.html
*/

define('_JEXEC', 1);

// Fix magic quotes.
@ini_set('magic_quotes_runtime', 0);

Expand Down Expand Up @@ -68,9 +63,24 @@
// Register the core Joomla test classes.
JLoader::registerPrefix('Test', __DIR__ . '/core');

// Some classes still dependen on JVersion
// until that's fixed we need to load it
/*
* The following classes still depend on `JVersion` so we must load it until they are dealt with.
*
* JInstallerHelper
* JUpdaterCollection
* JUpdaterExtension
* JUpdate
* JFactory
*/
require_once __DIR__ . '/version.php';

// We need this to test JSession
/*
* The PHP garbage collector can be too aggressive in closing circular references before they are no longer needed. This can cause
* segfaults during long, memory-intensive processes such as testing large test suites and collecting coverage data. We explicitly
* disable garbage collection during the execution of PHPUnit processes so that we (hopefully) don't run into these issues going
* forwards. This is only a problem PHP 5.3+.
*/
gc_disable();

// We need this to test JSession for now. We should really fix this.
ob_start();
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

/**
* en-GB localise class
*
Expand Down
2 changes: 0 additions & 2 deletions tests/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* @license GNU General Public License version 2 or later; see LICENSE
*/

defined('_JEXEC') or die;

/**
* Version information class for the Joomla CMS.
*
Expand Down

0 comments on commit eda07a6

Please sign in to comment.