[enh] adds phpunit tests layout
This commit is contained in:
parent
fdff96fa04
commit
fbc3ba935f
|
@ -0,0 +1,37 @@
|
|||
<?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'));
|
|
@ -0,0 +1,9 @@
|
|||
<?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('.');
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
* This is the abstract class for all tests
|
||||
* @see http://phpunit.de/manual/
|
||||
*/
|
||||
abstract class AlterncTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<phpunit
|
||||
bootstrap="bootstrap.php"
|
||||
>
|
||||
</phpunit>
|
|
@ -0,0 +1,107 @@
|
|||
<?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));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue