10000 Merge branch '5.3' into 5.4 · symfony/symfony@d5d0cec · GitHub
[go: up one dir, main page]

Skip to content

Commit d5d0cec

Browse files
Merge branch '5.3' into 5.4
* 5.3: Try making tests a bit less transient Fix CI on macos-11 [Serializer] Fix denormalizing custom class in UidNormalizer [Config] In XmlUtils, avoid converting from octal every string starting with a 0 Make RateLimiter resilient to timeShifting
2 parents 74a6936 + 9b1dcc5 commit d5d0cec

File tree

16 files changed

+106
-41
lines changed

16 files changed

+106
-41
lines changed

.appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ test_script:
6161
- copy /Y c:\php\php.ini-min c:\php\php.ini
6262
- IF %APPVEYOR_REPO_BRANCH:~-2% neq .x (rm -Rf src\Symfony\Bridge\PhpUnit)
6363
- mv src\Symfony\Component\HttpClient\phpunit.xml.dist src\Symfony\Component\HttpClient\phpunit.xml
64-
- php phpunit src\Symfony --exclude-group tty,benchmark,intl-data || SET X=!errorlevel!
64+
- php phpunit src\Symfony --exclude-group tty,benchmark,intl-data,network,transient-on-windows || SET X=!errorlevel!
6565
- php phpunit src\Symfony\Component\HttpClient || SET X=!errorlevel!
6666
- copy /Y c:\php\php.ini-max c:\php\php.ini
67-
- php phpunit src\Symfony --exclude-group tty,benchmark,intl-data || SET X=!errorlevel!
67+
- php phpunit src\Symfony --exclude-group tty,benchmark,intl-data,network,transient-on-windows || SET X=!errorlevel!
6868
- php phpunit src\Symfony\Component\HttpClient || SET X=!errorlevel!
6969
- exit %X%

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ jobs:
148148
echo "::endgroup::"
149149
150150
- name: Patch return types
151-
if: "matrix.php == '8.1' && ! matrix.mode && matrix.os == 'ubuntu-20.04'"
151+
if: "matrix.php == '8.1' && ! matrix.mode && matrix.os != 'macos-11'"
152152
run: |
153153
sed -i 's/"\*\*\/Tests\/"//' composer.json
154154
git add .
@@ -227,7 +227,7 @@ jobs:
227227
[[ ! $X ]] || (exit 1)
228228
229229
- name: Run tests with SIGCHLD enabled PHP
230-
if: "matrix.php == '7.2' && ! matrix.mode"
230+
if: "matrix.php == '7.2' && ! matrix.mode && matrix.os != 'macos-11'"
231231
run: |
232232
mkdir build
233233
cd build

src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public function getDataForPhpize(): array
169169
[1, '1'],
170170
[-1, '-1'],
171171
[0777, '0777'],
172+
[-511, '-0777'],
173+
['0877', '0877'],
172174
[255, '0xFF'],
173175
[100.0, '1e2'],
174176
[-120.0, '-1.2E2'],

src/Symfony/Component/Config/Util/XmlUtils.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,11 @@ public static function phpize($value)
236236
case 'null' === $lowercaseValue:
237237
return null;
238238
case ctype_digit($value):
239-
$raw = $value;
240-
$cast = (int) $value;
241-
242-
return '0' == $value[0] ? octdec($value) : (($raw === (string) $cast) ? $cast : $raw);
243239
case isset($value[1]) && '-' === $value[0] && ctype_digit(substr($value, 1)):
244240
10000 $raw = $value;
245241
$cast = (int) $value;
246242

247-
return '0' == $value[1] ? octdec($value) : (($raw === (string) $cast) ? $cast : $raw);
243+
return self::isOctal($value) ? \intval($value, 8) : (($raw === (string) $cast) ? $cast : $raw);
248244
case 'true' === $lowercaseValue:
249245
return true;
250246
case 'false' === $lowercaseValue:
@@ -281,4 +277,13 @@ protected static function getXmlErrors(bool $internalErrors)
281277

282278
return $errors;
283279
}
280+
281+
private static function isOctal(string $str): bool
282+
{
283+
if ('-' === $str[0]) {
284+
$str = substr($str, 1);
285+
}
286+
287+
return $str === '0'.decoct(\intval($str, 8));
288+
}
284289
}

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,9 @@ public function testRenderExceptionLineBreaks()
883883
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_linebreaks.txt', $tester->getDisplay(true), '->renderException() keep multiple line breaks');
884884
}
885885

886+
/**
887+
* @group transient-on-windows
888+
*/
886889
public function testRenderAnonymousException()
887890
{
888891
$application = new Application();
@@ -906,6 +909,9 @@ public function testRenderAnonymousException()
906909
$this->assertStringContainsString('Dummy type "class@anonymous" is invalid.', $tester->getDisplay(true));
907910
}
908911

912+
/**
913+
* @group transient-on-windows
914+
*/
909915
public function testRenderExceptionStackTraceContainsRootException()
910916
{
911917
$application = new Application();

src/Symfony/Component/Finder/Tests/Iterator/RecursiveDirectoryIteratorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class RecursiveDirectoryIteratorTest extends IteratorTestCase
2121
public function testRewindOnFtp()
2222
{
2323
try {
24-
$i = new RecursiveDirectoryIterator('ftp://speedtest.tele2.net/', \RecursiveDirectoryIterator::SKIP_DOTS);
24+
$i = new RecursiveDirectoryIterator('ftp://speedtest:speedtest@ftp.otenet.gr/', \RecursiveDirectoryIterator::SKIP_DOTS);
2525
} catch (\UnexpectedValueException $e) {
2626
$this->markTestSkipped('Unsupported stream "ftp".');
2727
}
@@ -37,14 +37,14 @@ public function testRewindOnFtp()
3737
public function testSeekOnFtp()
3838
{
3939
try {
40-
$i = new RecursiveDirectoryIterator('ftp://speedtest.tele2.net/', \RecursiveDirectoryIterator::SKIP_DOTS);
40+
$i = new RecursiveDirectoryIterator('ftp://speedtest:speedtest@ftp.otenet.gr/', \RecursiveDirectoryIterator::SKIP_DOTS);
4141
} catch (\UnexpectedValueException $e) {
4242
$this->markTestSkipped('Unsupported stream "ftp".');
4343
}
4444

4545
$contains = [
46-
'ftp://speedtest.tele2.net'.\DIRECTORY_SEPARATOR.'1000GB.zip',
47-
'ftp://speedtest.tele2.net'.\DIRECTORY_SEPARATOR.'100GB.zip',
46+
'ftp://speedtest:speedtest@ftp.otenet.gr'.\DIRECTORY_SEPARATOR.'test100Mb.db',
47+
'ftp://speedtest:speedtest@ftp.otenet.gr'.\DIRECTORY_SEPARATOR.'test100k.db',
4848
];
4949
$actual = [];
5050

src/Symfony/Component/Lock/Tests/Store/PdoDbalStoreTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function tearDownAfterClass(): void
5050
*/
5151
protected function getClockDelay()
5252
{
53-
return 1000000;
53+
return 1500000;
5454
}
5555

5656
/**

src/Symfony/Component/RateLimiter/Policy/FixedWindowLimiter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function reserve(int $tokens = 1, float $maxTime = null): Reservation
6464
$now = microtime(true);
6565
$availableTokens = $window->getAvailableTokens($now);
6666
if ($availableTokens >= $tokens) {
67-
$window->add($tokens);
67+
$window->add($tokens, $now);
6868

6969
$reservation = new Reservation($now, new RateLimit($window->getAvailableTokens($now), \DateTimeImmutable::createFromFormat('U', floor($now)), true, $this->limit));
7070
} else {
@@ -75,7 +75,7 @@ public function reserve(int $tokens = 1, float $maxTime = null): Reservation
7575
throw new MaxWaitDurationExceededException(sprintf('The rate limiter wait time ("%d" seconds) is longer than the provided maximum time ("%d" seconds).', $waitDuration, $maxTime), new RateLimit($window->getAvailableTokens($now), \DateTimeImmutable::createFromFormat('U', floor($now + $waitDuration)), false, $this->limit));
7676
}
7777

78-
$window->add($tokens);
78+
$window->add($tokens, $now);
7979

8080
$reservation = new Reservation($now + $waitDuration, new RateLimit($window->getAvailableTokens($now), \DateTimeImmutable::createFromFormat('U', floor($now + $waitDuration)), false, $this->limit));
8181
}

src/Symfony/Component/RateLimiter/Policy/TokenBucket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function setTokens(int $tokens): void
8181

8282
public function getAvailableTokens(float $now): int
8383
{
84-
$elapsed = $now - $this->timer;
84+
$elapsed = max(0, $now - $this->timer);
8585

8686
return min($this->burstSize, $this->tokens + $this->rate->calculateNewTokensDuringInterval($elapsed));
8787
}

src/Symfony/Component/RateLimiter/Policy/TokenBucketLimiter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public function reserve(int $tokens = 1, float $maxTime = null): Reservation
8686

8787
// at $now + $waitDuration all tokens will be reserved for this process,
8888
// so no tokens are left for other processes.
89-
$bucket->setTokens(0);
90-
$bucket->setTimer($now + $waitDuration);
89+
$bucket->setTokens($availableTokens - $tokens);
90+
$bucket->setTimer($now);
9191

92-
$reservation = new Reservation($bucket->getTimer(), new RateLimit(0, \DateTimeImmutable::createFromFormat('U', floor($now + $waitDuration)), false, $this->maxBurst));
92+
$reservation = new Reservation($now + $waitDuration, new RateLimit(0, \DateTimeImmutable::createFromFormat('U', floor($now + $waitDuration)), false, $this->maxBurst));
9393
}
9494

9595
$this->storage->save($bucket);

0 commit comments

Comments
 (0)
0