Skip to content

Commit

Permalink
Set up unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker authored and realityking committed Aug 20, 2012
1 parent d27d94d commit 45b442a
Show file tree
Hide file tree
Showing 25 changed files with 3,218 additions and 2 deletions.
10 changes: 8 additions & 2 deletions build.xml
Expand Up @@ -4,11 +4,17 @@
<property name="source" value="." />

<target name="clean" description="Clean up and create artifact directories">
<delete dir="${basedir}/build/coverage" />
<delete dir="${basedir}/build/logs" />

<mkdir dir="${basedir}/build/coverage" />
<mkdir dir="${basedir}/build/logs" />
</target>

<target name="phpunit" description="Run unit tests using PHPUnit and generates junit.xml and clover.xml">
<exec executable="phpunit" />
</target>

<target name="phpcs" description="Generate checkstyle.xml using PHP_CodeSniffer">
<exec executable="phpcs">
<arg value="--report=checkstyle" />
Expand All @@ -18,6 +24,6 @@
<arg path="${source}" />
</exec>
</target>
<target name="build" depends="clean,phpcs" />

<target name="build" depends="clean,phpunit,phpcs" />
</project>
20 changes: 20 additions & 0 deletions phpunit.xml.dist
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/unit/bootstrap.php" colors="false">
<testsuites>
<testsuite name="libraries">
<directory>tests/unit/suites/libraries</directory>
</testsuite>
</testsuites>

<logging>
<log type="coverage-html" target="build/coverage" title="Joomla-CMS" charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70" />
<log type="coverage-clover" target="build/logs/clover.xml" />
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false" />
</logging>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">libraries/cms</directory>
</whitelist>
</filter>
</phpunit>
93 changes: 93 additions & 0 deletions tests/unit/bootstrap.php
@@ -0,0 +1,93 @@
<?php
/**
* Prepares a minimalist framework for unit testing.
*
* Joomla is assumed to include the /unittest/ directory.
* eg, /path/to/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
*/

define('_JEXEC', 1);

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

// Maximise error reporting.
ini_set('zend.ze1_compatibility_mode', '0');
error_reporting(E_ALL & ~E_STRICT);
ini_set('display_errors', 1);

/*
* Ensure that required path constants are defined. These can be overridden within the phpunit.xml file
* if you chose to create a custom version of that file.
*/
if (!defined('JPATH_TESTS'))
{
define('JPATH_TESTS', realpath(__DIR__));
}
if (!defined('JPATH_PLATFORM'))
{
define('JPATH_PLATFORM', realpath(dirname(dirname(__DIR__)) . '/libraries'));
}
if (!defined('JPATH_LIBRARIES'))
{
define('JPATH_LIBRARIES', realpath(dirname(dirname(__DIR__)) . '/libraries'));
}
if (!defined('JPATH_BASE'))
{
define('JPATH_BASE', realpath(dirname(dirname(__DIR__))));
}
if (!defined('JPATH_ROOT'))
{
define('JPATH_ROOT', realpath(JPATH_BASE));
}
if (!defined('JPATH_CACHE'))
{
define('JPATH_CACHE', JPATH_BASE . '/cache');
}
if (!defined('JPATH_CONFIGURATION'))
{
define('JPATH_CONFIGURATION', JPATH_BASE);
}
if (!defined('JPATH_SITE'))
{
define('JPATH_SITE', JPATH_ROOT);
}
if (!defined('JPATH_ADMINISTRATOR'))
{
define('JPATH_ADMINISTRATOR', JPATH_ROOT . '/administrator');
}
if (!defined('JPATH_INSTALLATION'))
{
define('JPATH_INSTALLATION', JPATH_ROOT . '/installation');
}
if (!defined('JPATH_MANIFESTS'))
{
define('JPATH_MANIFESTS', JPATH_ADMINISTRATOR . '/manifests');
}
if (!defined('JPATH_PLUGINS'))
{
define('JPATH_PLUGINS', JPATH_BASE . '/plugins');
}
if (!defined('JPATH_THEMES'))
{
define('JPATH_THEMES', JPATH_BASE . '/templates');
}

// Import the platform in legacy mode.
require_once JPATH_PLATFORM . '/import.legacy.php';

// Force library to be in JError legacy mode
JError::setErrorHandling(E_NOTICE, 'message');
JError::setErrorHandling(E_WARNING, 'message');

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

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

0 comments on commit 45b442a

Please sign in to comment.