Added multiple tests and started real continuous integration

This commit is contained in:
Abel Hoogeveen 2015-05-01 22:47:11 +02:00
parent 58f0910f63
commit c86822f99b
17 changed files with 220 additions and 35 deletions

3
.gitignore vendored
View File

@ -11,4 +11,5 @@ FuzeWorks.esproj/*
*.swp
*.out
Core/Cache/
Core/Logs/Error.log
Core/Logs/Error.log
build/

View File

@ -7,8 +7,9 @@ class ModelLoadEvent extends Event {
public $directory;
public $model;
public function init($model){
public function init($model, $directory){
$this->model = $model;
$this->directory = $directory;
}
}

View File

@ -23,7 +23,7 @@ class Models extends Bus{
public function loadModel($name, $directory = null){
// Model load event
$event = $this->events->fireEvent('modelLoadEvent', $name);
$event = $this->events->fireEvent('modelLoadEvent', $name, $directory);
$directory = ($event->directory === null ? "Application/Models" : $event->directory);
$name = ($event->model === null ? $name : $event->model);

View File

@ -0,0 +1,22 @@
<?php
namespace Module\Example;
use \FuzeWorks\Module;
/**
* Sections module, see usage documentation
* @author TechFuze
*/
class Main extends Module {
/**
* Loads the module and registers the events
* @access public
*/
public function onLoad() {
}
}
?>

View File

@ -0,0 +1,23 @@
<?php
return array(
'module_class' => 'Module\Example\Main',
'module_file' => 'class.main.php',
'module_name' => 'Example',
'abstract' => false,
'dependencies' => array(),
'events' => array(),
'sections' => array(),
'name' => 'FuzeWorks Example Module',
'description' => 'A descriptive module that functions as an example',
'author' => 'MyCorp',
'version' => '1.0.0',
'website' => 'http://fuzeworks.techfuze.net/',
'date_created' => '29-04-2015',
'date_updated' => '29-04-2015',
'enabled' => true,
);

View File

@ -1,7 +1,6 @@
<project name="FuzeWorks" default="build" basedir=".">
<target name="clean">
<delete dir="${basedir}/build" />
<delete dir="${basedir}/source/.git" />
</target>
<target name="prepare">
@ -10,22 +9,28 @@
<mkdir dir="${basedir}/build/phpdoc" />
</target>
<target name="phpdoc">
<target name="phpunit">
<exec dir="${basedir}" executable="php" failonerror="true">
<arg value="phpunit.phar"/>
<arg line="--configuration phpunit.xml
--log-junit build/logs/phpunit.xml
--coverage-clover build/logs/clover.xml
--coverage-html build/clover" />
</exec>
</target>
<target name="phpdoc">
<exec dir="${basedir}" executable="php" failonerror="yes">
<arg value="apigen.phar"/>
<arg line="generate --source .
--exclude 'tests/*'
--exclude 'Core/System/Smarty/*'
--title 'FuzeWorks Documentation build #${buildNumber}'
--destination build/phpdoc" />
<arg line="generate --source . --destination 'build/phpdoc' --exclude 'tests/*','build/*','Core/System/Smarty/*' "/>
</exec>
</target>
<target name="zip">
<exec dir="${basedir}" executable="zip" failonerror="true">
<arg line="-r ${basedir}/build/fuzeworks-core.zip . -x build\* tests\* .git\*" />
<arg line="-r ${basedir}/build/fuzeworks-core.zip . -x build\* tests\* .git\* phpunit.phar apigen.phar phpunit.xml build.xml" />
</exec>
</target>
<target name="build" depends="clean,prepare,phpdoc,zip" />
<target name="build" depends="clean,prepare,phpunit,phpdoc,zip" />
</project>

View File

@ -1,9 +1,13 @@
<?php
// Include framework
require_once( dirname(__FILE__) . "/Core/System/class.core.php");
require('load.php');
// Load it
$core = new \FuzeWorks\Core();
$core->init();
$core->loadMod('router');
$core->mods->router->setPath( (isset($_GET['path']) ? $_GET['path'] : null) );
$core->mods->router->route();
$core->mods->router->loadController();
?>

View File

@ -1,13 +0,0 @@
<?php
// Include framework
if (!defined('FUZEPATH')) {
define( 'FUZEPATH', dirname(__FILE__) . '/' );
}
require_once( dirname(__FILE__) . "/Core/System/class.core.php");
// Load it
$core = new Core();
$core->init();
?>

View File

@ -1,5 +1,5 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
bootstrap="load.php"
bootstrap="tests/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"

7
tests/autoload.php Normal file
View File

@ -0,0 +1,7 @@
<?php
// Load the abstract
require_once("class.abstract.coreTestAbstract.php");
require_once( "Core/System/class.core.php");
?>

View File

@ -0,0 +1,23 @@
<?php
/**
* Class CoreTestAbstract
*
* Provides the event tests with some basic functionality
*/
abstract class CoreTestAbstract extends PHPUnit_Framework_TestCase
{
/**
* This function provides the framework
* @returns \FuzeWorks\Core
*/
static function createCore()
{
$core = new FuzeWorks\Core();
$core->init();
//Disable debugging
$core->mods->logger->disable();
return $core;
}
}

View File

@ -1,7 +0,0 @@
<?php
class CoreTest extends PHPUnit_Framework_TestCase {
public function testCanBeNegated() {
}
}

20
tests/core_coreTest.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/**
* Class CoreTest
*
* Core testing suite, will test basic core functionality
*/
class CoreTest extends CoreTestAbstract
{
public function testCanLoadStartupFiles(){
$core = $this->createCore();
// Assert
$this->assertInstanceOf('\FuzeWorks\Config', $core->mods->config);
$this->assertInstanceOf('\FuzeWorks\Logger', $core->mods->logger);
$this->assertInstanceOf('\FuzeWorks\Events', $core->mods->events);
$this->assertInstanceOf('\FuzeWorks\Layout', $core->mods->layout);
$this->assertInstanceOf('\FuzeWorks\Models', $core->mods->models);
}
}

23
tests/core_modelTest.php Normal file
View File

@ -0,0 +1,23 @@
<?php
/**
* Class ModelTest
*
* Core model testing suite, will test model parent class
*
*/
class ModelTest extends CoreTestAbstract
{
/**
* Tests wether FuzeWorks is able to load a simple Dummy Model
*/
public function testModelLoading() {
$core = $this->createCore();
$core->mods->models->loadModel('dummy', 'tests/models/testModelLoading/');
$this->assertInstanceOf('\Model\Dummy', $core->mods->models->dummy);
}
// PARENT INTERACTION VIA A DUMMY MODELSERVER IN DUMMY MODULE
}

50
tests/core_moduleTest.php Normal file
View File

@ -0,0 +1,50 @@
<?php
/**
* Class ModuleTest
*
* Core module testing suite, will test basic module functionality
*
*/
class ModuleTest extends CoreTestAbstract
{
/**
* Tests the loading of a single module located in a folder
*/
public function testFolderLoading(){
$core = $this->createCore();
$mod = $core->loadMod('mycorp/example');
$this->assertInstanceOf('\Module\Example\Main', $mod);
}
/**
* Test if a reloaded module is the same Id
*/
public function testDuplicateInstance() {
$core = $this->createCore();
// The 2 instances which should be the same
$mod = $core->loadMod('mycorp/example');
$mod2 = $core->loadMod('mycorp/example');
$this->assertEquals(spl_object_hash($mod), spl_object_hash($mod2));
}
/**
* Test if the retrieved module info is correct
*/
public function testModuleInfo() {
$core = $this->createCore();
$mod = $core->loadMod('mycorp/example');
// The name
$this->assertEquals('mycorp/example', $mod->getModuleName());
// The directory
$this->assertEquals('Modules/example/', $mod->getModulePath());
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Model;
use \FuzeWorks\Model;
class Dummy extends Model{
public function __construct(&$core){
parent::__construct($core);
}
}
?>

View File

@ -0,0 +1,13 @@
<?php
namespace Model;
use \FuzeWorks\Model;
class Dummy extends Model{
public function __construct(&$core){
parent::__construct($core);
}
}
?>