Skip to content

Commit 7adba28

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: [PropertyInfo] Update DoctrineExtractor for new DBAL 4 BIGINT type Update security.nl.xlf [Validator] IBAN Check digits should always between 2 and 98 [Security] Populate translations for trans-unit 20 add missing plural translation messages filter out empty HTTP header parts [String] Fix folded in compat mode Remove calls to `getMockForAbstractClass()` [ErrorHandler] Do not call xdebug_get_function_stack() with xdebug >= 3.0 when not in develop mode [Serializer] Fix type for missing property add test for JSON response with null as content [Filesystem] Fix dumpFile `stat failed` error hitting custom handler Remove calls to `TestCase::iniSet()` and calls to deprecated methods of `MockBuilder` [PhpUnitBridge] Fix `DeprecationErrorHandler` with PhpUnit 10
2 parents e4bd593 + 6284bb5 commit 7adba28

File tree

111 files changed

+682
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+682
-180
lines changed

.github/workflows/integration-tests.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ jobs:
192192
./phpunit install
193193
echo "::endgroup::"
194194
195+
- name: Check for changes in translation files
196+
id: changed-translation-files
197+
run: |
198+
echo 'changed='$((git diff --quiet HEAD~1 HEAD -- 'src/**/Resources/translations/*.xlf' || (echo 'true' && exit 1)) && echo 'false') >> $GITHUB_OUTPUT
199+
200+
- name: Check Translation Status
201+
if: steps.changed-translation-files.outputs.changed == 'true'
202+
run: |
203+
php src/Symfony/Component/Translation/Resources/bin/translation-status.php -v
204+
php .github/sync-translations.php
205+
git diff --exit-code src/ || (echo '::error::Run "php .github/sync-translations.php" to fix XLIFF files.' && exit 1)
206+
195207
- name: Run tests
196208
run: ./phpunit --group integration -v
197209
env:
@@ -216,15 +228,3 @@ jobs:
216228
# docker run --rm -e COMPOSER_ROOT_VERSION -v $(pwd):/app -v $(which composer):/usr/local/bin/composer -v $(which vulcain):/usr/local/bin/vulcain -w /app php:8.1-alpine ./phpunit src/Symfony/Component/HttpClient/Tests/CurlHttpClientTest.php --filter testHttp2Push
217229
# sudo rm -rf .phpunit
218230
# [ -d .phpunit.bak ] && mv .phpunit.bak .phpunit
219-
220-
- name: Check for changes in translation files
221-
id: changed-translation-files
222-
run: |
223-
echo 'changed='$((git diff --quiet HEAD~1 HEAD -- 'src/**/Resources/translations/*.xlf' || (echo 'true' && exit 1)) && echo 'false') >> $GITHUB_OUTPUT
224-
225-
- name: Check Translation Status
226-
if: steps.changed-translation-files.outputs.changed == 'true'
227-
run: |
228-
php src/Symfony/Component/Translation/Resources/bin/translation-status.php -v
229-
php .github/sync-translations.php
230-
git diff --exit-code src/ || (echo '::error::Run "php .github/sync-translations.php" to fix XLIFF files.' && exit 1)

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\PropertyInfo;
1313

1414
use Doctrine\Common\Collections\Collection;
15+
use Doctrine\DBAL\Types\BigIntType;
1516
use Doctrine\DBAL\Types\Types;
1617
use Doctrine\ORM\EntityManagerInterface;
1718
use Doctrine\ORM\Mapping\AssociationMapping;
@@ -132,6 +133,15 @@ public function getTypes(string $class, string $property, array $context = []):
132133
}
133134

134135
$nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property);
136+
137+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
138+
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
139+
return [
140+
new Type(Type::BUILTIN_TYPE_INT, $nullable),
141+
new Type(Type::BUILTIN_TYPE_STRING, $nullable),
142+
];
143+
}
144+
135145
$enumType = null;
136146
if (null !== $enumClass = self::getMappingValue($metadata->getFieldMapping($property), 'enumType') ?? null) {
137147
$enumType = new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $enumClass);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\EntityRepository;
15+
16+
class MockableRepository extends EntityRepository
17+
{
18+
public function findByCustom()
19+
{
20+
}
21+
}

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Common\EventManager;
1616
use Doctrine\DBAL\DriverManager;
1717
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
18+
use Doctrine\DBAL\Types\BigIntType;
1819
use Doctrine\DBAL\Types\Type as DBALType;
1920
use Doctrine\ORM\EntityManager;
2021
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
@@ -143,10 +144,17 @@ public function testExtractEnum()
143144

144145
public static function typesProvider(): array
145146
{
147+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
148+
if (!method_exists(BigIntType::class, 'getName')) {
149+
$expectedBingIntType = [new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)];
150+
} else {
151+
$expectedBingIntType = [new Type(Type::BUILTIN_TYPE_STRING)];
152+
}
153+
146154
return [
147155
['id', [new Type(Type::BUILTIN_TYPE_INT)]],
148156
['guid', [new Type(Type::BUILTIN_TYPE_STRING)]],
149-
['bigint', [new Type(Type::BUILTIN_TYPE_STRING)]],
157+
['bigint', $expectedBingIntType],
150158
['time', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')]],
151159
['timeImmutable', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTimeImmutable')]],
152160
['dateInterval', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateInterval')]],

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,11 @@ private function getManager($em, $name = null)
236236

237237
private function getObjectManager($repository)
238238
{
239-
$em = $this->getMockBuilder(ObjectManager::class)
240-
->onlyMethods(['getClassMetadata', 'getRepository'])
241-
->getMockForAbstractClass();
242-
$em->expects($this->any())
243-
->method('getRepository')
239+
$objectManager = $this->createMock(ObjectManager::class);
240+
$objectManager->method('getRepository')
244241
->willReturn($repository);
245242

246-
return $em;
243+
return $objectManager;
247244
}
248245

249246
private function createSchema($em)

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity;
2929
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNullableNameEntity;
3030
use Symfony\Bridge\Doctrine\Tests\Fixtures\Employee;
31+
use Symfony\Bridge\Doctrine\Tests\Fixtures\MockableRepository;
3132
use Symfony\Bridge\Doctrine\Tests\Fixtures\Person;
3233
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
3334
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
@@ -85,14 +86,10 @@ protected function createRegistryMock($em = null)
8586

8687
protected function createRepositoryMock()
8788
{
88-
$repository = $this->getMockBuilder(EntityRepository::class)
89+
return $this->getMockBuilder(MockableRepository::class)
8990
->disableOriginalConstructor()
90-
->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName'])
91-
->addMethods(['findByCustom'])
92-
->getMock()
93-
;
94-
95-
return $repository;
91+
->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName', 'findByCustom'])
92+
->getMock();
9693
}
9794

9895
protected function createEntityManagerMock($repositoryMock)

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

+6
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ private static function getPhpUnitErrorHandler(): callable
376376

377377
if ('PHPUnit\Util\ErrorHandler::handleError' === $eh) {
378378
return $eh;
379+
} elseif (ErrorHandler::class === $eh) {
380+
return function (int $errorNumber, string $errorString, string $errorFile, int $errorLine) {
381+
ErrorHandler::instance()($errorNumber, $errorString, $errorFile, $errorLine);
382+
383+
return true;
384+
};
379385
}
380386

381387
foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {

src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ trait RuntimeLoaderProvider
2020
protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer)
2121
{
2222
$loader = $this->createMock(RuntimeLoaderInterface::class);
23-
$loader->expects($this->any())->method('load')->will($this->returnValueMap([
23+
$loader->expects($this->any())->method('load')->willReturnMap([
2424
['Symfony\Component\Form\FormRenderer', $renderer],
25-
]));
25+
]);
2626
$environment->addRuntimeLoader($loader);
2727
}
2828
}

src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class HttpKernelExtensionTest extends TestCase
3030
{
3131
public function testFragmentWithError()
3232
{
33-
$renderer = $this->getFragmentHandler($this->throwException(new \Exception('foo')));
33+
$renderer = $this->getFragmentHandler(new \Exception('foo'));
3434

3535
$this->expectException(\Twig\Error\RuntimeError::class);
3636

@@ -39,7 +39,7 @@ public function testFragmentWithError()
3939

4040
public function testRenderFragment()
4141
{
42-
$renderer = $this->getFragmentHandler($this->returnValue(new Response('html')));
42+
$renderer = $this->getFragmentHandler(new Response('html'));
4343

4444
$response = $this->renderTemplate($renderer);
4545

@@ -84,11 +84,17 @@ public function testGenerateFragmentUri()
8484
$this->assertSame('/_fragment?_hash=PP8%2FeEbn1pr27I9wmag%2FM6jYGVwUZ0l2h0vhh2OJ6CI%3D&amp;_path=template%3Dfoo.html.twig%26_format%3Dhtml%26_locale%3Den%26_controller%3DSymfonyBundleFrameworkBundleControllerTemplateController%253A%253AtemplateAction', $twig->render('index'));
8585
}
8686

87-
protected function getFragmentHandler($return)
87+
protected function getFragmentHandler($returnOrException): FragmentHandler
8888
{
8989
$strategy = $this->createMock(FragmentRendererInterface::class);
9090
$strategy->expects($this->once())->method('getName')->willReturn('inline');
91-
$strategy->expects($this->once())->method('render')->will($return);
91+
92+
$mocker = $strategy->expects($this->once())->method('render');
93+
if ($returnOrException instanceof \Exception) {
94+
$mocker->willThrowException($returnOrException);
95+
} else {
96+
$mocker->willReturn($returnOrException);
97+
}
9298

9399
$context = $this->createMock(RequestStack::class);
94100

src/Symfony/Component/Config/Tests/Definition/BaseNodeTest.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,36 @@ public function testGetPathForChildNode(string $expected, array $params)
3636
}
3737
}
3838

39-
$node = $this->getMockForAbstractClass(BaseNode::class, $constructorArgs);
39+
$node = new class(...$constructorArgs) extends BaseNode {
40+
protected function validateType($value): void
41+
{
42+
}
43+
44+
protected function normalizeValue($value)
45+
{
46+
return null;
47+
}
48+
49+
protected function mergeValues($leftSide, $rightSide)
50+
{
51+
return null;
52+
}
53+
54+
protected function finalizeValue($value)
55+
{
56+
return null;
57+
}
58+
59+
public function hasDefaultValue(): bool
60+
{
61+
return true;
62+
}
63+
64+
public function getDefaultValue()
65+
{
66+
return null;
67+
}
68+
};
4069

4170
$this->assertSame($expected, $node->getPath());
4271
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use Symfony\Component\Console\SignalRegistry\SignalRegistry;
4545
use Symfony\Component\Console\Terminal;
4646
use Symfony\Component\Console\Tester\ApplicationTester;
47+
use Symfony\Component\Console\Tests\Fixtures\MockableAppliationWithTerminalWidth;
4748
use Symfony\Component\DependencyInjection\ContainerBuilder;
4849
use Symfony\Component\EventDispatcher\EventDispatcher;
4950
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -932,7 +933,9 @@ public function testRenderExceptionEscapesLines()
932933

933934
public function testRenderExceptionLineBreaks()
934935
{
935-
$application = $this->getMockBuilder(Application::class)->addMethods(['getTerminalWidth'])->getMock();
936+
$application = $this->getMockBuilder(MockableAppliationWithTerminalWidth::class)
937+
->onlyMethods(['getTerminalWidth'])
938+
->getMock();
936939
$application->setAutoExit(false);
937940
$application->expects($this->any())
938941
->method('getTerminalWidth')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\Fixtures;
13+
14+
use Symfony\Component\Console\Application;
15+
16+
class MockableAppliationWithTerminalWidth extends Application
17+
{
18+
public function getTerminalWidth(): int
19+
{
20+
return 0;
21+
}
22+
}

src/Symfony/Component/Console/Tests/Question/QuestionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ public function testSetAutocompleterValuesInvalid($values)
157157
public function testSetAutocompleterValuesWithTraversable()
158158
{
159159
$question1 = new Question('Test question 1');
160-
$iterator1 = $this->getMockForAbstractClass(\IteratorAggregate::class);
160+
$iterator1 = $this->createMock(\IteratorAggregate::class);
161161
$iterator1
162162
->expects($this->once())
163163
->method('getIterator')
164164
->willReturn(new \ArrayIterator(['Potato']));
165165
$question1->setAutocompleterValues($iterator1);
166166

167167
$question2 = new Question('Test question 2');
168-
$iterator2 = $this->getMockForAbstractClass(\IteratorAggregate::class);
168+
$iterator2 = $this->createMock(\IteratorAggregate::class);
169169
$iterator2
170170
->expects($this->once())
171171
->method('getIterator')

src/Symfony/Component/ErrorHandler/Error/FatalError.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(string $message, int $code, array $error, ?int $trac
3131
}
3232
}
3333
} elseif (null !== $traceOffset) {
34-
if (\function_exists('xdebug_get_function_stack') && $trace = @xdebug_get_function_stack()) {
34+
if (\function_exists('xdebug_get_function_stack') && \in_array(\ini_get('xdebug.mode'), ['develop', false], true) && $trace = @xdebug_get_function_stack()) {
3535
if (0 < $traceOffset) {
3636
array_splice($trace, -$traceOffset);
3737
}

src/Symfony/Component/Filesystem/Filesystem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ public function dumpFile(string $filename, $content)
686686
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
687687
}
688688

689-
self::box('chmod', $tmpFile, @fileperms($filename) ?: 0666 & ~umask());
689+
self::box('chmod', $tmpFile, self::box('fileperms', $filename) ?: 0666 & ~umask());
690690

691691
$this->rename($tmpFile, $filename, true);
692692
} finally {

src/Symfony/Component/Form/Test/Traits/ValidatorExtensionTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ protected function getValidatorExtension(): ValidatorExtension
3636

3737
$this->validator = $this->createMock(ValidatorInterface::class);
3838
$metadata = $this->getMockBuilder(ClassMetadata::class)->setConstructorArgs([''])->onlyMethods(['addPropertyConstraint'])->getMock();
39-
$this->validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
40-
$this->validator->expects($this->any())->method('validate')->will($this->returnValue(new ConstraintViolationList()));
39+
$this->validator->expects($this->any())->method('getMetadataFor')->willReturn($metadata);
40+
$this->validator->expects($this->any())->method('validate')->willReturn(new ConstraintViolationList());
4141

4242
return new ValidatorExtension($this->validator, false);
4343
}

0 commit comments

Comments
 (0)