Browse Source

Try to fix test failures on PHP 7.4.

ADmad 6 years ago
parent
commit
401abc25ee
1 changed files with 22 additions and 12 deletions
  1. 22 12
      tests/TestCase/View/ViewTest.php

+ 22 - 12
tests/TestCase/View/ViewTest.php

@@ -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);
+    }
 }