PHP Code:
$array = array( 'id' => '1', 'firstname' => 'les', 'lastname' => 'quinn' );
$serialised = serialize( $array );
file_put_contents( 'array.php', $serialised );
define( 'SIMPLE_TEST', '../tools/simpletest/' );
require_once( SIMPLE_TEST.'reporter.php' );
require_once( SIMPLE_TEST.'unit_tester.php' );
class ASimpleTestOfSimpleTest extends UnitTestCase {
public function __construct() {
parent::__construct( 'Test: A Simple Test Of Simple Test' );
}
public function testDummyArray() {
$array = array( 'id' => '1', 'firstname' => 'les', 'lastname' => 'quinn' );
$this -> assertTrue( in_array( 1, $array ) );
}
public function testSerialisedArrayFetch() {
$array = unserialize( file_get_contents( 'array.php' ) );
$this -> assertTrue( in_array( 'les', $array ) );
}
public function testGetArrayFromRequireFile() {
require_once( 'non-serialised-array.php' );
$this -> assertTrue( in_array( 'les', $array ) );
}
public function testRequiredArrayFetch() {
// this fails with an error
require_once( 'non-serialised-array.php' );
$this -> assertTrue( in_array( 'les', $array ) );
}
public function testRequiredArrayFetchLoop() {
require_once( 'non-serialised-array.php' );
foreach( $array as $key => $value ) {
// this test throws exactly the same error that i
// got with my other scripts
}
}
}
$test = new ASimpleTestOfSimpleTest();
$test -> run( new HtmlReporter() );
PHP Code:
// required file
$array = array( 'id' => '1', 'firstname' => 'les', 'lastname' => 'quinn' );
Report:
Code:
1/1 test cases complete: 3 passes, 1 fails and 2 exceptions.
Make what of it, if you will but there is definitely a bug there somewhere. I've wasted the last day trying to work with this, and it's cost me money, lack of sleep and now I've got a -BEEP- of a headache.
Marcus, if at some point you get around to reading through this thread, I'd very much like to see some input from you.
Bookmarks