Sfoglia il codice sorgente

Make it possible to test sonata deprecations

WouterJ 10 anni fa
parent
commit
35f5b10273
1 ha cambiato i file con 16 aggiunte e 8 eliminazioni
  1. 16 8
      Tests/Datagrid/ListMapperTest.php

+ 16 - 8
Tests/Datagrid/ListMapperTest.php

@@ -121,21 +121,29 @@ class ListMapperTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals('fooName', $fieldDescription->getOption('label'));
         $this->assertEquals('fooName', $fieldDescription->getOption('label'));
     }
     }
 
 
-    /**
-     * @group legacy
-     */
     public function testAddViewInlineActionException()
     public function testAddViewInlineActionException()
     {
     {
+        set_error_handler('PHPUnit_Util_ErrorHandler::handleError');
+
         $this->setExpectedException('PHPUnit_Framework_Error', 'Inline action "view" is deprecated since version 2.2.4. Use inline action "show" instead.');
         $this->setExpectedException('PHPUnit_Framework_Error', 'Inline action "view" is deprecated since version 2.2.4. Use inline action "show" instead.');
 
 
-        $this->assertFalse($this->listMapper->has('_action'));
-        $this->listMapper->add('_action', 'actions', array('actions'=>array('view'=>array())));
+        try {
+            $this->assertFalse($this->listMapper->has('_action'));
+            $this->listMapper->add('_action', 'actions', array('actions'=>array('view'=>array())));
+        } catch (\PHPUnit_Framework_Error $e) {
+            restore_error_handler();
+
+            if ('Inline action "view" is deprecated since version 2.2.4. Use inline action "show" instead.' === $e->getMessage()) {
+                throw $e;
+            }
+        }
+
+        restore_error_handler();
     }
     }
 
 
     public function testAddViewInlineAction()
     public function testAddViewInlineAction()
     {
     {
-        // ignore E_USER_DEPRECATED error
-        $previousErrorHandler = set_error_handler( function () {}, E_USER_DEPRECATED);
+        $terminateErrorIgnore = \PHPUnit_Util_ErrorHandler::handleErrorOnce(E_USER_DEPRECATED);
 
 
         $this->assertFalse($this->listMapper->has('_action'));
         $this->assertFalse($this->listMapper->has('_action'));
         $this->listMapper->add('_action', 'actions', array('actions'=>array('view'=>array())));
         $this->listMapper->add('_action', 'actions', array('actions'=>array('view'=>array())));
@@ -149,7 +157,7 @@ class ListMapperTest extends \PHPUnit_Framework_TestCase
         $this->assertCount(1, $fieldDescription->getOption('actions'));
         $this->assertCount(1, $fieldDescription->getOption('actions'));
         $this->assertEquals(array('show'=>array()), $fieldDescription->getOption('actions'));
         $this->assertEquals(array('show'=>array()), $fieldDescription->getOption('actions'));
 
 
-        set_error_handler($previousErrorHandler);
+        $terminateErrorIgnore();
     }
     }
 
 
     public function testAddRemove()
     public function testAddRemove()