File tree Expand file tree Collapse file tree 6 files changed +213
-26
lines changed Expand file tree Collapse file tree 6 files changed +213
-26
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,19 @@ trait ConstraintTrait
20
20
{
21
21
use Legacy \ConstraintTraitForV6;
22
22
}
23
- } else {
23
+ } elseif ( $ r -> getProperty ( ' exporter ' )-> isProtected ()) {
24
24
trait ConstraintTrait
25
25
{
26
26
use Legacy \ConstraintTraitForV7;
27
27
}
28
+ } elseif (\PHP_VERSION < 70100 || !$ r ->getMethod ('evaluate ' )->hasReturnType ()) {
29
+ trait ConstraintTrait
30
+ {
31
+ use Legacy \ConstraintTraitForV8;
32
+ }
33
+ } else {
34
+ trait ConstraintTrait
35
+ {
36
+ use Legacy \ConstraintTraitForV9;
37
+ }
28
38
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bridge \PhpUnit \Legacy ;
13
+
14
+ /**
15
+ * @internal
16
+ */
17
+ trait ConstraintLogicTrait
18
+ {
19
+ private function doEvaluate ($ other , $ description , $ returnResult )
20
+ {
21
+ $ success = false ;
22
+
23
+ if ($ this ->matches ($ other )) {
24
+ $ success = true ;
25
+ }
26
+
27
+ if ($ returnResult ) {
28
+ return $ success ;
29
+ }
30
+
31
+ if (!$ success ) {
32
+ $ this ->fail ($ other , $ description );
33
+ }
34
+
35
+ return null ;
36
+ }
37
+
38
+ private function doAdditionalFailureDescription ($ other ): string
39
+ {
40
+ return '' ;
41
+ }
42
+
43
+ private function doCount (): int
44
+ {
45
+ return 1 ;
46
+ }
47
+
48
+ private function doFailureDescription ($ other ): string
49
+ {
50
+ return $ this ->exporter ()->export ($ other ).' ' .$ this ->toString ();
51
+ }
52
+
53
+ private function doMatches ($ other ): bool
54
+ {
55
+ return false ;
56
+ }
57
+
58
+ private function doToString (): string
59
+ {
60
+ return '' ;
61
+ }
62
+ }
Original file line number Diff line number Diff line change 18
18
*/
19
19
trait ConstraintTraitForV6
20
20
{
21
+ /**
22
+ * @return bool|null
23
+ */
24
+ public function evaluate ($ other , $ description = '' , $ returnResult = false )
25
+ {
26
+ return $ this ->doEvaluate ($ other , $ description , $ returnResult );
27
+ }
28
+
21
29
/**
22
30
* @return int
23
31
*/
@@ -86,6 +94,25 @@ private function doCount()
86
94
return 1 ;
87
95
}
88
96
97
+ private function doEvaluate ($ other , $ description , $ returnResult )
98
+ {
99
+ $ success = false ;
100
+
101
+ if ($ this ->matches ($ other )) {
102
+ $ success = true ;
103
+ }
104
+
105
+ if ($ returnResult ) {
106
+ return $ success ;
107
+ }
108
+
109
+ if (!$ success ) {
110
+ $ this ->fail ($ other , $ description );
111
+ }
112
+
113
+ return null ;
114
+ }
115
+
89
116
private function doFailureDescription ($ other )
90
117
{
91
118
return $ this ->exporter ()->export ($ other ).' ' .$ this ->toString ();
Original file line number Diff line number Diff line change 18
18
*/
19
19
trait ConstraintTraitForV7
20
20
{
21
+ use ConstraintLogicTrait;
22
+
23
+ /**
24
+ * @return bool|null
25
+ */
26
+ public function evaluate ($ other , $ description = '' , $ returnResult = false )
27
+ {
28
+ return $ this ->doEvaluate ($ other , $ description , $ returnResult );
29
+ }
30
+
21
31
public function count (): int
22
32
{
23
33
return $ this ->doCount ();
@@ -51,29 +61,4 @@ protected function matches($other): bool
51
61
{
52
62
return $ this ->doMatches ($ other );
53
63
}
54
-
55
- private function doAdditionalFailureDescription ($ other ): string
56
- {
57
- return '' ;
58
- }
59
-
60
- private function doCount (): int
61
- {
62
- return 1 ;
63
- }
64
-
65
- private function doFailureDescription ($ other ): string
66
- {
67
- return $ this ->exporter ()->export ($ other ).' ' .$ this ->toString ();
68
- }
69
-
70
- private function doMatches ($ other ): bool
71
- {
72
- return false ;
73
- }
74
-
75
- private function doToString (): string
76
- {
77
- return '' ;
78
- }
79
64
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bridge \PhpUnit \Legacy ;
13
+
14
+ /**
15
+ * @internal
16
+ */
17
+ trait ConstraintTraitForV8
18
+ {
19
+ use ConstraintLogicTrait;
20
+
21
+ /**
22
+ * @return bool|null
23
+ */
24
+ public function evaluate ($ other , $ description = '' , $ returnResult = false )
25
+ {
26
+ return $ this ->doEvaluate ($ other , $ description , $ returnResult );
27
+ }
28
+
29
+ public function count (): int
30
+ {
31
+ return $ this ->doCount ();
32
+ }
33
+
34
+ public function toString (): string
35
+ {
36
+ return $ this ->doToString ();
37
+ }
38
+
39
+ protected function additionalFailureDescription ($ other ): string
40
+ {
41
+ return $ this ->doAdditionalFailureDescription ($ other );
42
+ }
43
+
44
+ protected function failureDescription ($ other ): string
45
+ {
46
+ return $ this ->doFailureDescription ($ other );
47
+ }
48
+
49
+ protected function matches ($ other ): bool
50
+ {
51
+ return $ this ->doMatches ($ other );
52
+ }
53
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bridge \PhpUnit \Legacy ;
13
+
14
+ /**
15
+ * @internal
16
+ */
17
+ trait ConstraintTraitForV9
18
+ {
19
+ use ConstraintLogicTrait;
20
+
21
+ public function evaluate ($ other , string $ description = '' , bool $ returnResult = false ): ?bool
22
+ {
23
+ return $ this ->doEvaluate ($ other , $ description , $ returnResult );
24
+ }
25
+
26
+ public function count (): int
27
+ {
28
+ return $ this ->doCount ();
29
+ }
30
+
31
+ public function toString (): string
32
+ {
33
+ return $ this ->doToString ();
34
+ }
35
+
36
+ protected function additionalFailureDescription ($ other ): string
37
+ {
38
+ return $ this ->doAdditionalFailureDescription ($ other );
39
+ }
40
+
41
+ protected function failureDescription ($ other ): string
42
+ {
43
+ return $ this ->doFailureDescription ($ other );
44
+ }
45
+
46
+ protected function matches ($ other ): bool
47
+ {
48
+ return $ this ->doMatches ($ other );
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments