Skip to content

Commit

Permalink
Merge branch '4.4' into 5.0
Browse files Browse the repository at this point in the history
* 4.4: (25 commits)
  [DoctrineBridge] Use new Types::* constants and support new json type
  [Debug][ErrorHandler] improved deprecation notices for methods new args and return type
  [BrowserKit] Nested file array prevents uploading file
  [ExpressionLanguage] Fixed collisions of character operators with object properties
  [Validator] Remove specific check for Valid targets
  [PhpUnitBridge] Use trait instead of extending deprecated class
  Fix versioned namespace clears
  fix remember me
  Use strict assertion in asset tests
  [DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types
  Do not rely on the current locale when dumping a Graphviz object
  fix typo
  [Ldap] force default network timeout
  [Config] don't throw on missing excluded paths
  Docs: Typo, grammar
  [Validator] Add the missing translations for the Polish ("pl") locale
  [PhpUnitBridge] Add compatibility to PHPUnit 9 #35662
  [Routing] Add locale requirement for localized routes
  [Console] Inline exact-match handling with 4.4
  Set previous exception when rethrown from controller resolver
  ...
  • Loading branch information
nicolas-grekas committed Feb 24, 2020
2 parents d29865e + 1024f5f commit 08a233b
Show file tree
Hide file tree
Showing 57 changed files with 576 additions and 127 deletions.
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Expand Up @@ -277,3 +277,5 @@ public function reset()
$this->choiceLoaders = [];
}
}

interface_exists(ObjectManager::class);
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php
Expand Up @@ -96,3 +96,5 @@ private function parameterToArray(Parameter $parameter): array
return [$parameter->getName(), $parameter->getType(), $parameter->getValue()];
}
}

interface_exists(ObjectManager::class);
80 changes: 52 additions & 28 deletions src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Expand Up @@ -103,7 +103,9 @@ public function getTypes(string $class, string $property, array $context = [])
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
}

$collectionKeyType = $this->getPhpType($typeOfField);
if (!$collectionKeyType = $this->getPhpType($typeOfField)) {
return null;
}
}
}

Expand All @@ -123,39 +125,46 @@ public function getTypes(string $class, string $property, array $context = [])

if ($metadata->hasField($property)) {
$typeOfField = $metadata->getTypeOfField($property);
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property);

switch ($typeOfField) {
case DBALType::DATE:
case DBALType::DATETIME:
case DBALType::DATETIMETZ:
case 'vardatetime':
case DBALType::TIME:
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')];

case 'date_immutable':
case 'datetime_immutable':
case 'datetimetz_immutable':
case 'time_immutable':
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTimeImmutable')];

case 'dateinterval':
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateInterval')];

case DBALType::TARRAY:
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
if (!$builtinType = $this->getPhpType($typeOfField)) {
return null;
}

case DBALType::SIMPLE_ARRAY:
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))];
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property);

case DBALType::JSON_ARRAY:
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
switch ($builtinType) {
case Type::BUILTIN_TYPE_OBJECT:
switch ($typeOfField) {
case DBALType::DATE:
case DBALType::DATETIME:
case DBALType::DATETIMETZ:
case 'vardatetime':
case DBALType::TIME:
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')];

case 'date_immutable':
case 'datetime_immutable':
case 'datetimetz_immutable':
case 'time_immutable':
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTimeImmutable')];

case 'dateinterval':
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateInterval')];
}

default:
$builtinType = $this->getPhpType($typeOfField);
break;
case Type::BUILTIN_TYPE_ARRAY:
switch ($typeOfField) {
case DBALType::TARRAY:
case DBALType::JSON_ARRAY:
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];

return $builtinType ? [new Type($builtinType, $nullable)] : null;
case DBALType::SIMPLE_ARRAY:
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))];
}
}

return [new Type($builtinType, $nullable)];
}

return null;
Expand Down Expand Up @@ -247,7 +256,22 @@ private function getPhpType(string $doctrineType): ?string
return Type::BUILTIN_TYPE_RESOURCE;

case DBALType::OBJECT:
case DBALType::DATE:
case DBALType::DATETIME:
case DBALType::DATETIMETZ:
case 'vardatetime':
case DBALType::TIME:
case 'date_immutable':
case 'datetime_immutable':
case 'datetimetz_immutable':
case 'time_immutable':
case 'dateinterval':
return Type::BUILTIN_TYPE_OBJECT;

case DBALType::TARRAY:
case DBALType::SIMPLE_ARRAY:
case DBALType::JSON_ARRAY:
return Type::BUILTIN_TYPE_ARRAY;
}

return null;
Expand Down
Expand Up @@ -153,3 +153,6 @@ private function getClassMetadata(): ClassMetadata
return $this->getObjectManager()->getClassMetadata($this->classOrAlias);
}
}

interface_exists(ObjectManager::class);
interface_exists(ObjectRepository::class);
Expand Up @@ -11,12 +11,14 @@

namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo;

use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineGeneratedValue;
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation;
use Symfony\Component\PropertyInfo\Type;

/**
Expand Down Expand Up @@ -58,6 +60,8 @@ public function testGetProperties()
'bar',
'indexedBar',
'indexedFoo',
'indexedByDt',
'indexedByCustomType',
],
$this->createExtractor()->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
);
Expand Down Expand Up @@ -149,6 +153,15 @@ public function typesProvider()
['simpleArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
['customFoo', null],
['notMapped', null],
['indexedByDt', [new Type(
Type::BUILTIN_TYPE_OBJECT,
false,
Collection::class,
true,
new Type(Type::BUILTIN_TYPE_OBJECT),
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
)]],
['indexedByCustomType', null],
];
}

Expand Down
Expand Up @@ -112,4 +112,14 @@ class DoctrineDummy
private $bigint;

public $notMapped;

/**
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="dt", indexBy="dt")
*/
protected $indexedByDt;

/**
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="customType", indexBy="customType")
*/
private $indexedByCustomType;
}
@@ -0,0 +1,30 @@
<?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\PropertyInfo\Fixtures;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;

/**
* @Entity
*/
final class DoctrineDummy210 extends DoctrineDummy
{
/**
* @Column(type="json", nullable=true)
*/
private $json;
}
Expand Up @@ -39,4 +39,14 @@ class DoctrineRelation
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedFoo")
*/
protected $foo;

/**
* @Column(type="datetime")
*/
private $dt;

/**
* @Column(type="foo")
*/
private $customType;
}
63 changes: 63 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/CommandForV9.php
@@ -0,0 +1,63 @@
<?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\PhpUnit\Legacy;

use PHPUnit\TextUI\Command as BaseCommand;
use PHPUnit\TextUI\Configuration\Configuration;
use PHPUnit\TextUI\Configuration\Registry;
use PHPUnit\TextUI\TestRunner as BaseRunner;
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;

/**
* {@inheritdoc}
*
* @internal
*/
class CommandForV9 extends BaseCommand
{
/**
* {@inheritdoc}
*/
protected function createRunner(): BaseRunner
{
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : [];

$registeredLocally = false;

foreach ($this->arguments['listeners'] as $registeredListener) {
if ($registeredListener instanceof SymfonyTestsListener) {
$registeredListener->globalListenerDisabled();
$registeredLocally = true;
break;
}
}

if (isset($this->arguments['configuration'])) {
$configuration = $this->arguments['configuration'];
if (!$configuration instanceof Configuration) {
$configuration = Registry::getInstance()->get($this->arguments['configuration']);
}
foreach ($configuration->listeners() as $registeredListener) {
if ('Symfony\Bridge\PhpUnit\SymfonyTestsListener' === ltrim($registeredListener->className(), '\\')) {
$registeredLocally = true;
break;
}
}
}

if (!$registeredLocally) {
$this->arguments['listeners'][] = new SymfonyTestsListener();
}

return parent::createRunner();
}
}
7 changes: 5 additions & 2 deletions src/Symfony/Bridge/PhpUnit/Legacy/CoverageListenerForV6.php
Expand Up @@ -11,8 +11,9 @@

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;

/**
* CoverageListener adds `@covers <className>` on each test when possible to
Expand All @@ -22,8 +23,10 @@
*
* @internal
*/
class CoverageListenerForV6 extends BaseTestListener
class CoverageListenerForV6 implements TestListener
{
use TestListenerDefaultImplementation;

private $trait;

public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Bridge/PhpUnit/TextUI/Command.php
Expand Up @@ -13,8 +13,10 @@

if (version_compare(\PHPUnit\Runner\Version::id(), '6.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV5', 'Symfony\Bridge\PhpUnit\TextUI\Command');
} else {
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '9.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV6', 'Symfony\Bridge\PhpUnit\TextUI\Command');
} else {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV9', 'Symfony\Bridge\PhpUnit\TextUI\Command');
}

if (false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/composer.json
Expand Up @@ -24,7 +24,7 @@
"symfony/error-handler": "For tracking deprecated interfaces usages at runtime with DebugClassLoader"
},
"conflict": {
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0|<6.4,>=6.0"
},
"autoload": {
"files": [ "bootstrap.php" ],
Expand Down
Expand Up @@ -35,7 +35,7 @@ class TwigErrorRenderer implements ErrorRendererInterface
public function __construct(Environment $twig, HtmlErrorRenderer $fallbackErrorRenderer = null, $debug = false)
{
if (!\is_bool($debug) && !\is_callable($debug)) {
throw new \TypeError(sprintf('Argument 2 passed to %s() must be a boolean or a callable, %s given.', __METHOD__, \is_object($debug) ? \get_class($debug) : \gettype($debug)));
throw new \TypeError(sprintf('Argument 3 passed to %s() must be a boolean or a callable, %s given.', __METHOD__, \is_object($debug) ? \get_class($debug) : \gettype($debug)));
}

$this->twig = $twig;
Expand Down
Expand Up @@ -37,7 +37,7 @@ public function testGetBasePathSet()

$requestStackContext = new RequestStackContext($requestStack);

$this->assertEquals($testBasePath, $requestStackContext->getBasePath());
$this->assertSame($testBasePath, $requestStackContext->getBasePath());
}

public function testIsSecureFalse()
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Asset/Tests/PackageTest.php
Expand Up @@ -24,7 +24,7 @@ class PackageTest extends TestCase
public function testGetUrl($version, $format, $path, $expected)
{
$package = new Package($version ? new StaticVersionStrategy($version, $format) : new EmptyVersionStrategy());
$this->assertEquals($expected, $package->getUrl($path));
$this->assertSame($expected, $package->getUrl($path));
}

public function getConfigs()
Expand All @@ -50,6 +50,6 @@ public function getConfigs()
public function testGetVersion()
{
$package = new Package(new StaticVersionStrategy('v1'));
$this->assertEquals('v1', $package->getVersion('/foo'));
$this->assertSame('v1', $package->getVersion('/foo'));
}
}

0 comments on commit 08a233b

Please sign in to comment.