本文整理汇总了PHP中PHPUnit类的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit类的具体用法?PHP PHPUnit怎么用?PHP PHPUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
function main() {
// include_once($_SERVER['DOCUMENT_ROOT'].'/ScarletFinal/classes/Template.php');
// $template = new Template('main.tpl/');
include('header.php');
// $template->compile('main.tpl');
require_once '../Sandbox.php';
include '../PHPUnit.php';
if(isset($_GET['path']) && is_dir($_GET['path'])) {
$suite = (isset($_GET['test'])) ? $_GET['test'] : '';
$phpunit = new PHPUnit($_GET['path'], $suite);
chdir($_GET['path']);
} else {
throw new Exception("Could not find the specified tests directory: <strong>".$_GET['path'].'</strong>', 1);
}
$results = $phpunit->run();
// print_r($results);
echo $phpunit->toHTML($results);
include('footer.php');
// include('main.php');
}
示例2: check_for_errors
function check_for_errors() {
function toHTML($type, $e) {
$left = '<div class="box rounded error">';
$out = '<div class="light rounded">!</div>
<div class="message">'.$type.': '.$e['message'].'</div>
<div class="line">'.$e['line'].'</div>
<div class="file">'.$e['file'].'</div>';
$right = '</div>';
return $left.$out.$right;
}
$results_so_far = '';
if(stristr(@ob_get_contents(),"<body>")) { //this is already HTML
//do nothing for now. In the future we may change behaviour
} elseif (@ob_get_contents()) { //this is json output, process it.
$results_so_far = @ob_get_contents();
@ob_clean();
echo PHPUnit::toHTML($results_so_far);
}
if( false === is_null($aError = error_get_last()) ) {
switch($aError['type']) {
case E_NOTICE:
echo toHTML("Notice", $aError);
break;
case E_WARNING:
echo toHTML("Warning", $aError);
break;
case E_ERROR:
echo toHTML("Error", $aError);
break;
case E_PARSE:
echo toHTML("Parse", $aError);
break;
default:
echo toHTML("Unknown", $aError);
echo "<br/>";
break;
}
}
if($results_so_far) {
include('Main/footer.php');
}
exit(1);
}
示例3: runTest
function runTest($name)
{
$test = strToLower($name);
include_once "test_{$test}.php";
echo "# Starting unit test for {$name}:\n";
$tc =& new PhpUnit_TestSuite('File_Passwd' . ($name != 'File_Passwd' ? '_' . $name : '') . 'Test');
$rs = PHPUnit::run($tc);
echo $rs->toString() . "\n";
flush();
}
示例4: show
/**
* this prints the HTML code straight out
*
*/
function show()
{
$request = $_REQUEST;
$showPassed = FALSE;
$submitted = @$request['submitted'];
if ($submitted) {
$showPassed = @$request['showOK'] ? TRUE : FALSE;
}
$suiteResults = array();
foreach ($this->_suites as $aSuite) {
$aSuiteResult = array();
// remove the first directory's name from the test-suite name, since it
// mostly is something like 'tests' or alike
$removablePrefix = explode('_', $aSuite->getName());
$aSuiteResult['name'] = str_replace($removablePrefix[0] . '_', '', $aSuite->getName());
if ($submitted && isset($request[$aSuiteResult['name']])) {
$result = PHPUnit::run($aSuite);
$aSuiteResult['counts']['run'] = $result->runCount();
$aSuiteResult['counts']['error'] = $result->errorCount();
$aSuiteResult['counts']['failure'] = $result->failureCount();
$aSuiteResult['results'] = $this->_prepareResult($result, $showPassed);
$per = 100 / $result->runCount();
$failed = $per * $result->errorCount() + $per * $result->failureCount();
$aSuiteResult['percent'] = round(100 - $failed, 2);
} else {
$aSuiteResult['addInfo'] = 'NOT EXECUTED';
}
$suiteResults[] = $aSuiteResult;
}
$final['name'] = 'OVERALL RESULT';
$final['counts'] = array();
$final['percent'] = 0;
$numExecutedTests = 0;
foreach ($suiteResults as $aSuiteResult) {
if (sizeof(@$aSuiteResult['counts'])) {
foreach ($aSuiteResult['counts'] as $key => $aCount) {
if (!isset($final['counts'][$key])) {
$final['counts'][$key] = 0;
}
$final['counts'][$key] += $aCount;
}
}
}
if (isset($final['counts']['run'])) {
$per = 100 / $final['counts']['run'];
$failed = $per * $final['counts']['error'] + $per * $final['counts']['failure'];
$final['percent'] = round(100 - $failed, 2);
} else {
$final['percent'] = 0;
}
array_unshift($suiteResults, $final);
include 'PHPUnit/GUI/HTML.tpl';
}
示例5: check_for_errors
function check_for_errors()
{
function toHTML($type, $e)
{
$left = '<div class="box rounded error">';
$out = '<div class="light rounded">!</div>
<div class="message">' . $type . ': ' . $e['message'] . '</div>
<div class="line">' . $e['line'] . '</div>
<div class="file">' . $e['file'] . '</div>';
$right = '</div>';
return $left . $out . $right;
}
$results_so_far = '';
if (@ob_get_contents()) {
$results_so_far = @ob_get_contents();
@ob_clean();
echo PHPUnit::toHTML($results_so_far);
}
if (false === is_null($aError = error_get_last())) {
switch ($aError['type']) {
case E_NOTICE:
echo toHTML("Notice", $aError);
break;
case E_WARNING:
echo toHTML("Warning", $aError);
break;
case E_ERROR:
echo toHTML("Error", $aError);
break;
case E_PARSE:
echo toHTML("Parse", $aError);
break;
default:
echo toHTML("Unknown", $aError);
echo "<br/>";
break;
}
}
if ($results_so_far) {
include 'Main/footer.php';
}
exit(1);
}
示例6: PHPUnit_TestSuite
$message2->delete();
$message->fetch();
$threadCount2 = $message->getNumMessagesInThread();
if ($threadCount != ($threadCount2 + 1)) {
$this->fail("Thread stats not updated correctly.");
}
}
} // class PhorumMessage_test
class PhorumForum_test extends PHPUnit_TestCase
{
}
$suite = new PHPUnit_TestSuite("PhorumUser_Test");
$suite->addTestSuite("PhorumMessage_Test");
$result = PHPUnit::run($suite);
echo $result->toHtml();
//$message = new Phorum_message(1);
//camp_dump($message);
?>
示例7: test_entryContributor
$this->assertEquals($value, $this->entry->author);
}
function test_entryContributor()
{
$value = 'Sam Ruby';
$this->assertEquals($value, $this->entry->contributor);
}
function test_entryContributorOffset()
{
$value = 'Joe Gregorio';
$this->assertEquals($value, $this->entry->contributor(1));
}
# According to RFC4287 section 4.2.7.2:
# [..]If the 'rel' attribute is not present, the link element MUST be
# interpreted as if the link relation type is "alternate".
function test_getsLinkWithoutRel()
{
$source = '<?xml version="1.0" ?>
<entry xmlns="http://www.w3.org/2005/Atom">
<link href="http://example.org/2005/04/02/atom" />
</entry>
';
$feed = new XML_Feed_Parser($source);
$entry = $feed->getEntryByOffset(0);
// Output
$this->assertEquals("http://example.org/2005/04/02/atom", $entry->link(0, 'href', array('rel' => 'alternate')));
}
}
$suite = new PHPUnit_TestSuite('XML_Feed_Parser_Atom_valueValidity_TestCase');
$result = PHPUnit::run($suite, '123');
echo $result->toString();
示例8: testrelativePath
if (OS_WINDOWS) {
$this->assertTrue(File::isAbsolute('C:\\\\data'));
$this->assertTrue(File::isAbsolute('d:/data'));
$this->assertFalse(File::isAbsolute('\\'));
} else {
$this->assertTrue(File::isAbsolute('/'));
$this->assertFalse(File::isAbsolute('\\'));
$this->assertTrue(File::isAbsolute('~mike/bin'));
}
}
function testrelativePath()
{
$this->assertEquals('tests/File', File::relativePath('/usr/share/pear/tests/File', '/usr/share/pear', '/'));
$this->assertEquals('../etc', File::relativePath('/etc', '/usr', '/'));
$this->assertEquals('D:\\Data', File::relativePath('D:\\Data', 'C:\\Data', '\\'));
if (OS_WINDOWS) {
$this->assertEquals('data\\dir', File::relativePath('/var/data/dir', '/var'));
} else {
$this->assertEquals('data/dir', File::relativePath('/var/data/dir', '/var'));
}
$this->assertEquals('../', File::relativePath('data', 'data/dir', '/'));
}
function testrealpath()
{
$drive = OS_WINDOWS ? substr(getcwd(), 0, 2) : '';
$this->assertEquals($drive . '/a/weird/path/is', File::realpath('/a\\weird//path\\is/that/./../', '/'));
$this->assertEquals($drive . '/a/weird/path/is/that', File::realpath('/a\\weird//path\\is/that/./../that/.', '/'));
}
}
$result =& PHPUnit::run(new PHPUnit_TestSuite('FileTest'));
echo $result->toString();
示例9: tearDown
}
function tearDown()
{
}
/**
* Try to work with this ill-formed feed. If the tidy extension is not installed,
* it expects parsing to fail. If tidy is installed and parsing fails, the test
* fails. If tidy is installed and it parses, then the test passes.
*/
function test_Tidy()
{
$sample_dir = XML_Feed_Parser_TestCase::getSampleDir();
$file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "illformed_atom10.xml");
try {
$feed = new XML_Feed_Parser($file, false, true, true);
} catch (XML_Feed_Parser_Exception $e) {
if (extension_loaded('tidy')) {
$this->assertTrue(false);
} else {
$this->assertTrue(true);
}
return;
}
$entry = $feed->getEntryByOffset(0);
$this->assertEquals($entry->author, 'Example author');
}
}
$suite = new PHPUnit_TestSuite();
$suite->addTestSuite("XML_Feed_Parser_Tidy_TestCase");
$result = PHPUnit::run($suite, "123");
echo $result->toString();
示例10: phpversion
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n<head>\n<title>{$title}</title>\n</head>\n<body>\n<h1>{$title}</h1>\n";
} else {
echo "{$title}\n\n";
}
if (isset($_SERVER['REQUEST_METHOD'])) {
echo "<h3>Using lib version: {$xmlrpcVersion} on PHP version: " . phpversion() . "</h3>\n";
echo '<h3>Running ' . $suite->testCount() . ' tests (some of which are multiple) against servers: http://' . htmlspecialchars($LOCALSERVER . $URI) . ' and https://' . htmlspecialchars($HTTPSSERVER . $HTTPSURI) . "\n ...</h3>\n";
flush();
} else {
echo "Using lib version: {$xmlrpcVersion} on PHP version: " . phpversion() . "\n";
echo 'Running ' . $suite->testCount() . ' tests (some of which are multiple) against servers: http://' . $LOCALSERVER . $URI . ' and https://' . $HTTPSSERVER . $HTTPSURI . "\n\n";
}
// do some basic timing measurement
list($micro, $sec) = explode(' ', microtime());
$start_time = $sec + $micro;
$PHPUnit = new PHPUnit();
$result = $PHPUnit->run($suite);
list($micro, $sec) = explode(' ', microtime());
$end_time = $sec + $micro;
if (!isset($_SERVER['REQUEST_METHOD'])) {
echo $result->toString() . "\n";
}
if (isset($_SERVER['REQUEST_METHOD'])) {
echo '<h3>' . $result->failureCount() . " test failures</h3>\n";
printf("Time spent: %.2f secs<br/>\n", $end_time - $start_time);
} else {
echo $result->failureCount() . " test failures\n";
printf("Time spent: %.2f secs\n", $end_time - $start_time);
}
if ($result->failureCount() && !$DEBUG) {
$target = strpos($_SERVER['PHP_SELF'], '?') ? $_SERVER['PHP_SELF'] . '&DEBUG=1' : $_SERVER['PHP_SELF'] . '?DEBUG=1';
示例11: testExtractBody
function testExtractBody()
{
$testcases = array("before<body></body>after" => "", "<body>Simple</body>" => "Simple", "<Body>Ignore case</BODY>" => "Ignore case", "<body id=\"id123\">Attributes</body>" => "Attributes", "<body id=\"id123\">Html entities: &<></body >" => "Html entities: &<>", "<body><b class=\"bold\">Tags</b></body\n\n>" => " Tags ", "<body\n\n>\nNewlines\n</body\n\n>" => "\nNewlines\n");
foreach ($testcases as $html => $body) {
$this->assertEquals($body, $this->indexer->extract_body($html));
}
}
}
class IndexerFactoryTest extends PHPUnit_TestCase
{
var $index;
function setUp()
{
$this->index = new IndexStub();
}
function tearDown()
{
unset($this->index);
}
function testIndexer()
{
$testcases = array('abc.txt' => 'Fulltext_TextIndexer', 'abc.htm' => 'Fulltext_HtmlIndexer', 'abc.html' => 'Fulltext_HtmlIndexer');
foreach ($testcases as $path => $class) {
$this->assertTrue(is_a(Fulltext_indexer_factory($path, $this->index), $class), $class);
}
}
}
$testcases = array('HtmlIndexerTest', 'IndexerFactoryTest');
foreach ($testcases as $testcase) {
echo PHPUnit::run(new PHPUnit_TestSuite($testcase))->toString();
}
示例12: QuickForm_table_test
class QuickForm_table_test extends PHPUnit_TestCase
{
var $el;
function QuickForm_table_test($name = 'QuickForm_table_test')
{
$this->PHPUnit_TestCase($name);
}
function setUp()
{
$this->el = new HTML_QuickForm_table('test_table', 'Testing');
$this->el->addField(new HTML_QuickForm_text('fname', 'First Name'));
$this->el->addField(new HTML_QuickForm_text('lname', 'Last Name'));
}
function tearDown()
{
}
function test_Html()
{
$this->assertEquals($this->el->toHtml(), '');
}
function test_Html_with_values()
{
$el = unserialize(serialize($this->el));
$el->setName('test_table_2');
$el->setValue(array(array('fname' => 'John', 'lname' => 'Stamos'), array('fname' => 'Sally', 'lname' => 'Field'), array('fname' => 'Steve', 'lname' => 'Field')));
$this->assertEquals($el->toHtml(), '');
}
}
$test = new PHPUnit_TestSuite('QuickForm_table_test');
$result = PHPUnit::run($test);
print $result->toString();
示例13: runTest
/**
* Run the test suite.
*
* This method runs the test suite and updates the messages
* for the user. When finished it changes the status line
* to 'Test Complete'
*
* @access public
* @param none
* @return void
*/
function runTest()
{
// Notify the user that the test is running.
$this->_showStatus('Running Test...');
// Run the test.
$result = PHPUnit::run($this->suite);
// Update the labels.
$this->_setLabelValue($this->numberOfRuns, $result->runCount());
$this->_setLabelValue($this->numberOfErrors, $result->errorCount());
$this->_setLabelValue($this->numberOfFailures, $result->failureCount());
// Update the progress bar.
$this->_updateProgress($result->runCount(), $result->errorCount(), $result->failureCount());
// Show the errors.
$this->_showFailures($result->errors(), $this->dumpArea);
// Show the messages from the tests.
if ($this->showPassed->get_active()) {
// Show failures and success.
$this->_showAll($result, $this->reportArea);
} else {
// Show only failures.
$this->_showFailures($result->failures(), $this->reportArea);
}
// Update the status message.
$this->_showStatus('Test complete');
}
示例14: phpversion
} else {
echo "{$title}\n\n";
}
if (isset($_SERVER['REQUEST_METHOD'])) {
echo "<h3>Using lib version: {$xmlrpcVersion} on PHP version: " . phpversion() . "</h3>\n";
echo '<h3>Running ' . $suite->testCount() . ' tests (some of which are multiple) against servers: http://' . htmlspecialchars($LOCALSERVER . $URI) . ' and https://' . htmlspecialchars($HTTPSSERVER . $HTTPSURI) . "\n ...</h3>\n";
flush();
@ob_flush();
} else {
echo "Using lib version: {$xmlrpcVersion} on PHP version: " . phpversion() . "\n";
echo 'Running ' . $suite->testCount() . ' tests (some of which are multiple) against servers: http://' . $LOCALSERVER . $URI . ' and https://' . $HTTPSSERVER . $HTTPSURI . "\n\n";
}
// do some basic timing measurement
list($micro, $sec) = explode(' ', microtime());
$start_time = $sec + $micro;
$PHPUnit = new PHPUnit();
$result = $PHPUnit->run($suite, $DEBUG == 0 ? '.' : '<hr/>');
list($micro, $sec) = explode(' ', microtime());
$end_time = $sec + $micro;
if (!isset($_SERVER['REQUEST_METHOD'])) {
echo $result->toString() . "\n";
}
if (isset($_SERVER['REQUEST_METHOD'])) {
echo '<h3>' . $result->failureCount() . " test failures</h3>\n";
printf("Time spent: %.2f secs<br/>\n", $end_time - $start_time);
} else {
echo $result->failureCount() . " test failures\n";
printf("Time spent: %.2f secs\n", $end_time - $start_time);
}
if ($result->failureCount() && !$DEBUG) {
$target = strpos($_SERVER['PHP_SELF'], '?') ? $_SERVER['PHP_SELF'] . '&DEBUG=1' : $_SERVER['PHP_SELF'] . '?DEBUG=1';
示例15: run
public function run()
{
$ut = new PHPUnit();
$ut->execute();
}