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:
  [Serializer] Improve exception message in UnwrappingDenormalizer
  [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
  Return false in isTtySupported() when open_basedir restrictions prevent access to /dev/tty.
  Remove calls to `TestCase::iniSet()` and calls to deprecated methods of `MockBuilder`
  [PhpUnitBridge] Fix `DeprecationErrorHandler` with PhpUnit 10
  • Loading branch information
fabpot committed May 17, 2024
2 parents bb91614 + 142c4be commit c58c599
Show file tree
Hide file tree
Showing 111 changed files with 670 additions and 173 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ jobs:
./phpunit install
echo "::endgroup::"
- name: Check for changes in translation files
id: changed-translation-files
run: |
echo 'changed='$((git diff --quiet HEAD~1 HEAD -- 'src/**/Resources/translations/*.xlf' || (echo 'true' && exit 1)) && echo 'false') >> $GITHUB_OUTPUT
- name: Check Translation Status
if: steps.changed-translation-files.outputs.changed == 'true'
run: |
php src/Symfony/Component/Translation/Resources/bin/translation-status.php -v
php .github/sync-translations.php
git diff --exit-code src/ || (echo '::error::Run "php .github/sync-translations.php" to fix XLIFF files.' && exit 1)
- name: Run tests
run: ./phpunit --group integration -v
env:
Expand All @@ -216,15 +228,3 @@ jobs:
# 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
# sudo rm -rf .phpunit
# [ -d .phpunit.bak ] && mv .phpunit.bak .phpunit

- name: Check for changes in translation files
id: changed-translation-files
run: |
echo 'changed='$((git diff --quiet HEAD~1 HEAD -- 'src/**/Resources/translations/*.xlf' || (echo 'true' && exit 1)) && echo 'false') >> $GITHUB_OUTPUT
- name: Check Translation Status
if: steps.changed-translation-files.outputs.changed == 'true'
run: |
php src/Symfony/Component/Translation/Resources/bin/translation-status.php -v
php .github/sync-translations.php
git diff --exit-code src/ || (echo '::error::Run "php .github/sync-translations.php" to fix XLIFF files.' && exit 1)
10 changes: 10 additions & 0 deletions src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Doctrine\PropertyInfo;

use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\BigIntType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AssociationMapping;
Expand Down Expand Up @@ -236,6 +237,15 @@ public function getTypes(string $class, string $property, array $context = []):
}

$nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property);

// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
return [
new Type(Type::BUILTIN_TYPE_INT, $nullable),
new Type(Type::BUILTIN_TYPE_STRING, $nullable),
];
}

$enumType = null;
if (null !== $enumClass = self::getMappingValue($metadata->getFieldMapping($property), 'enumType') ?? null) {
$enumType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, $nullable, $enumClass);
Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/Fixtures/MockableRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures;

use Doctrine\ORM\EntityRepository;

class MockableRepository extends EntityRepository
{
public function findByCustom()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Types\BigIntType;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
Expand Down Expand Up @@ -153,10 +154,17 @@ public function testExtractEnumLegacy()
*/
public static function legacyTypesProvider(): array
{
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
if (!method_exists(BigIntType::class, 'getName')) {
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_INT), new Type(LegacyType::BUILTIN_TYPE_STRING)];
} else {
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_STRING)];
}

return [
['id', [new LegacyType(LegacyType::BUILTIN_TYPE_INT)]],
['guid', [new LegacyType(LegacyType::BUILTIN_TYPE_STRING)]],
['bigint', [new LegacyType(LegacyType::BUILTIN_TYPE_STRING)]],
['bigint', $expectedBingIntType],
['time', [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'DateTime')]],
['timeImmutable', [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'DateTimeImmutable')]],
['dateInterval', [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'DateInterval')]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,11 @@ private function getManager($em, $name = null)

private function getObjectManager($repository)
{
$em = $this->getMockBuilder(ObjectManager::class)
->onlyMethods(['getClassMetadata', 'getRepository'])
->getMockForAbstractClass();
$em->expects($this->any())
->method('getRepository')
$objectManager = $this->createMock(ObjectManager::class);
$objectManager->method('getRepository')
->willReturn($repository);

return $em;
return $objectManager;
}

private function createSchema($em)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Symfony\Bridge\Doctrine\Tests\Fixtures\Dto;
use Symfony\Bridge\Doctrine\Tests\Fixtures\Employee;
use Symfony\Bridge\Doctrine\Tests\Fixtures\HireAnEmployee;
use Symfony\Bridge\Doctrine\Tests\Fixtures\MockableRepository;
use Symfony\Bridge\Doctrine\Tests\Fixtures\Person;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
Expand Down Expand Up @@ -91,14 +92,10 @@ protected function createRegistryMock($em = null)

protected function createRepositoryMock()
{
$repository = $this->getMockBuilder(EntityRepository::class)
return $this->getMockBuilder(MockableRepository::class)
->disableOriginalConstructor()
->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName'])
->addMethods(['findByCustom'])
->getMock()
;

return $repository;
->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName', 'findByCustom'])
->getMock();
}

protected function createEntityManagerMock($repositoryMock)
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ private static function getPhpUnitErrorHandler(): callable

if ('PHPUnit\Util\ErrorHandler::handleError' === $eh) {
return $eh;
} elseif (ErrorHandler::class === $eh) {
return function (int $errorNumber, string $errorString, string $errorFile, int $errorLine) {
ErrorHandler::instance()($errorNumber, $errorString, $errorFile, $errorLine);

return true;
};
}

foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ trait RuntimeLoaderProvider
protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer)
{
$loader = $this->createMock(RuntimeLoaderInterface::class);
$loader->expects($this->any())->method('load')->will($this->returnValueMap([
$loader->expects($this->any())->method('load')->willReturnMap([
['Symfony\Component\Form\FormRenderer', $renderer],
]));
]);
$environment->addRuntimeLoader($loader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HttpKernelExtensionTest extends TestCase
{
public function testFragmentWithError()
{
$renderer = $this->getFragmentHandler($this->throwException(new \Exception('foo')));
$renderer = $this->getFragmentHandler(new \Exception('foo'));

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

Expand All @@ -39,7 +39,7 @@ public function testFragmentWithError()

public function testRenderFragment()
{
$renderer = $this->getFragmentHandler($this->returnValue(new Response('html')));
$renderer = $this->getFragmentHandler(new Response('html'));

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

Expand Down Expand Up @@ -83,11 +83,17 @@ public function testGenerateFragmentUri()
$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'));
}

protected function getFragmentHandler($return)
protected function getFragmentHandler($returnOrException): FragmentHandler
{
$strategy = $this->createMock(FragmentRendererInterface::class);
$strategy->expects($this->once())->method('getName')->willReturn('inline');
$strategy->expects($this->once())->method('render')->will($return);

$mocker = $strategy->expects($this->once())->method('render');
if ($returnOrException instanceof \Exception) {
$mocker->willThrowException($returnOrException);
} else {
$mocker->willReturn($returnOrException);
}

$context = new RequestStack();

Expand Down
31 changes: 30 additions & 1 deletion src/Symfony/Component/Config/Tests/Definition/BaseNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,36 @@ public function testGetPathForChildNode(string $expected, array $params)
}
}

$node = $this->getMockForAbstractClass(BaseNode::class, $constructorArgs);
$node = new class(...$constructorArgs) extends BaseNode {
protected function validateType($value): void
{
}

protected function normalizeValue($value)
{
return null;
}

protected function mergeValues($leftSide, $rightSide)
{
return null;
}

protected function finalizeValue($value)
{
return null;
}

public function hasDefaultValue(): bool
{
return true;
}

public function getDefaultValue()
{
return null;
}
};

$this->assertSame($expected, $node->getPath());
}
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use Symfony\Component\Console\SignalRegistry\SignalRegistry;
use Symfony\Component\Console\Terminal;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\Console\Tests\Fixtures\MockableAppliationWithTerminalWidth;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -932,7 +933,9 @@ public function testRenderExceptionEscapesLines()

public function testRenderExceptionLineBreaks()
{
$application = $this->getMockBuilder(Application::class)->addMethods(['getTerminalWidth'])->getMock();
$application = $this->getMockBuilder(MockableAppliationWithTerminalWidth::class)
->onlyMethods(['getTerminalWidth'])
->getMock();
$application->setAutoExit(false);
$application->expects($this->any())
->method('getTerminalWidth')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Console\Tests\Fixtures;

use Symfony\Component\Console\Application;

class MockableAppliationWithTerminalWidth extends Application
{
public function getTerminalWidth(): int
{
return 0;
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Tests/Question/QuestionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ public function testSetAutocompleterValuesInvalid($values)
public function testSetAutocompleterValuesWithTraversable()
{
$question1 = new Question('Test question 1');
$iterator1 = $this->getMockForAbstractClass(\IteratorAggregate::class);
$iterator1 = $this->createMock(\IteratorAggregate::class);
$iterator1
->expects($this->once())
->method('getIterator')
->willReturn(new \ArrayIterator(['Potato']));
$question1->setAutocompleterValues($iterator1);

$question2 = new Question('Test question 2');
$iterator2 = $this->getMockForAbstractClass(\IteratorAggregate::class);
$iterator2 = $this->createMock(\IteratorAggregate::class);
$iterator2
->expects($this->once())
->method('getIterator')
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/ErrorHandler/Error/FatalError.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
}
}
} elseif (null !== $traceOffset) {
if (\function_exists('xdebug_get_function_stack') && $trace = @xdebug_get_function_stack()) {
if (\function_exists('xdebug_get_function_stack') && \in_array(\ini_get('xdebug.mode'), ['develop', false], true) && $trace = @xdebug_get_function_stack()) {
if (0 < $traceOffset) {
array_splice($trace, -$traceOffset);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ public function dumpFile(string $filename, $content): void
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
}

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

$this->rename($tmpFile, $filename, true);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ protected function getValidatorExtension(): ValidatorExtension

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

return new ValidatorExtension($this->validator, false);
}
Expand Down

0 comments on commit c58c599

Please sign in to comment.