Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  Fix CI
  Bump ext-redis in CI on PHP >= 8.4
  Adjust pretty name of closures on PHP 8.4
  implement NodeVisitorInterface instead of extending AbstractNodeVisitor
  sync .github/expected-missing-return-types.diff
  skip test assertions that are no longer valid with PHP >= 8.2.18/8.3.5
  • Loading branch information
nicolas-grekas committed Apr 16, 2024
2 parents 39a5fdc + f09249c commit 9fd64b8
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
coverage: "none"
ini-values: date.timezone=UTC,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
php-version: "${{ matrix.php }}"
extensions: "${{ env.extensions }}"
extensions: "${{ matrix.extensions || env.extensions }}"
tools: flex

- name: Configure environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
use Twig\Node\ModuleNode;
use Twig\Node\Node;
use Twig\Node\SetNode;
use Twig\NodeVisitor\AbstractNodeVisitor;
use Twig\NodeVisitor\NodeVisitorInterface;

/**
* @author Fabien Potencier <fabien@symfony.com>
*/
final class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
final class TranslationDefaultDomainNodeVisitor implements NodeVisitorInterface
{
private Scope $scope;

Expand All @@ -37,7 +37,7 @@ public function __construct()
$this->scope = new Scope();
}

protected function doEnterNode(Node $node, Environment $env): Node
public function enterNode(Node $node, Environment $env): Node
{
if ($node instanceof BlockNode || $node instanceof ModuleNode) {
$this->scope = $this->scope->enter();
Expand Down Expand Up @@ -83,7 +83,7 @@ protected function doEnterNode(Node $node, Environment $env): Node
return $node;
}

protected function doLeaveNode(Node $node, Environment $env): ?Node
public function leaveNode(Node $node, Environment $env): ?Node
{
if ($node instanceof TransDefaultDomainNode) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Node;
use Twig\NodeVisitor\AbstractNodeVisitor;
use Twig\NodeVisitor\NodeVisitorInterface;

/**
* TranslationNodeVisitor extracts translation messages.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class TranslationNodeVisitor extends AbstractNodeVisitor
final class TranslationNodeVisitor implements NodeVisitorInterface
{
public const UNDEFINED_DOMAIN = '_undefined';

Expand All @@ -49,7 +49,7 @@ public function getMessages(): array
return $this->messages;
}

protected function doEnterNode(Node $node, Environment $env): Node
public function enterNode(Node $node, Environment $env): Node
{
if (!$this->enabled) {
return $node;
Expand Down Expand Up @@ -98,7 +98,7 @@ protected function doEnterNode(Node $node, Environment $env): Node
return $node;
}

protected function doLeaveNode(Node $node, Environment $env): ?Node
public function leaveNode(Node $node, Environment $env): ?Node
{
return $node;
}
Expand Down
12 changes: 9 additions & 3 deletions src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public function testCreateConnection(string $dsn, string $expectedClass)
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
}

$mock = self::getObjectForTrait(RedisTrait::class);
$mock = new class () {
use RedisTrait;
};
$connection = $mock::createConnection($dsn);

self::assertInstanceOf($expectedClass, $connection);
Expand All @@ -43,7 +45,9 @@ public function testUrlDecodeParameters()
self::markTestSkipped('REDIS_AUTHENTICATED_HOST env var is not defined.');
}

$mock = self::getObjectForTrait(RedisTrait::class);
$mock = new class () {
use RedisTrait;
};
$connection = $mock::createConnection('redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST'));

self::assertInstanceOf(\Redis::class, $connection);
Expand Down Expand Up @@ -100,7 +104,9 @@ public function testPconnectSelectsCorrectDatabase()
}

try {
$mock = self::getObjectForTrait(RedisTrait::class);
$mock = new class () {
use RedisTrait;
};

$dsn = 'redis://'.getenv('REDIS_HOST');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function testCallErrorExceptionInfo()
$this->assertSame('Undefined variable $foo', $e->getMessage());
$this->assertSame(__FILE__, $e->getFile());
$this->assertSame(0, $e->getCode());
$this->assertSame('Symfony\Component\ErrorHandler\{closure}', $trace[0]['function']);
$this->assertStringMatchesFormat('%A{closure%A}', $trace[0]['function']);
$this->assertSame(ErrorHandler::class, $trace[0]['class']);
$this->assertSame('triggerNotice', $trace[1]['function']);
$this->assertSame(__CLASS__, $trace[1]['class']);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ public function testCopyForOriginUrlsAndExistingLocalFileDefaultsToCopy()
}

$finder = new PhpExecutableFinder();
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:8057']));
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', 'localhost:8057']));
$process->setWorkingDirectory(__DIR__.'/Fixtures/web');

$process->start();

do {
usleep(50000);
} while (!@fopen('http://127.0.0.1:8057', 'r'));
} while (!@fopen('http://localhost:8057', 'r'));

try {
$sourceFilePath = 'http://localhost:8057/logo_symfony_header.png';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static function provideControllerCallables(): array
'Closure',
fn () => 'foo',
[
'class' => __NAMESPACE__.'\{closure}',
'class' => \PHP_VERSION_ID >= 80400 ? sprintf('{closure:%s():%d}', __METHOD__, __LINE__ - 2) : __NAMESPACE__.'\{closure}',
'method' => null,
'file' => __FILE__,
'line' => __LINE__ - 5,
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Mime/Tests/Part/DataPartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ public function testFromPathWithUrl()
}

$finder = new PhpExecutableFinder();
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:8057']));
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', 'localhost:8057']));
$process->setWorkingDirectory(__DIR__.'/../Fixtures/web');
$process->start();

try {
do {
usleep(50000);
} while (!@fopen('http://127.0.0.1:8057', 'r'));
} while (!@fopen('http://localhost:8057', 'r'));
$p = DataPart::fromPath($file = 'http://localhost:8057/logo_symfony_header.png');
$content = file_get_contents($file);
$this->assertEquals($content, $p->getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public function testBcryptWithNulByte()
$hasher = new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT);
$plainPassword = "a\0b";

$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword));
if (\PHP_VERSION_ID < 80218 || \PHP_VERSION_ID >= 80300 && \PHP_VERSION_ID < 80305) {
// password_hash() does not accept passwords containing NUL bytes since PHP 8.2.18 and 8.3.5
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword));
}

$this->assertTrue($hasher->verify($hasher->hash($plainPassword), $plainPassword));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ public function testBcryptWithNulByte()
$hasher = new SodiumPasswordHasher(null, null);
$plainPassword = "a\0b";

$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword));
if (\PHP_VERSION_ID < 80218 || \PHP_VERSION_ID >= 80300 && \PHP_VERSION_ID < 80305) {
// password_hash() does not accept passwords containing NUL bytes since PHP 8.2.18 and 8.3.5
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword));
}

$this->assertTrue($hasher->verify((new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT))->hash($plainPassword), $plainPassword));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ protected function getGroups(array $context): array
/**
* Is this attribute allowed?
*/
protected function isAllowedAttribute(object|string $classOrObject, string $attribute, ?string $format = null, array $context = []): bool
protected function isAllowedAttribute(object|string $classOrObject, string $attribute, ?string $format = null, array $context = [])
{
$ignoredAttributes = $context[self::IGNORED_ATTRIBUTES] ?? $this->defaultContext[self::IGNORED_ATTRIBUTES];
if (\in_array($attribute, $ignoredAttributes, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected function setAttributeValue(object $object, string $attribute, mixed $v
}
}

protected function isAllowedAttribute($classOrObject, string $attribute, ?string $format = null, array $context = []): bool
protected function isAllowedAttribute($classOrObject, string $attribute, ?string $format = null, array $context = [])
{
if (!parent::isAllowedAttribute($classOrObject, $attribute, $format, $context)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected function getAllowedAttributes(string|object $classOrObject, array $con
return $allowedAttributes;
}

protected function isAllowedAttribute($classOrObject, string $attribute, ?string $format = null, array $context = []): bool
protected function isAllowedAttribute($classOrObject, string $attribute, ?string $format = null, array $context = [])
{
if (!parent::isAllowedAttribute($classOrObject, $attribute, $format, $context)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/Tests/LazyStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testReturnTypeError()
$s = LazyString::fromCallable(fn () => []);

$this->expectException(\TypeError::class);
$this->expectExceptionMessage('Return value of '.__NAMESPACE__.'\{closure}() passed to '.LazyString::class.'::fromCallable() must be of the type string, array returned.');
$this->expectExceptionMessageMatches('{^Return value of .*\{closure.*\}\(\) passed to '.preg_quote(LazyString::class).'::fromCallable\(\) must be of the type string, array returned\.$}');

(string) $s;
}
Expand Down

0 comments on commit 9fd64b8

Please sign in to comment.