Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dbc1db2

Browse filesBrowse files
committed
Merge branch '5.1' into 5.2
* 5.1: Fix merge. Fix CS [Messenger] Test generated SQL [Config] YamlReferenceDumper: No default value required for VariableNode with array example Remove PHPUnit configuration files from components without tests. [DependencyInjection] Fix container linter for union types.
2 parents 2f607de + 7c31fa0 commit dbc1db2
Copy full SHA for dbc1db2

File tree

Expand file treeCollapse file tree

13 files changed

+154
-232
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+154
-232
lines changed

‎.github/patch-types.php

Copy file name to clipboardExpand all lines: .github/patch-types.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/ParseError.php'):
2222
case false !== strpos($file, '/src/Symfony/Component/Debug/Tests/Fixtures/'):
2323
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Compiler/OptionalServiceClass.php'):
24+
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/UnionConstructor.php'):
2425
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php'):
2526
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes_80.php'):
2627
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/uniontype_classes.php'):

‎src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Config\Definition\NodeInterface;
1818
use Symfony\Component\Config\Definition\PrototypedArrayNode;
1919
use Symfony\Component\Config\Definition\ScalarNode;
20+
use Symfony\Component\Config\Definition\VariableNode;
2021
use Symfony\Component\Yaml\Inline;
2122

2223
/**
@@ -95,6 +96,9 @@ private function writeNode(NodeInterface $node, NodeInterface $parentNode = null
9596
} elseif ($node instanceof EnumNode) {
9697
$comments[] = 'One of '.implode('; ', array_map('json_encode', $node->getValues()));
9798
$default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
99+
} elseif (VariableNode::class === \get_class($node) && \is_array($example)) {
100+
// If there is an array example, we are sure we dont need to print a default value
101+
$default = '';
98102
} else {
99103
$default = '~';
100104

‎src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php
+15-14Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,27 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio
153153
/**
154154
* @throws InvalidParameterTypeException When a parameter is not compatible with the declared type
155155
*/
156-
private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix, string $type = null): void
156+
private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix, \ReflectionType $reflectionType = null): void
157157
{
158-
if (null === $type) {
159-
$type = $parameter->getType();
158+
$reflectionType = $reflectionType ?? $parameter->getType();
160159

161-
if ($type instanceof \ReflectionUnionType) {
162-
foreach ($type->getTypes() as $type) {
163-
try {
164-
$this->checkType($checkedDefinition, $value, $parameter, $envPlaceholderUniquePrefix, $type);
160+
if ($reflectionType instanceof \ReflectionUnionType) {
161+
foreach ($reflectionType->getTypes() as $t) {
162+
try {
163+
$this->checkType($checkedDefinition, $value, $parameter, $envPlaceholderUniquePrefix, $t);
165164

166-
return;
167-
} catch (InvalidParameterTypeException $e) {
168-
}
165+
return;
166+
} catch (InvalidParameterTypeException $e) {
169167
}
170-
171-
throw new InvalidParameterTypeException($this->currentId, $e->getCode(), $parameter);
172168
}
173169

174-
$type = $type->getName();
170+
throw new InvalidParameterTypeException($this->currentId, $e->getCode(), $parameter);
175171
}
172+
if (!$reflectionType instanceof \ReflectionNamedType) {
173+
return;
174+
}
175+
176+
$type = $reflectionType->getName();
176177

177178
if ($value instanceof Reference) {
178179
if (!$this->container->has($value = (string) $value)) {
@@ -285,7 +286,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
285286

286287
$checkFunction = sprintf('is_%s', $type);
287288

288-
if (!$parameter->getType()->isBuiltin() || !$checkFunction($value)) {
289+
if (!$reflectionType->isBuiltin() || !$checkFunction($value)) {
289290
throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? $class : get_debug_type($value), $parameter);
290291
}
291292
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php
+69Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgumentNotNull;
2727
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo;
2828
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
29+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor;
2930
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo;
3031
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Wobble;
3132
use Symfony\Component\ExpressionLanguage\Expression;
@@ -803,4 +804,72 @@ public function testProcessResolveParameters()
803804

804805
putenv('ARRAY=');
805806
}
807+
808+
/**
809+
* @requires PHP 8
810+
*/
811+
public function testUnionTypePassesWithReference()
812+
{
813+
$container = new ContainerBuilder();
814+
815+
$container->register('foo', Foo::class);
816+
$container->register('union', UnionConstructor::class)
817+
->setArguments([new Reference('foo')]);
818+
819+
(new CheckTypeDeclarationsPass(true))->process($container);
820+
821+
$this->addToAssertionCount(1);
822+
}
823+
824+
/**
825+
* @requires PHP 8
826+
*/
827+
public function testUnionTypePassesWithBuiltin()
828+
{
829+
$container = new ContainerBuilder();
830+
831+
$container->register('union', UnionConstructor::class)
832+
->setArguments([42]);
833+
834+
(new CheckTypeDeclarationsPass(true))->process($container);
835+
836+
$this->addToAssertionCount(1);
837+
}
838+
839+
/**
840+
* @requires PHP 8
841+
*/
842+
public function testUnionTypeFailsWithReference()
843+
{
844+
$container = new ContainerBuilder();
845+
846+
$container->register('waldo', Waldo::class);
847+
$container->register('union', UnionConstructor::class)
848+
->setArguments([new Reference('waldo')]);
849+
850+
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
851+
$this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo" passed.');
852+
853+
(new CheckTypeDeclarationsPass(true))->process($container);
854+
855+
$this->addToAssertionCount(1);
856+
}
857+
858+
/**
859+
* @requires PHP 8
860+
*/
861+
public function testUnionTypeFailsWithBuiltin()
862+
{
863+
$container = new ContainerBuilder();
864+
865+
$container->register('union', UnionConstructor::class)
866+
->setArguments([[1, 2, 3]]);
867+
868+
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
869+
$this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "array" passed.');
870+
871+
(new CheckTypeDeclarationsPass(true))->process($container);
872+
873+
$this->addToAssertionCount(1);
874+
}
806875
}
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;
4+
5+
class UnionConstructor
6+
{
7+
public function __construct(Foo|int $arg)
8+
{
9+
}
10+
}

‎src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php
+55-1Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;
1313

1414
use Doctrine\DBAL\Abstraction\Result as AbstractionResult;
15+
use Doctrine\DBAL\Connection as DBALConnection;
1516
use Doctrine\DBAL\DBALException;
17+
use Doctrine\DBAL\Driver\Result as DriverResult;
18+
use Doctrine\DBAL\Driver\ResultStatement;
1619
use Doctrine\DBAL\Exception;
1720
use Doctrine\DBAL\Platforms\AbstractPlatform;
21+
use Doctrine\DBAL\Platforms\MySQL57Platform;
22+
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
1823
use Doctrine\DBAL\Query\QueryBuilder;
1924
use Doctrine\DBAL\Result;
2025
use Doctrine\DBAL\Schema\AbstractSchemaManager;
@@ -118,7 +123,7 @@ public function testItThrowsATransportExceptionIfItCannotRejectMessage()
118123

119124
private function getDBALConnectionMock()
120125
{
121-
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
126+
$driverConnection = $this->createMock(DBALConnection::class);
122127
$platform = $this->createMock(AbstractPlatform::class);
123128
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');
124129
$configuration = $this->createMock(\Doctrine\DBAL\Configuration::class);
@@ -349,6 +354,55 @@ public function testFindAll()
349354
$this->assertEquals(['type' => DummyMessage::class], $doctrineEnvelopes[1]['headers']);
350355
}
351356

357+
/**
358+
* @dataProvider providePlatformSql
359+
*/
360+
public function testGeneratedSql(AbstractPlatform $platform, string $expectedSql)
361+
{
362+
$driverConnection = $this->createMock(DBALConnection::class);
363+
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
364+
$driverConnection->method('createQueryBuilder')->willReturnCallback(function () use ($driverConnection) {
365+
return new QueryBuilder($driverConnection);
366+
});
367+
368+
if (interface_exists(DriverResult::class)) {
369+
$result = $this->createMock(DriverResult::class);
370+
$result->method('fetchAssociative')->willReturn(false);
371+
372+
if (class_exists(Result::class)) {
373+
$result = new Result($result, $driverConnection);
374+
}
375+
} else {
376+
$result = $this->createMock(ResultStatement::class);
377+
$result->method('fetch')->willReturn(false);
378+
}
379+
380+
$driverConnection->expects($this->once())->method('beginTransaction');
381+
$driverConnection
382+
->expects($this->once())
383+
->method('executeQuery')
384+
->with($expectedSql)
385+
->willReturn($result)
386+
;
387+
$driverConnection->expects($this->once())->method('commit');
388+
389+
$connection = new Connection([], $driverConnection);
390+
$connection->get();
391+
}
392+
393+
public function providePlatformSql(): iterable
394+
{
395+
yield 'MySQL' => [
396+
new MySQL57Platform(),
397+
'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC LIMIT 1 FOR UPDATE',
398+
];
399+
400+
yield 'SQL Server' => [
401+
new SQLServer2012Platform(),
402+
'SELECT m.* FROM messenger_messages m WITH (UPDLOCK, ROWLOCK) WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY ',
403+
];
404+
}
405+
352406
public function testConfigureSchema()
353407
{
354408
$driverConnection = $this->getDBALConnectionMock();

‎src/Symfony/Component/Notifier/Bridge/Firebase/phpunit.xml.dist

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Firebase/phpunit.xml.dist
-31Lines changed: 0 additions & 31 deletions
This file was deleted.

‎src/Symfony/Component/Notifier/Bridge/Mattermost/phpunit.xml.dist

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Mattermost/phpunit.xml.dist
-31Lines changed: 0 additions & 31 deletions
This file was deleted.

‎src/Symfony/Component/Notifier/Bridge/Nexmo/phpunit.xml.dist

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Nexmo/phpunit.xml.dist
-31Lines changed: 0 additions & 31 deletions
This file was deleted.

‎src/Symfony/Component/Notifier/Bridge/OvhCloud/phpunit.xml.dist

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/OvhCloud/phpunit.xml.dist
-31Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.