MDL-37286 improve coding style in unit tests
authorPetr Škoda <commits@skodak.org>
Sat, 12 Jan 2013 14:28:57 +0000 (15:28 +0100)
committerPetr Škoda <commits@skodak.org>
Sat, 12 Jan 2013 14:28:57 +0000 (15:28 +0100)
lib/tests/weblib_test.php

index c9586f5..f7f2fca 100644 (file)
@@ -217,56 +217,46 @@ class web_testcase extends advanced_testcase {
         $this->resetAfterTest(false);
 
         $trace = new null_progress_trace();
-        ob_start();
         $trace->output('do');
         $trace->output('re', 1);
         $trace->output('mi', 2);
         $trace->finished();
         $output = ob_get_contents();
-        ob_end_clean();
         $this->assertSame('', $output);
+        $this->expectOutputString('');
     }
 
     public function test_text_progres_trace() {
         $this->resetAfterTest(false);
 
         $trace = new text_progress_trace();
-        ob_start();
         $trace->output('do');
         $trace->output('re', 1);
         $trace->output('mi', 2);
         $trace->finished();
-        $output = ob_get_contents();
-        ob_end_clean();
-        $this->assertSame("do\n  re\n    mi\n", $output);
+        $this->expectOutputString("do\n  re\n    mi\n");
     }
 
     public function test_html_progres_trace() {
         $this->resetAfterTest(false);
 
         $trace = new html_progress_trace();
-        ob_start();
         $trace->output('do');
         $trace->output('re', 1);
         $trace->output('mi', 2);
         $trace->finished();
-        $output = ob_get_contents();
-        ob_end_clean();
-        $this->assertSame("<p>do</p>\n<p>&#160;&#160;re</p>\n<p>&#160;&#160;&#160;&#160;mi</p>\n", $output);
+        $this->expectOutputString("<p>do</p>\n<p>&#160;&#160;re</p>\n<p>&#160;&#160;&#160;&#160;mi</p>\n");
     }
 
     public function test_html_list_progress_trace() {
         $this->resetAfterTest(false);
 
         $trace = new html_list_progress_trace();
-        ob_start();
         $trace->output('do');
         $trace->output('re', 1);
         $trace->output('mi', 2);
         $trace->finished();
-        $output = ob_get_contents();
-        ob_end_clean();
-        $this->assertSame("<ul>\n<li>do<ul>\n<li>re<ul>\n<li>mi</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n", $output);
+        $this->expectOutputString("<ul>\n<li>do<ul>\n<li>re<ul>\n<li>mi</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n");
     }
 
     public function test_progres_trace_buffer() {
@@ -284,18 +274,15 @@ class web_testcase extends advanced_testcase {
         $this->assertSame($output, $trace->get_buffer());
 
         $trace = new progress_trace_buffer(new html_progress_trace(), false);
-        ob_start();
         $trace->output('do');
         $trace->output('re', 1);
         $trace->output('mi', 2);
         $trace->finished();
-        $output = ob_get_contents();
-        ob_end_clean();
-        $this->assertSame('', $output);
         $this->assertSame("<p>do</p>\n<p>&#160;&#160;re</p>\n<p>&#160;&#160;&#160;&#160;mi</p>\n", $trace->get_buffer());
         $this->assertSame("<p>do</p>\n<p>&#160;&#160;re</p>\n<p>&#160;&#160;&#160;&#160;mi</p>\n", $trace->get_buffer());
         $trace->reset_buffer();
         $this->assertSame('', $trace->get_buffer());
+        $this->expectOutputString('');
     }
 
     public function test_combined_progres_trace() {
@@ -305,16 +292,12 @@ class web_testcase extends advanced_testcase {
         $trace2 = new progress_trace_buffer(new text_progress_trace(), false);
 
         $trace = new combined_progress_trace(array($trace1, $trace2));
-
-        ob_start();
         $trace->output('do');
         $trace->output('re', 1);
         $trace->output('mi', 2);
         $trace->finished();
-        $output = ob_get_contents();
-        ob_end_clean();
-        $this->assertSame('', $output);
         $this->assertSame("<p>do</p>\n<p>&#160;&#160;re</p>\n<p>&#160;&#160;&#160;&#160;mi</p>\n", $trace1->get_buffer());
         $this->assertSame("do\n  re\n    mi\n", $trace2->get_buffer());
+        $this->expectOutputString('');
     }
 }