|
|
@@ -1636,14 +1636,14 @@ class ViewTest extends TestCase
|
|
|
/**
|
|
|
* Test setting a block's content to an object without __toString magic method
|
|
|
*
|
|
|
- * This should produce a "Object of class TestObjectWithoutToString could not be converted to string" error
|
|
|
- * which gets thrown as a \PHPUnit\Framework\Error\Error Exception by PHPUnit.
|
|
|
- *
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testBlockSetObjectWithoutToString()
|
|
|
{
|
|
|
- $this->expectException(\PHPUnit\Framework\Error\Error::class);
|
|
|
+ $this->checkException(
|
|
|
+ 'Object of class Cake\Test\TestCase\View\TestObjectWithoutToString could not be converted to string'
|
|
|
+ );
|
|
|
+
|
|
|
$objectWithToString = new TestObjectWithoutToString();
|
|
|
$this->View->assign('testWithObjectWithoutToString', $objectWithToString);
|
|
|
}
|
|
|
@@ -1693,14 +1693,14 @@ class ViewTest extends TestCase
|
|
|
/**
|
|
|
* Test appending an object without __toString magic method to a block with append.
|
|
|
*
|
|
|
- * This should produce a "Object of class TestObjectWithoutToString could not be converted to string" error
|
|
|
- * which gets thrown as a \PHPUnit\Framework\Error\Error Exception by PHPUnit.
|
|
|
- *
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testBlockAppendObjectWithoutToString()
|
|
|
{
|
|
|
- $this->expectException(\PHPUnit\Framework\Error\Error::class);
|
|
|
+ $this->checkException(
|
|
|
+ 'Object of class Cake\Test\TestCase\View\TestObjectWithoutToString could not be converted to string'
|
|
|
+ );
|
|
|
+
|
|
|
$object = new TestObjectWithoutToString();
|
|
|
$this->View->assign('testBlock', 'Block ');
|
|
|
$this->View->append('testBlock', $object);
|
|
|
@@ -1726,14 +1726,14 @@ class ViewTest extends TestCase
|
|
|
/**
|
|
|
* Test prepending an object without __toString magic method to a block with prepend.
|
|
|
*
|
|
|
- * This should produce a "Object of class TestObjectWithoutToString could not be converted to string" error
|
|
|
- * which gets thrown as a \PHPUnit\Framework\Error\Error Exception by PHPUnit.
|
|
|
- *
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testBlockPrependObjectWithoutToString()
|
|
|
{
|
|
|
- $this->expectException(\PHPUnit\Framework\Error\Error::class);
|
|
|
+ $this->checkException(
|
|
|
+ 'Object of class Cake\Test\TestCase\View\TestObjectWithoutToString could not be converted to string'
|
|
|
+ );
|
|
|
+
|
|
|
$object = new TestObjectWithoutToString();
|
|
|
$this->View->assign('test', 'Block ');
|
|
|
$this->View->prepend('test', $object);
|
|
|
@@ -2198,4 +2198,14 @@ TEXT;
|
|
|
$this->assertEquals('mypath', $View->templatePath);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ protected function checkException($message)
|
|
|
+ {
|
|
|
+ if (version_compare(PHP_VERSION, '7.4', '>=')) {
|
|
|
+ $this->expectException(\Error::class);
|
|
|
+ } else {
|
|
|
+ $this->expectException(\PHPUnit\Framework\Error\Error::class);
|
|
|
+ }
|
|
|
+ $this->expectExceptionMessage($message);
|
|
|
+ }
|
|
|
}
|