ソースを参照

Fix risky tests.

Failing to close output buffers makes PHPUnit unhappy. Switch to test
styles that allow all created buffers to be closed.
Mark Story 11 年 前
コミット
92bd86274b

+ 1 - 0
tests/TestCase/Routing/Filter/AssetFilterTest.php

@@ -224,6 +224,7 @@ class AssetFilterTest extends TestCase {
 		$request = new Request($url);
 		$request = new Request($url);
 		$event = new Event('Dispatcher.beforeDispatch', $this, compact('request', 'response'));
 		$event = new Event('Dispatcher.beforeDispatch', $this, compact('request', 'response'));
 
 
+		ob_start();
 		$filter->beforeDispatch($event);
 		$filter->beforeDispatch($event);
 		$result = ob_get_contents();
 		$result = ob_get_contents();
 		ob_end_clean();
 		ob_end_clean();

+ 39 - 14
tests/TestCase/View/ViewTest.php

@@ -1475,23 +1475,33 @@ class ViewTest extends TestCase {
 /**
 /**
  * Test that starting the same block twice throws an exception
  * Test that starting the same block twice throws an exception
  *
  *
- * @expectedException \Cake\Core\Exception\Exception
  * @return void
  * @return void
  */
  */
 	public function testStartBlocksTwice() {
 	public function testStartBlocksTwice() {
-		$this->View->start('first');
-		$this->View->start('first');
+		try {
+			$this->View->start('first');
+			$this->View->start('first');
+			$this->fail('No exception');
+		} catch (\Cake\Core\Exception\Exception $e) {
+			ob_end_clean();
+			$this->assertTrue(true);
+		}
 	}
 	}
 
 
 /**
 /**
  * Test that an exception gets thrown when you leave a block open at the end
  * Test that an exception gets thrown when you leave a block open at the end
  * of a view.
  * of a view.
  *
  *
- * @expectedException \LogicException
  * @return void
  * @return void
  */
  */
 	public function testExceptionOnOpenBlock() {
 	public function testExceptionOnOpenBlock() {
-		$this->View->render('open_block');
+		try {
+			$this->View->render('open_block');
+			$this->fail('No exception');
+		} catch (\LogicException $e) {
+			ob_end_clean();
+			$this->assertContains('The "no_close" block was left open', $e->getMessage());
+		}
 	}
 	}
 
 
 /**
 /**
@@ -1514,23 +1524,32 @@ TEXT;
 /**
 /**
  * Make sure that extending the current view with itself causes an exception
  * Make sure that extending the current view with itself causes an exception
  *
  *
- * @expectedException LogicException
  * @return void
  * @return void
  */
  */
 	public function testExtendSelf() {
 	public function testExtendSelf() {
-		$this->View->layout = false;
-		$this->View->render('extend_self');
+		try {
+			$this->View->layout = false;
+			$this->View->render('extend_self');
+			$this->fail('No exception');
+		} catch (\LogicException $e) {
+			ob_end_clean();
+			$this->assertContains('cannot have views extend themselves', $e->getMessage());
+		}
 	}
 	}
 
 
 /**
 /**
  * Make sure that extending in a loop causes an exception
  * Make sure that extending in a loop causes an exception
  *
  *
- * @expectedException LogicException
  * @return void
  * @return void
  */
  */
 	public function testExtendLoop() {
 	public function testExtendLoop() {
-		$this->View->layout = false;
-		$this->View->render('extend_loop');
+		try {
+			$this->View->layout = false;
+			$this->View->render('extend_loop');
+		} catch (\LogicException $e) {
+			ob_end_clean();
+			$this->assertContains('cannot have views extend in a loop', $e->getMessage());
+		}
 	}
 	}
 
 
 /**
 /**
@@ -1554,12 +1573,18 @@ TEXT;
 /**
 /**
  * Extending an element which doesn't exist should throw a missing view exception
  * Extending an element which doesn't exist should throw a missing view exception
  *
  *
- * @expectedException LogicException
  * @return void
  * @return void
  */
  */
 	public function testExtendMissingElement() {
 	public function testExtendMissingElement() {
-		$this->View->layout = false;
-		$this->View->render('extend_missing_element');
+		try {
+			$this->View->layout = false;
+			$this->View->render('extend_missing_element');
+			$this->fail('No exception');
+		} catch (\LogicException $e) {
+			ob_end_clean();
+			ob_end_clean();
+			$this->assertContains('element', $e->getMessage());
+		}
 	}
 	}
 
 
 /**
 /**

+ 1 - 0
tests/test_app/Plugin/Company/TestPluginThree/webroot/css/company.css

@@ -0,0 +1 @@
+/* company.css */