Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Call plugins' tearDown method when test stop

  • Loading branch information...
commit 237e39d42763daa00b786a14dd8849decdfa7119 1 parent 07a03db
Nikolay authored November 23, 2012
8  library/GeometriaLab/Test/PHPUnit/Plugin/AbstractPlugin.php
@@ -33,4 +33,12 @@ public function getTest()
33 33
     {
34 34
         return $this->test;
35 35
     }
  36
+
  37
+    /**
  38
+     * It will call when a test ended
  39
+     */
  40
+    public function tearDown()
  41
+    {
  42
+
  43
+    }
36 44
 }
5  library/GeometriaLab/Test/PHPUnit/Plugin/PluginInterface.php
@@ -20,4 +20,9 @@ public function setTest(TestCaseInterface $test);
20 20
      * @return TestCaseInterface
21 21
      */
22 22
     public function getTest();
  23
+
  24
+    /**
  25
+     * It will call when a test ended
  26
+     */
  27
+    public function tearDown();
23 28
 }
14  library/GeometriaLab/Test/PHPUnit/Plugin/PluginListener.php
@@ -114,6 +114,18 @@ public function startTest(\PHPUnit_Framework_Test $test)
114 114
      */
115 115
     public function endTest(\PHPUnit_Framework_Test $test, $time)
116 116
     {
117  
-
  117
+        if ($test instanceof TestCaseInterface) {
  118
+            foreach ($test->getPluginManager()->getRegisteredServices() as $serviceName => $plugins) {
  119
+                if ($serviceName === 'instances') {
  120
+                    continue;
  121
+                }
  122
+                foreach ($plugins as $pluginName) {
  123
+                    $plugin = $test->getPluginManager()->get($pluginName);
  124
+                    if (method_exists($plugin, 'tearDown')) {
  125
+                        $plugin->tearDown();
  126
+                    }
  127
+                }
  128
+            }
  129
+        }
118 130
     }
119 131
 }
2  library/GeometriaLab/Test/PHPUnit/TestCaseInterface.php
@@ -13,7 +13,7 @@
13 13
     public function setPluginManager(PluginManager $pluginManager);
14 14
 
15 15
     /**
16  
-     * @return \GeometriaLab\Test\Plugin\PluginManager
  16
+     * @return \GeometriaLab\Test\PHPUnit\Plugin\PluginManager
17 17
      */
18 18
     public function getPluginManager();
19 19
 

0 notes on commit 237e39d

Please sign in to comment.
Something went wrong with that request. Please try again.