1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Codeception \Util \Shared ;
4
6
5
7
use Codeception \PHPUnit \TestCase ;
6
- use PHPUnit \Framework \Constraint \Constraint ;
8
+ use PHPUnit \Framework \Assert as PHPUnitAssert ;
9
+ use PHPUnit \Framework \Constraint \Constraint as PHPUnitConstraint ;
7
10
use PHPUnit \Framework \Constraint \LogicalNot ;
8
11
9
12
trait Asserts
10
13
{
11
14
use InheritedAsserts;
12
15
13
- /**
14
- * @param $arguments
15
- * @param bool $not
16
- */
17
- protected function assert ($ arguments , $ not = false )
16
+ protected function assert (array $ arguments , bool $ not = false )
18
17
{
19
18
$ not = $ not ? 'Not ' : '' ;
20
19
$ method = ucfirst (array_shift ($ arguments ));
21
20
if (($ method === 'True ' ) && $ not ) {
22
21
$ method = 'False ' ;
23
22
$ not = '' ;
24
23
}
24
+
25
25
if (($ method === 'False ' ) && $ not ) {
26
26
$ method = 'True ' ;
27
27
$ not = '' ;
28
28
}
29
29
30
- call_user_func_array ([' \PHPUnit\Framework\Assert ' , 'assert ' . $ not . $ method ], $ arguments );
30
+ call_user_func_array ([PHPUnitAssert::class , 'assert ' . $ not . $ method ], $ arguments );
31
31
}
32
32
33
33
protected function assertNot ($ arguments )
@@ -37,82 +37,66 @@ protected function assertNot($arguments)
37
37
38
38
/**
39
39
* Asserts that a file does not exist.
40
- *
41
- * @param string $filename
42
- * @param string $message
43
40
*/
44
- protected function assertFileNotExists ($ filename , $ message = '' )
41
+ protected function assertFileNotExists (string $ filename , string $ message = '' )
45
42
{
46
- TestCase::assertFileNotExists ($ filename , $ message );
43
+ TestCase::assertFileDoesNotExist ($ filename , $ message );
47
44
}
48
45
49
46
/**
50
47
* Asserts that a value is greater than or equal to another value.
51
48
*
52
- * @param $expected
53
- * @param $actual
54
- * @param string $message
49
+ * @param mixed $expected
50
+ * @param mixed $actual
55
51
*/
56
- protected function assertGreaterOrEquals ($ expected , $ actual , $ message = '' )
52
+ protected function assertGreaterOrEquals ($ expected , $ actual , string $ message = '' )
57
53
{
58
54
TestCase::assertGreaterThanOrEqual ($ expected , $ actual , $ message );
59
55
}
60
56
61
57
/**
62
58
* Asserts that a variable is empty.
63
59
*
64
- * @param $actual
65
- * @param string $message
60
+ * @param mixed $actual
66
61
*/
67
- protected function assertIsEmpty ($ actual , $ message = '' )
62
+ protected function assertIsEmpty ($ actual , string $ message = '' )
68
63
{
69
64
TestCase::assertEmpty ($ actual , $ message );
70
65
}
71
66
72
67
/**
73
68
* Asserts that a value is smaller than or equal to another value.
74
69
*
75
- * @param $expected
76
- * @param $actual
77
- * @param string $message
70
+ * @param mixed $expected
71
+ * @param mixed $actual
78
72
*/
79
- protected function assertLessOrEquals ($ expected , $ actual , $ message = '' )
73
+ protected function assertLessOrEquals ($ expected , $ actual , string $ message = '' )
80
74
{
81
75
TestCase::assertLessThanOrEqual ($ expected , $ actual , $ message );
82
76
}
83
77
84
78
/**
85
79
* Asserts that a string does not match a given regular expression.
86
- *
87
- * @param string $pattern
88
- * @param string $string
89
- * @param string $message
90
80
*/
91
- protected function assertNotRegExp ($ pattern , $ string , $ message = '' )
81
+ protected function assertNotRegExp (string $ pattern , string $ string , string $ message = '' )
92
82
{
93
- TestCase::assertNotRegExp ($ pattern , $ string , $ message );
83
+ TestCase::assertDoesNotMatchRegularExpression ($ pattern , $ string , $ message );
94
84
}
95
85
96
86
/**
97
87
* Asserts that a string matches a given regular expression.
98
- *
99
- * @param string $pattern
100
- * @param string $string
101
- * @param string $message
102
88
*/
103
- protected function assertRegExp ($ pattern , $ string , $ message = '' )
89
+ protected function assertRegExp (string $ pattern , string $ string , string $ message = '' )
104
90
{
105
- TestCase::assertRegExp ($ pattern , $ string , $ message );
91
+ TestCase::assertMatchesRegularExpression ($ pattern , $ string , $ message );
106
92
}
107
93
108
94
/**
109
95
* Evaluates a PHPUnit\Framework\Constraint matcher object.
110
96
*
111
- * @param $value
112
- * @param Constraint $constraint
113
- * @param string $message
97
+ * @param mixed $value
114
98
*/
115
- protected function assertThatItsNot ($ value , $ constraint , $ message = '' )
99
+ protected function assertThatItsNot ($ value , PHPUnitConstraint $ constraint , string $ message = '' )
116
100
{
117
101
$ constraint = new LogicalNot ($ constraint );
118
102
TestCase::assertThat ($ value , $ constraint , $ message );
0 commit comments