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
2020 {
2121 use Legacy \ConstraintTraitForV6;
2222 }
23- } else {
23+ } elseif ( $ r -> getProperty ( ' exporter ' )-> isProtected ()) {
2424 trait ConstraintTrait
2525 {
2626 use Legacy \ConstraintTraitForV7;
2727 }
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+ }
2838}
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 1818 */
1919trait ConstraintTraitForV6
2020{
21+ /**
22+ * @return bool|null
23+ */
24+ public function evaluate ($ other , $ description = '' , $ returnResult = false )
25+ {
26+ return $ this ->doEvaluate ($ other , $ description , $ returnResult );
27+ }
28+
2129 /**
2230 * @return int
2331 */
@@ -86,6 +94,25 @@ private function doCount()
8694 return 1 ;
8795 }
8896
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+
89116 private function doFailureDescription ($ other )
90117 {
91118 return $ this ->exporter ()->export ($ other ).' ' .$ this ->toString ();
Original file line number Diff line number Diff line change 1616 */
1717trait ConstraintTraitForV7
1818{
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+
1929 public function count (): int
2030 {
2131 return $ this ->doCount ();
@@ -40,29 +50,4 @@ protected function matches($other): bool
4050 {
4151 return $ this ->doMatches ($ other );
4252 }
43-
44- private function doAdditionalFailureDescription ($ other ): string
45- {
46- return '' ;
47- }
48-
49- private function doCount (): int
50- {
51- return 1 ;
52- }
53-
54- private function doFailureDescription ($ other ): string
55- {
56- return $ this ->exporter ()->export ($ other ).' ' .$ this ->toString ();
57- }
58-
59- private function doMatches ($ other ): bool
60- {
61- return false ;
62- }
63-
64- private function doToString (): string
65- {
66- return '' ;
67- }
6853}
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