2121
2222class TestCase extends \PHPUnit \Framework \TestCase
2323{
24+ /**
25+ * Returns a test double for the specified class.
26+ *
27+ * Shim for PHPUnit 4
28+ *
29+ * @param string $originalClassName
30+ *
31+ * @throws Exception
32+ *
33+ * @return PHPUnit_Framework_MockObject_MockObject
34+ */
35+ protected function createMock ($ originalClassName )
36+ {
37+ if (is_callable ('parent::createMock ' )) {
38+ return parent ::createMock ($ originalClassName );
39+ }
40+
41+ return $ this ->getMockBuilder ($ originalClassName )
42+ ->disableOriginalConstructor ()
43+ ->disableOriginalClone ()
44+ ->disableArgumentCloning ()
45+ ->getMock ();
46+ }
47+
48+ /**
49+ * Returns a mock object for the specified class.
50+ *
51+ * Shim for PHPUnit 6
52+ *
53+ * @param string $originalClassName name of the class to mock
54+ * @param array|null $methods When provided, only methods whose names are in the array
55+ * are replaced with a configurable test double. The behavior
56+ * of the other methods is not changed.
57+ * Providing null means that no methods will be replaced.
58+ * @param array $arguments parameters to pass to the original class' constructor
59+ * @param string $mockClassName class name for the generated test double class
60+ * @param bool $callOriginalConstructor can be used to disable the call to the original class' constructor
61+ * @param bool $callOriginalClone can be used to disable the call to the original class' clone constructor
62+ * @param bool $callAutoload can be used to disable __autoload() during the generation of the test double class
63+ * @param bool $cloneArguments
64+ * @param bool $callOriginalMethods
65+ * @param object $proxyTarget
66+ *
67+ * @throws PHPUnit_Framework_Exception
68+ *
69+ * @return PHPUnit_Framework_MockObject_MockObject
70+ *
71+ * @since Method available since Release 3.0.0
72+ */
73+ public function getMock ($ originalClassName , $ methods = [], array $ arguments = [], $ mockClassName = '' , $ callOriginalConstructor = true , $ callOriginalClone = true , $ callAutoload = true , $ cloneArguments = false , $ callOriginalMethods = false , $ proxyTarget = null )
74+ {
75+ if (is_callable ('parent::getMock ' )) {
76+ return parent ::getMock (
77+ $ originalClassName ,
78+ $ methods ,
79+ $ arguments ,
80+ $ mockClassName ,
81+ $ callOriginalConstructor ,
82+ $ callOriginalClone ,
83+ $ callAutoload ,
84+ $ cloneArguments ,
85+ $ callOriginalMethods ,
86+ $ proxyTarget
87+ );
88+ }
89+
90+ return $ this ->getMockBuilder ($ originalClassName )
91+ ->getMock ();
92+ }
93+
2494 /**
2595 * Shim for PHPUnit 6
2696 *
@@ -41,4 +111,18 @@ public function setExpectedException($exceptionName, $exceptionMessage = '', $ex
41111 $ this ->expectExceptionCode ($ exceptionCode );
42112 }
43113 }
114+
115+ /**
116+ * Shim for PHPUnit 4
117+ *
118+ * @param mixed $exceptionName
119+ */
120+ public function expectException ($ exceptionName )
121+ {
122+ if (is_callable ('parent::expectException ' )) {
123+ return parent ::expectException ($ exceptionName );
124+ }
125+
126+ $ this ->setExpectedException ($ exceptionName );
127+ }
44128}
0 commit comments