Skip to content

Commit

Permalink
Nette\Test: fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 9, 2012
1 parent d54e6dc commit 97c6a00
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
12 changes: 7 additions & 5 deletions Tester/NetteTestCase.php
Expand Up @@ -66,23 +66,25 @@ public function run()
{
$this->execute();
$tests = 0;
$trim = isset($this->sections['expect']);

// compare output
$output = self::normalize($this->output, $trim);
$expectedOutput = self::normalize($this->getExpectedOutput(), $trim);
$expectedOutput = $this->getExpectedOutput();
if ($expectedOutput !== NULL) {
$tests++;
$trim = isset($this->sections['expect']);
$output = self::normalize($this->output, $trim);
$expectedOutput = self::normalize($expectedOutput, $trim);
if (!$this->compare($output, $expectedOutput)) {
throw new NetteTestCaseException("Output doesn't match.");
}
}

// compare headers
$expectedHeaders = self::normalize($this->getExpectedHeaders(), TRUE);
$expectedHeaders = $this->getExpectedHeaders();
if ($expectedHeaders !== NULL) {
$tests++;
$headers = array_change_key_case(self::parseLines($this->headers, ':'), CASE_LOWER);
$expectedHeaders = self::normalize($expectedHeaders, TRUE);
$expectedHeaders = array_change_key_case(self::parseLines($expectedHeaders, ':'), CASE_LOWER);
foreach ($expectedHeaders as $name => $header) {
if (!isset($headers[$name])) {
Expand Down Expand Up @@ -229,7 +231,7 @@ public static function parseSections($testFile)
$sections['options']['name'] = preg_match('#^\s*\*\s*TEST:(.*)#mi', $phpDoc, $matches) ? trim($matches[1]) : $testFile;

// file parts
$tmp = preg_split('#^-{3,}([^ -]+)-{1,}(?:\r?\n|$)#m', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
$tmp = preg_split('#^-{3,}([^\s-]+)-{1,}(?:\r?\n|$)#m', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
$i = 1;
while (isset($tmp[$i])) {
$sections[strtolower($tmp[$i])] = $tmp[$i+1];
Expand Down
9 changes: 4 additions & 5 deletions Tester/RunTests.php
Expand Up @@ -86,18 +86,17 @@ public function run()
$count++;
$testCase = new NetteTestCase($entry, $this->cmdLine);
try {
echo '.';
$testCase->run();
echo '.';
$passed[] = array($testCase->getName(), $entry);

} catch (NetteTestCaseException $e) {
echo 'F';
$failed[] = array($testCase->getName(), $entry, $e->getMessage());

if ($testCase->getExpectedOutput() !== NULL) {
$this->log($entry, $testCase->getOutput(), self::OUTPUT);
$this->log($entry, $testCase->getExpectedOutput(), self::EXPECTED);
}
$this->log($entry, $testCase->getOutput(), self::OUTPUT);
$this->log($entry, $testCase->getExpectedOutput(), self::EXPECTED);

if ($testCase->getExpectedHeaders() !== NULL) {
$this->log($entry, $testCase->getHeaders(), self::OUTPUT, self::HEADERS);
$this->log($entry, $testCase->getExpectedHeaders(), self::EXPECTED, self::HEADERS);
Expand Down
18 changes: 15 additions & 3 deletions Tester/initialize.php
Expand Up @@ -92,13 +92,25 @@ public static function purge($dir)


/**
* Writes new heading.
* Writes new section.
* @param string
* @return void
*/
public static function heading($heading)
public static function section($heading = NULL)
{
echo "$heading\n" . str_repeat('-', strlen($heading)) . "\n\n";
echo $heading ? "==> $heading\n\n" : "===\n\n";
}



/**
* Writes new message.
* @param string
* @return void
*/
public static function message($message)
{
echo "$message\n\n";
}


Expand Down
11 changes: 7 additions & 4 deletions tests/Test.dump().001.phpt
@@ -1,7 +1,7 @@
<?php

/**
* Test: Nette\Test::dump() basic types & heading()
* Test: Nette\Test::dump() basic types & section()
*
* @author David Grudl
* @category Nette
Expand Down Expand Up @@ -44,7 +44,9 @@ class TestClass

dump( new TestClass );

Test::heading('Section');
Test::section('Section');

Test::section();


__halt_compiler();
Expand Down Expand Up @@ -89,5 +91,6 @@ object(TestClass) (3) {
"z" protected => int(30)
}

Section
-------
==> Section

===
4 changes: 2 additions & 2 deletions tests/Test.getSection().phpt
@@ -1,7 +1,7 @@
<?php

/**
* Test: Nette\Test::heading()
* Test: Nette\Test::getSection()
*
* @author David Grudl
* @category Nette
Expand Down Expand Up @@ -52,5 +52,5 @@ array(5) {
"category" => string(5) "Nette"
"package" => string(10) "Nette\Test"
"subpackage" => string(9) "UnitTests"
"name" => string(21) "Nette\Test::heading()"
"name" => string(24) "Nette\Test::getSection()"
}

0 comments on commit 97c6a00

Please sign in to comment.