4
4
5
5
use phpmock \AbstractMockTest ;
6
6
use Mockery ;
7
+ use Mockery \MockInterface ;
7
8
8
9
/**
9
10
* Tests PHPMockery.
@@ -25,4 +26,37 @@ protected function mockFunction($namespace, $functionName, callable $function)
25
26
{
26
27
PHPMockery::mock ($ namespace , $ functionName )->andReturnUsing ($ function );
27
28
}
29
+
30
+ protected function setUp ()
31
+ {
32
+ parent ::setUp ();
33
+
34
+ $ this ->workaroundMockeryIssue268 ();
35
+ }
36
+
37
+ /**
38
+ * Workaround for Mockery's issue 268.
39
+ *
40
+ * Mockery-0.9 introduced global memoization of reflection methods. This
41
+ * workaround clears that memoization to fix the affected tests.
42
+ *
43
+ * @link https://github.com/padraic/mockery/issues/268 Issue 268
44
+ */
45
+ private function workaroundMockeryIssue268 ()
46
+ {
47
+ foreach (get_declared_classes () as $ class ) {
48
+ if (!is_subclass_of ($ class , MockInterface::class)) {
49
+ continue ;
50
+
51
+ }
52
+ try {
53
+ $ _mockery_methods = new \ReflectionProperty ($ class , "_mockery_methods " );
54
+ $ _mockery_methods ->setAccessible (true );
55
+ $ _mockery_methods ->setValue (null );
56
+
57
+ } catch (\ReflectionException $ e ) {
58
+ // The unaffected version mockery-0.8 didn't had that property.
59
+ }
60
+ }
61
+ }
28
62
}
0 commit comments