Skip to content

Commit f3a180b

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: fix typo in PULL_REQUEST_TEMPLATE.md Allow to disable lock without defining a resource [HttpFoundation] Compare cookie with null value as empty string in ResponseCookieValueSame Fix deprecation notice when date argument is not nullable and null value is provided
2 parents 4d4c411 + db1cf2b commit f3a180b

File tree

7 files changed

+60
-6
lines changed

7 files changed

+60
-6
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| Bug fix? | yes/no
55
| New feature? | yes/no <!-- please update src/**/CHANGELOG.md files -->
66
| Deprecations? | yes/no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
7-
| Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
7+
| Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
88
| License | MIT
99
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
1010
<!--

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,12 +1270,15 @@ private function addLockSection(ArrayNodeDefinition $rootNode, callable $enableI
12701270
})
12711271
->end()
12721272
->addDefaultsIfNotSet()
1273+
->validate()
1274+
->ifTrue(static function (array $config) { return $config['enabled'] && !$config['resources']; })
1275+
->thenInvalid('At least one resource must be defined.')
1276+
->end()
12731277
->fixXmlConfig('resource')
12741278
->children()
12751279
->arrayNode('resources')
12761280
->normalizeKeys(false)
12771281
->useAttributeAsKey('name')
1278-
->requiresAtLeastOneElement()
12791282
->defaultValue(['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']])
12801283
->beforeNormalization()
12811284
->ifString()->then(function ($v) { return ['default' => $v]; })

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,31 @@ public function testItErrorsWhenDefaultBusDoesNotExist()
427427
]);
428428
}
429429

430+
public function testLockCanBeDisabled()
431+
{
432+
$processor = new Processor();
433+
$configuration = new Configuration(true);
434+
435+
$config = $processor->processConfiguration($configuration, [
436+
['lock' => ['enabled' => false]],
437+
]);
438+
439+
$this->assertFalse($config['lock']['enabled']);
440+
}
441+
442+
public function testEnabledLockNeedsResources()
443+
{
444+
$processor = new Processor();
445+
$configuration = new Configuration(true);
446+
447+
$this->expectException(InvalidConfigurationException::class);
448+
$this->expectExceptionMessage('Invalid configuration for path "framework.lock": At least one resource must be defined.');
449+
450+
$processor->processConfiguration($configuration, [
451+
['lock' => ['enabled' => true]],
452+
]);
453+
}
454+
430455
protected static function getBundleDefaultConfig()
431456
{
432457
return [

src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseCookieValueSame.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function matches($response): bool
5454
return false;
5555
}
5656

57-
return $this->value === $cookie->getValue();
57+
return $this->value === (string) $cookie->getValue();
5858
}
5959

6060
/**

src/Symfony/Component/HttpFoundation/Tests/Test/Constraint/ResponseCookieValueSameTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ public function testConstraint()
4141

4242
$this->fail();
4343
}
44+
45+
public function testCookieWithNullValueIsComparedAsEmptyString()
46+
{
47+
$response = new Response();
48+
$response->headers->setCookie(Cookie::create('foo', null, 0, '/path'));
49+
50+
$this->assertTrue((new ResponseCookieValueSame('foo', '', '/path'))->evaluate($response, '', true));
51+
}
4452
}

src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/DateTimeValueResolver.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
6060
$format = $attribute->format;
6161
}
6262

63-
$date = false;
64-
6563
if (null !== $format) {
6664
$date = $class::createFromFormat($format, $value);
6765

@@ -73,7 +71,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
7371
$value = '@'.$value;
7472
}
7573
try {
76-
$date = new $class($value);
74+
$date = new $class($value ?? 'now');
7775
} catch (\Exception) {
7876
$date = false;
7977
}

src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/DateTimeValueResolverTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ public function testNullableWithEmptyAttribute()
119119
$this->assertNull($results[0]);
120120
}
121121

122+
/**
123+
* @dataProvider getTimeZones
124+
*/
125+
public function testNow(string $timezone)
126+
{
127+
date_default_timezone_set($timezone);
128+
$resolver = new DateTimeValueResolver();
129+
130+
$argument = new ArgumentMetadata('dummy', \DateTime::class, false, false, null, false);
131+
$request = self::requestWithAttributes(['dummy' => null]);
132+
133+
/** @var \Generator $results */
134+
$results = $resolver->resolve($request, $argument);
135+
$results = iterator_to_array($results);
136+
137+
$this->assertCount(1, $results);
138+
$this->assertEquals('0', $results[0]->diff(new \DateTimeImmutable())->format('%s'));
139+
$this->assertSame($timezone, $results[0]->getTimezone()->getName(), 'Default timezone');
140+
}
141+
122142
public function testPreviouslyConvertedAttribute()
123143
{
124144
$resolver = new DateTimeValueResolver();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy