Added first few unit tests
This commit is contained in:
parent
22aa588cde
commit
454a59123c
@ -77,8 +77,7 @@ class JSObject extends Object{
|
||||
$method = ( ! empty($args)) ? $args[0] : "print_r";
|
||||
$data = (isset($args[1])) ? $args[1] : array();
|
||||
|
||||
// 32762 == (E_ALL|E_NOTICE|E_STRICT) & ~(E_ERROR | E_PARSE)
|
||||
if(ini_get('error_reporting') == 32762 && empty($data))
|
||||
if(empty($data))
|
||||
{
|
||||
$data =& $this;
|
||||
}
|
||||
|
@ -1,9 +1,96 @@
|
||||
<?php
|
||||
|
||||
class miniMVCTest extends PHPUnit_Framework_TestCase {
|
||||
require_once('simpletest/autorun.php');
|
||||
require_once('../src/sys/common.php');
|
||||
|
||||
class commonTest extends UnitTestCase {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct('Common.php Tests');
|
||||
}
|
||||
|
||||
function setUp()
|
||||
{
|
||||
$this->empty = array();
|
||||
$this->object = new JSObject();
|
||||
$this->array_like = new JSObject(array('foo' => 'bar'));
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function testCreation()
|
||||
{
|
||||
// Empty is not array like
|
||||
$this->assertFalse(is_like_array($this->empty));
|
||||
|
||||
// Empty object is array like - because objects are truthy
|
||||
$this->assertTrue(is_like_array($this->object));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class JSObjectTest extends PHPUnit_Framework_TestCase {
|
||||
class miniMVCTest extends UnitTestCase {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct('miniMVC Class Tests');
|
||||
}
|
||||
|
||||
function setUp()
|
||||
{
|
||||
$this->mm = new miniMVC();
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
unset($this->mm);
|
||||
}
|
||||
|
||||
function testCreation()
|
||||
{
|
||||
// miniMVC::get_instance returns reference to latest miniMVC object
|
||||
$this->assertReference($this->mm, miniMVC::get_instance());
|
||||
|
||||
// Expect an error trying to clone the miniMVC object
|
||||
$this->expectError("Clone is not allowed.");
|
||||
$mm2 = clone $this->mm;
|
||||
|
||||
// miniMVC extends JSObject, right?
|
||||
$this->assertIsA($this->mm, 'JSObject');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class JSObjectTest extends UnitTestCase {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct('JSObject Class Tests');
|
||||
}
|
||||
|
||||
function setUp()
|
||||
{
|
||||
$this->JSO = new JSObject(array(
|
||||
'foo' => 54,
|
||||
'bar' => 'baz',
|
||||
));
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
unset($this->JSO);
|
||||
}
|
||||
|
||||
function testCreation()
|
||||
{
|
||||
|
||||
// __toString produces same output as print_r by default
|
||||
$this->assertIdentical($this->JSO->__toString(), '<pre>'.print_r($this->JSO, TRUE).'</pre>');
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user