Skip to content

Commit 063ce8a

Browse files
Merge branch '4.4' into 5.1
* 4.4: fix merge Remove branch-version (keep them for contracts only) [HttpClient] relax auth bearer format requirements [PHPUnitBridge] Silence errors from mkdir() [DependencyInjection] Preload classes with union types correctly. [Serializer] fix decoding float XML attributes starting with 0 add missing dutch translations Support PHPUnit 8 and PHPUnit 9 in constraint compatibility trait Add expectDeprecation, expectNotice, expectWarning, and expectError to TestCase polyfill Add missing exporter function for PHPUnit 7 [Validator] Add missing romanian translations [Cache] Use correct expiry in ChainAdapter do not translate null placeholders or titles
2 parents 76dbcb2 + e283912 commit 063ce8a

9 files changed

+320
-31
lines changed

ConstraintTrait.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

Legacy/ConstraintLogicTrait.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
}

Legacy/ConstraintTraitForV6.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
*/
1919
trait 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();

Legacy/ConstraintTraitForV7.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@
1111

1212
namespace Symfony\Bridge\PhpUnit\Legacy;
1313

14+
use SebastianBergmann\Exporter\Exporter;
15+
1416
/**
1517
* @internal
1618
*/
1719
trait ConstraintTraitForV7
1820
{
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+
1931
public function count(): int
2032
{
2133
return $this->doCount();
@@ -31,38 +43,22 @@ protected function additionalFailureDescription($other): string
3143
return $this->doAdditionalFailureDescription($other);
3244
}
3345

34-
protected function failureDescription($other): string
35-
{
36-
return $this->doFailureDescription($other);
37-
}
38-
39-
protected function matches($other): bool
40-
{
41-
return $this->doMatches($other);
42-
}
43-
44-
private function doAdditionalFailureDescription($other): string
45-
{
46-
return '';
47-
}
48-
49-
private function doCount(): int
46+
protected function exporter(): Exporter
5047
{
51-
return 1;
52-
}
48+
if (null !== $this->exporter) {
49+
$this->exporter = new Exporter();
50+
}
5351

54-
private function doFailureDescription($other): string
55-
{
56-
return $this->exporter()->export($other).' '.$this->toString();
52+
return $this->exporter;
5753
}
5854

59-
private function doMatches($other): bool
55+
protected function failureDescription($other): string
6056
{
61-
return false;
57+
return $this->doFailureDescription($other);
6258
}
6359

64-
private function doToString(): string
60+
protected function matches($other): bool
6561
{
66-
return '';
62+
return $this->doMatches($other);
6763
}
6864
}

Legacy/ConstraintTraitForV8.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

Legacy/ConstraintTraitForV9.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

0 commit comments

Comments
 (0)