44
55namespace Codeception \Util \Shared ;
66
7- use Codeception \PHPUnit \TestCase ;
8- use PHPUnit \Framework \Assert as PHPUnitAssert ;
7+ use PHPUnit \Framework \Assert ;
98use PHPUnit \Framework \Constraint \Constraint as PHPUnitConstraint ;
109use PHPUnit \Framework \Constraint \LogicalNot ;
10+ use ReflectionClass ;
1111
1212trait Asserts
1313{
1414 use InheritedAsserts;
1515
16- protected function assert (array $ arguments , bool $ not = false )
16+ /**
17+ * @param array{0: string} $arguments
18+ */
19+ protected function assert (array $ arguments , bool $ not = false ): void
1720 {
1821 $ not = $ not ? 'Not ' : '' ;
1922 $ method = ucfirst (array_shift ($ arguments ));
@@ -27,20 +30,31 @@ protected function assert(array $arguments, bool $not = false)
2730 $ not = '' ;
2831 }
2932
30- call_user_func_array ([PHPUnitAssert::class, 'assert ' . $ not . $ method ], $ arguments );
33+ $ fullMethod = "assert {$ not }{$ method }" ;
34+
35+ $ rc = new ReflectionClass (Assert::class);
36+ if ($ rc ->hasMethod ($ fullMethod ) && $ rc ->getMethod ($ fullMethod )->isStatic ()) {
37+ $ rc ->getMethod ($ fullMethod )->invokeArgs (null , $ arguments );
38+ } else {
39+ throw new \RuntimeException ("Method Assert:: {$ fullMethod } does not exist " );
40+ }
3141 }
3242
33- protected function assertNot ($ arguments )
43+ /**
44+ * @param array{0: string} $arguments
45+ * @return void
46+ */
47+ protected function assertNot (array $ arguments ): void
3448 {
3549 $ this ->assert ($ arguments , true );
3650 }
3751
3852 /**
3953 * Asserts that a file does not exist.
4054 */
41- protected function assertFileNotExists (string $ filename , string $ message = '' )
55+ protected function assertFileNotExists (string $ filename , string $ message = '' ): void
4256 {
43- TestCase ::assertFileDoesNotExist ($ filename , $ message );
57+ Assert ::assertFileDoesNotExist ($ filename , $ message );
4458 }
4559
4660 /**
@@ -49,56 +63,49 @@ protected function assertFileNotExists(string $filename, string $message = '')
4963 * @param mixed $expected
5064 * @param mixed $actual
5165 */
52- protected function assertGreaterOrEquals ($ expected , $ actual , string $ message = '' )
66+ protected function assertGreaterOrEquals ($ expected , $ actual , string $ message = '' ): void
5367 {
54- TestCase ::assertGreaterThanOrEqual ($ expected , $ actual , $ message );
68+ Assert ::assertGreaterThanOrEqual ($ expected , $ actual , $ message );
5569 }
5670
5771 /**
5872 * Asserts that a variable is empty.
59- *
60- * @param mixed $actual
6173 */
62- protected function assertIsEmpty ($ actual , string $ message = '' )
74+ protected function assertIsEmpty (mixed $ actual , string $ message = '' ): void
6375 {
64- TestCase ::assertEmpty ($ actual , $ message );
76+ Assert ::assertEmpty ($ actual , $ message );
6577 }
6678
6779 /**
6880 * Asserts that a value is smaller than or equal to another value.
69- *
70- * @param mixed $expected
71- * @param mixed $actual
7281 */
73- protected function assertLessOrEquals ($ expected , $ actual , string $ message = '' )
82+ protected function assertLessOrEquals (mixed $ expected , mixed $ actual , string $ message = '' ): void
7483 {
75- TestCase ::assertLessThanOrEqual ($ expected , $ actual , $ message );
84+ Assert ::assertLessThanOrEqual ($ expected , $ actual , $ message );
7685 }
7786
7887 /**
7988 * Asserts that a string does not match a given regular expression.
8089 */
81- protected function assertNotRegExp (string $ pattern , string $ string , string $ message = '' )
90+ protected function assertNotRegExp (string $ pattern , string $ string , string $ message = '' ): void
8291 {
83- TestCase ::assertDoesNotMatchRegularExpression ($ pattern , $ string , $ message );
92+ Assert ::assertDoesNotMatchRegularExpression ($ pattern , $ string , $ message );
8493 }
8594
8695 /**
8796 * Asserts that a string matches a given regular expression.
8897 */
89- protected function assertRegExp (string $ pattern , string $ string , string $ message = '' )
98+ protected function assertRegExp (string $ pattern , string $ string , string $ message = '' ): void
9099 {
91- TestCase ::assertMatchesRegularExpression ($ pattern , $ string , $ message );
100+ Assert ::assertMatchesRegularExpression ($ pattern , $ string , $ message );
92101 }
93102
94103 /**
95104 * Evaluates a PHPUnit\Framework\Constraint matcher object.
96- *
97- * @param mixed $value
98105 */
99- protected function assertThatItsNot ($ value , PHPUnitConstraint $ constraint , string $ message = '' )
106+ protected function assertThatItsNot (mixed $ value , PHPUnitConstraint $ constraint , string $ message = '' ): void
100107 {
101108 $ constraint = new LogicalNot ($ constraint );
102- TestCase ::assertThat ($ value , $ constraint , $ message );
109+ Assert ::assertThat ($ value , $ constraint , $ message );
103110 }
104111}
0 commit comments