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 compatibility with Twig 3.10
  [Strings][EnglishInflector] Fix incorrect pluralisation of 'Album'
  handle union and intersection types for cascaded validations
  move wiring of the property info extractor to the ObjectNormalizer
  restore deprecated properties
  move Process component dep to require-dev
  Remove calls to `onConsecutiveCalls()`
  fix: remove unwanted type cast
  accept AbstractAsset instances when filtering schemas
  better distinguish URL schemes and windows drive letters
  handle edge cases when constructing constraints with named arguments
  convert empty CSV header names into numeric keys
  • Loading branch information
derrabus committed May 2, 2024
2 parents e02306b + 440675f commit a2fc1bb
Show file tree
Hide file tree
Showing 52 changed files with 547 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testMiddlewareWrapsInTransactionAndFlushes()
{
$this->connection->expects($this->exactly(1))
->method('isTransactionActive')
->will($this->onConsecutiveCalls(true, true, false))
->willReturn(true, true, false)
;

$this->middleware->handle(new Envelope(new \stdClass()), $this->getStackMock());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ public function testVerbosityChanged()
$output
->expects($this->exactly(2))
->method('getVerbosity')
->willReturnOnConsecutiveCalls(
OutputInterface::VERBOSITY_QUIET,
OutputInterface::VERBOSITY_DEBUG
)
->willReturn(OutputInterface::VERBOSITY_QUIET, OutputInterface::VERBOSITY_DEBUG)
;
$handler = new ConsoleHandler($output);
$this->assertFalse($handler->isHandling(RecordFactory::create(Level::Notice)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1900,18 +1900,19 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
$container->setParameter('serializer.default_context', $defaultContext);
}

$arguments = $container->getDefinition('serializer.normalizer.object')->getArguments();
$context = [];

if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) {
$arguments = $container->getDefinition('serializer.normalizer.object')->getArguments();
$context = ($arguments[6] ?? $defaultContext) + ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
$context += ($arguments[6] ?? $defaultContext) + ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
$container->getDefinition('serializer.normalizer.object')->setArgument(5, null);
$container->getDefinition('serializer.normalizer.object')->setArgument(6, $context);
}

if ($config['max_depth_handler'] ?? false) {
$arguments = $container->getDefinition('serializer.normalizer.object')->getArguments();
$context = ($arguments[6] ?? $defaultContext) + ['max_depth_handler' => new Reference($config['max_depth_handler'])];
$container->getDefinition('serializer.normalizer.object')->setArgument(6, $context);
$context += ($arguments[6] ?? $defaultContext) + ['max_depth_handler' => new Reference($config['max_depth_handler'])];
}

$container->getDefinition('serializer.normalizer.object')->setArgument(6, $context);
}

private function registerPropertyInfoConfiguration(ContainerBuilder $container, PhpFileLoader $loader): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
service('property_info')->ignoreOnInvalid(),
service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
null,
null,
service('property_info')->ignoreOnInvalid(),
])
->tag('serializer.normalizer', ['priority' => -1000])

Expand All @@ -139,7 +141,6 @@
service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
null,
[],
service('property_info')->ignoreOnInvalid(),
])

->set('serializer.denormalizer.array', ArrayDenormalizer::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ protected function getLoader()
$loader
->expects($this->exactly(7))
->method('load')
->willReturnOnConsecutiveCalls(
->willReturn(
$this->getCatalogue('fr', [
'foo' => 'foo (FR)',
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Twig\Environment;
use Twig\Loader\ArrayLoader;

class WebProfilerExtensionTest extends TestCase
{
Expand All @@ -23,7 +24,7 @@ class WebProfilerExtensionTest extends TestCase
*/
public function testDumpHeaderIsDisplayed(string $message, array $context, bool $dump1HasHeader, bool $dump2HasHeader)
{
$twigEnvironment = $this->mockTwigEnvironment();
$twigEnvironment = new Environment(new ArrayLoader());
$varCloner = new VarCloner();

$webProfilerExtension = new WebProfilerExtension();
Expand All @@ -44,13 +45,4 @@ public static function provideMessages(): iterable
yield ['Some message {foo}', ['foo' => 'foo', 'bar' => 'bar'], true, false];
yield ['Some message {foo}', ['bar' => 'bar'], false, true];
}

private function mockTwigEnvironment()
{
$twigEnvironment = $this->createMock(Environment::class);

$twigEnvironment->expects($this->any())->method('getCharset')->willReturn('UTF-8');

return $twigEnvironment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Twig\Extension\EscaperExtension;
use Twig\Extension\ProfilerExtension;
use Twig\Profiler\Profile;
use Twig\Runtime\EscaperRuntime;
use Twig\TwigFunction;

/**
Expand Down Expand Up @@ -108,6 +109,12 @@ public function getName(): string

private static function escape(Environment $env, string $s): string
{
// Twig 3.10 and above
if (class_exists(EscaperRuntime::class)) {
return $env->getRuntime(EscaperRuntime::class)->escape($s);
}

// Twig 3.9
if (method_exists(EscaperExtension::class, 'escape')) {
return EscaperExtension::escape($env, $s);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ protected function doClear(string $namespace): bool
}
$this->doDelete($keys);
}
} while ($cursor = (int) $cursor);
} while ($cursor);
}

return $cleared;
Expand Down
16 changes: 9 additions & 7 deletions src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ public function testImportWithFileLocatorDelegation()
$locatorMock = $this->createMock(FileLocatorInterface::class);

$locatorMockForAdditionalLoader = $this->createMock(FileLocatorInterface::class);
$locatorMockForAdditionalLoader->expects($this->any())->method('locate')->will($this->onConsecutiveCalls(
['path/to/file1'], // Default
['path/to/file1', 'path/to/file2'], // First is imported
['path/to/file1', 'path/to/file2'], // Second is imported
['path/to/file1'], // Exception
['path/to/file1', 'path/to/file2'] // Exception
));
$locatorMockForAdditionalLoader->expects($this->any())
->method('locate')
->willReturn(
['path/to/file1'],
['path/to/file1', 'path/to/file2'],
['path/to/file1', 'path/to/file2'],
['path/to/file1'],
['path/to/file1', 'path/to/file2']
);

$fileLoader = new TestFileLoader($locatorMock);
$fileLoader->setSupports(false);
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public function testLoadFile()
}

$mock = $this->createMock(Validator::class);
$mock->expects($this->exactly(2))->method('validate')->will($this->onConsecutiveCalls(false, true));
$mock->expects($this->exactly(2))->method('validate')
->willReturn(false, true);

try {
XmlUtils::loadFile($fixtures.'valid.xml', [$mock, 'validate']);
Expand Down
22 changes: 18 additions & 4 deletions src/Symfony/Component/Dotenv/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,24 @@
#[AsCommand(name: 'debug:dotenv', description: 'List all dotenv files with variables and values')]
final class DebugCommand extends Command
{
public function __construct(
private string $kernelEnvironment,
private string $projectDirectory,
) {
/**
* @deprecated since Symfony 6.1
*/
protected static $defaultName = 'debug:dotenv';

/**
* @deprecated since Symfony 6.1
*/
protected static $defaultDescription = 'List all dotenv files with variables and values';

private string $kernelEnvironment;
private string $projectDirectory;

public function __construct(string $kernelEnvironment, string $projectDirectory)
{
$this->kernelEnvironment = $kernelEnvironment;
$this->projectDirectory = $projectDirectory;

parent::__construct();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Filesystem/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public static function isAbsolute(string $path): bool
}

// Strip scheme
if (false !== $schemeSeparatorPosition = strpos($path, '://')) {
if (false !== ($schemeSeparatorPosition = strpos($path, '://')) && 1 !== $schemeSeparatorPosition) {
$path = substr($path, $schemeSeparatorPosition + 3);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/PathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ public static function provideIsAbsolutePathTests(): \Generator

yield ['C:/css/style.css', true];
yield ['D:/', true];
yield ['C:///windows', true];
yield ['C://test', true];

yield ['E:\\css\\style.css', true];
yield ['F:\\', true];
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Filesystem/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"require": {
"php": ">=8.2",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.8",
"symfony/polyfill-mbstring": "~1.8"
},
"require-dev": {
"symfony/process": "^6.4|^7.0"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SessionListenerTest extends TestCase
public function testSessionCookieOptions(array $phpSessionOptions, array $sessionOptions, array $expectedSessionOptions)
{
$session = $this->createMock(Session::class);
$session->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->method('getUsageIndex')->willReturn(0, 1);
$session->method('getId')->willReturn('123456');
$session->method('getName')->willReturn('PHPSESSID');
$session->method('save');
Expand Down Expand Up @@ -491,7 +491,7 @@ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent()
public function testSessionSaveAndResponseHasSessionCookie()
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session->expects($this->exactly(1))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(1))->method('getUsageIndex')->willReturn(0);
$session->expects($this->exactly(1))->method('getId')->willReturn('123456');
$session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
$session->expects($this->exactly(1))->method('save');
Expand Down Expand Up @@ -644,7 +644,7 @@ public function testSurrogateMainRequestIsPublic()
{
$session = $this->createMock(Session::class);
$session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
$sessionFactory = $this->createMock(SessionFactory::class);
$sessionFactory->expects($this->once())->method('createSession')->willReturn($session);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,17 @@ public function testRenderExceptionIgnoreErrors()

public function testRenderExceptionIgnoreErrorsWithAlt()
{
$strategy = new InlineFragmentRenderer($this->getKernel($this->onConsecutiveCalls(
$this->throwException(new \RuntimeException('foo')),
$this->returnValue(new Response('bar'))
)));
$strategy = new InlineFragmentRenderer($this->getKernel($this->returnCallback(function () {
static $firstCall = true;

if ($firstCall) {
$firstCall = false;

throw new \RuntimeException('foo');
}

return new Response('bar');
})));

$this->assertEquals('bar', $strategy->render('/', Request::create('/'), ['ignore_errors' => true, 'alt' => '/foo'])->getContent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ protected function getCache($request, $response)
if (\is_array($response)) {
$cache->expects($this->any())
->method('handle')
->will($this->onConsecutiveCalls(...$response))
->willReturn(...$response)
;
} else {
$cache->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected function getCache($request, $response)
if (\is_array($response)) {
$cache->expects($this->any())
->method('handle')
->will($this->onConsecutiveCalls(...$response))
->willReturn(...$response)
;
} else {
$cache->expects($this->any())
Expand Down

0 comments on commit a2fc1bb

Please sign in to comment.