<?php
# $HeadURL: https://svn.sigpipe.cz/r/trunk/testilence/tests/case.php $
# $Id: case.php 392 2007-02-11 19:24:38Z roman $
require_once dirname(__FILE__) . '/utils/case.php';
require_once dirname(__FILE__) . '/utils/reporter.php';
require_once dirname(__FILE__) . '/case/assert.php';
require_once dirname(__FILE__) . '/tempfile.php';
require_once dirname(__FILE__) . '/tempdir.php';
class tencetest_TestCaseInvokeTest extends tencetest_TestCase # {{{
{
private function doInvoke(Tence_TestCase $tc, $excName = null)
{
$rm = $this->ReflectionMethod($tc, 'test');
$this->willThrow($excName);
return $tc->invoke($rm);
}
function testRethrowsUnexpectedException() # {{{
{
$this->doInvoke(
new tencetest_util_UnexpectedExceptionTest,
'tencetest_util_UnexpectedException'
);
} # }}}
function testFailsOnWrongException() # {{{
{
$rv = $this->doInvoke(new tencetest_util_WrongExceptionTest);
return $this->assertFalse($rv->success());
} # }}}
function testFailsOnMissingException() # {{{
{
$rv = $this->doInvoke(new tencetest_util_MissingExceptionTest);
return $this->assertFalse($rv->success());
} # }}}
function testSwallowsExpectedException() # {{{
{
$rv = $this->doInvoke(new tencetest_util_ExpectedExceptionTest);
return $this->assertTrue($rv->success());
} # }}}
function testMissingAssertion() # {{{
{
$this->doInvoke(
new tencetest_util_VoidTest,
'Tence_MissingAssertion'
);
} # }}}
} # }}}
class tencetest_TestCaseRunTest extends tencetest_util_TestResultMatcher # {{{
{
protected $tc;
function setUp() # {{{
{
$this->tc = new tencetest_util_2FailuresAnd3Successes;
parent::setUp();
} # }}}
function testGetTests() # {{{
{
return $this->assertEquals(5, sizeof(iterator_to_array($this->tc->getTests())));
} # }}}
function testRun() # {{{
{
return $this->runAndAssert($this->tc, array(5, 2, 0, 0));
} # }}}
} # }}}
class tencetest_TestCaseFmtTest extends Tence_TestCase # {{{
{
function testNumber() {
return $this->assertEquals('1', $this->fmt(1));
}
function testTrue() {
return $this->assertEquals('True', $this->fmt(true));
}
function testFalse() {
return $this->assertEquals('False', $this->fmt(false));
}
function testNull() {
return $this->assertEquals('NULL', $this->fmt(null));
}
function testArray() {
$a = array(1, 2, 3);
$s = var_export($a, 1);
return $this->assertEquals($s, $this->fmt($a));
}
function testStdClass()
{
$re = '<stdClass instance.*>';
return $this->assertMatches($re, $this->fmt(new stdClass));
}
} # }}}
class tencetest_TestCaseMkdtempTest extends tencetest_TempDirFreshTest # {{{
{
protected function createDir() # {{{
{
return $this->mkdtemp();
} # }}}
function testMkdtempReturnsTempDirInstance() # {{{
{
return $this->assertIsA($this->td, 'Tence_util_TempDir');
} # }}}
function testMkdtempReturnsSoleReference() # {{{
{
$path = $this->mkdtemp()->path();
return $this->assertFalse(file_exists($path));
} # }}}
} # }}}
class tencetest_TestCaseMkstempTest extends tencetest_TempFileFreshTest # {{{
{
protected function createFile($path) # {{{
{
return $this->mkstemp($path);
} # }}}
function testMkstempReturnsTempFileInstance() # {{{
{
return $this->assertIsA($this->file, 'Tence_util_TempFile');
} # }}}
function testMkdtempReturnsSoleReference_path() # {{{
{
$path = $this->mkstemp()->path();
return $this->assertFalse(file_exists($path));
} # }}}
function testMkdtempReturnsSoleReference_fdesc() # {{{
{
$fd = $this->mkstemp()->fd();
return $this->assertFalse(is_resource($fd));
} # }}}
} # }}}
class tencetest_TestCaseSafeTests extends Tence_TestSuite # {{{
{
function __construct()
{
$this
->add(new tencetest_TestCaseAssertTests)
->add(new tencetest_TestCaseFmtTest)
->add(new tencetest_TestCaseInvokeTest)
->add(new tencetest_TestCaseRunTest)
;
}
} # }}}
class tencetest_TestCaseDangerousTests extends Tence_TestSuite # {{{
{
function __construct()
{
$this
->add(new tencetest_TestCaseMkdtempTest)
->add(new tencetest_TestCaseMkstempTest)
;
}
} # }}}
# vim: et ts=4 sts=4 sw=4 fdm=marker cms=\ #\ %s