Commit fbc3ba93 authored by alban's avatar alban
Browse files

[enh] adds phpunit tests layout

parent fdff96fa
<?php
class AutoLoader {
static private $classNames = array();
/**
* Store the filename (sans extension) & full path of all ".php" files found
*/
public static function registerDirectory($dirName) {
$di = new DirectoryIterator($dirName);
foreach ($di as $file) {
if ($file->isDir() && !$file->isLink() && !$file->isDot()) {
// recurse into directories other than a few special ones
self::registerDirectory($file->getPathname());
} elseif (substr($file->getFilename(), -4) === '.php') {
// save the class name / path of a .php file found
$className = substr($file->getFilename(), 0, -4);
AutoLoader::registerClass($className, $file->getPathname());
}
}
}
public static function registerClass($className, $fileName) {
AutoLoader::$classNames[$className] = $fileName;
}
public static function loadClass($className) {
if (isset(AutoLoader::$classNames[$className])) {
require_once(AutoLoader::$classNames[$className]);
}
}
}
spl_autoload_register(array('AutoLoader', 'loadClass'));
<?php
$pathList = array_merge( array("."),explode(PATH_SEPARATOR,get_include_path()));
set_include_path(implode(PATH_SEPARATOR, $pathList));
require_once('AutoLoader.php');
// Register the directory to your include files
AutoLoader::registerDirectory('lib');
AutoLoader::registerDirectory('../bureau/class');
AutoLoader::registerDirectory('.');
<?php
/**
* This is the abstract class for all tests
* @see http://phpunit.de/manual/
*/
abstract class AlterncTest extends PHPUnit_Framework_TestCase
{
}
\ No newline at end of file
<phpunit
bootstrap="bootstrap.php"
>
</phpunit>
<?php
/**
* This is a fake test for the purpose of showing how tests work and eventually
* validate the test environment works
*
* The following methods are available :
* assertArrayHasKey()
* assertClassHasAttribute()
* assertClassHasStaticAttribute()
* assertContains()
* assertContainsOnly()
* assertContainsOnlyInstancesOf()
* assertCount()
* assertEmpty()
* assertEqualXMLStructure()
* assertEquals()
* assertFalse()
* assertFileEquals()
* assertFileExists()
* assertGreaterThan()
* assertGreaterThanOrEqual()
* assertInstanceOf()
* assertInternalType()
* assertJsonFileEqualsJsonFile()
* assertJsonStringEqualsJsonFile()
* assertJsonStringEqualsJsonString()
* assertLessThan()
* assertLessThanOrEqual()
* assertNull()
* assertObjectHasAttribute()
* assertRegExp()
* assertStringMatchesFormat()
* assertStringMatchesFormatFile()
* assertSame()
* assertSelectCount()
* assertSelectEquals()
* assertSelectRegExp()
* assertStringEndsWith()
* assertStringEqualsFile()
* assertStringStartsWith()
* assertTag()
* assertThat()
* assertTrue()
* assertXmlFileEqualsXmlFile()
* assertXmlStringEqualsXmlFile()
* assertXmlStringEqualsXmlString()
*/
class DummyTest extends AlterncTest
{
/**
* The setup is automatically run before each test
*/
protected function setUp()
{
}
/**
* The tearDown is automatically run after each test
*/
protected function tearDown()
{
}
/**
* This function will NOT be executed as its name doesn't start with test*
*/
protected function notTested()
{
}
/**
* This function will be executed by methods
* @return boolean
*/
public function testDependance()
{
$this->assertTrue(FALSE);
return TRUE;
}
/**
* @depends testDependance
* @param bool $dependancyStatus Received from dependance return
*/
public function testHasDependancy( $dependancyStatus)
{
$this->assertTrue($dependancyStatus);
}
public function testPushAndPop()
{
$stack = array();
$this->assertEquals(0, count($stack));
array_push($stack, 'foo');
$this->assertEquals('foo', $stack[count($stack)-1]);
$this->assertEquals(1, count($stack));
$this->assertEquals('foo', array_pop($stack));
$this->assertEquals(0, count($stack));
}
}
<?php
class LogTest extends AlterncTest
{
/**
*
* @var m_log
*/
private $logger;
protected function setUp()
{
$this->logger = new m_log();
}
protected function tearDown()
{
}
public function testPushAndPop()
{
$stack = array();
$this->assertEquals(0, count($stack));
array_push($stack, 'foo');
$this->assertEquals('foo', $stack[count($stack)-1]);
$this->assertEquals(1, count($stack));
$this->assertEquals('foo', array_pop($stack));
$this->assertEquals(0, count($stack));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment