Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
* 4.4:
  install compatible versions of mongodb/mongodb only
  fix resolving parent/self/static type annotations
  [Console] fix QuestionHelper::getHiddenResponse() not working with space in project directory name
  [WebLink] Escape double quotes in attributes values
  • Loading branch information
xabbuh committed Feb 17, 2021
2 parents b148f89 + 1a5aec1 commit e3b0c88
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -255,7 +255,7 @@ install:
fi
phpenv global $PHP
rm vendor/composer/package-versions-deprecated -Rf
([[ $deps ]] && cd src/Symfony/Component/HttpFoundation; cp composer.json composer.bak; composer require --dev --no-update mongodb/mongodb ^1.9.0)
([[ $deps ]] && cd src/Symfony/Component/HttpFoundation; cp composer.json composer.bak; composer require --dev --no-update mongodb/mongodb)
tfold 'composer update' $COMPOSER_UP
tfold 'phpunit install' ./phpunit install
if [[ $deps = high ]]; then
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/QuestionHelper.php
Expand Up @@ -411,7 +411,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $
$exe = $tmpExe;
}

$sExec = shell_exec($exe);
$sExec = shell_exec('"'.$exe.'"');
$value = $trimmable ? rtrim($sExec) : $sExec;
$output->writeln('');

Expand Down
22 changes: 21 additions & 1 deletion src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php
Expand Up @@ -142,11 +142,31 @@ public function getTypes(string $class, string $property, array $context = []):
break;
}

$parentClass = null;
$types = [];
/** @var DocBlock\Tags\Var_|DocBlock\Tags\Return_|DocBlock\Tags\Param $tag */
foreach ($docBlock->getTagsByName($tag) as $tag) {
if ($tag && !$tag instanceof InvalidTag && null !== $tag->getType()) {
$types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType()));
foreach ($this->phpDocTypeHelper->getTypes($tag->getType()) as $type) {
switch ($type->getClassName()) {
case 'self':
case 'static':
$resolvedClass = $class;
break;

case 'parent':
if (false !== $resolvedClass = $parentClass ?? $parentClass = get_parent_class($class)) {
break;
}
// no break

default:
$types[] = $type;
continue 2;
}

$types[] = new Type(Type::BUILTIN_TYPE_OBJECT, $type->isNullable(), $resolvedClass, $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType());
}
}
}

Expand Down
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait;
use Symfony\Component\PropertyInfo\Type;
Expand Down Expand Up @@ -136,6 +137,7 @@ public function typesProvider()
null,
null,
],
['self', [new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)], null, null],
];
}

Expand Down Expand Up @@ -342,6 +344,38 @@ public function propertiesDefinedByTraitsProvider(): array
];
}

/**
* @dataProvider propertiesStaticTypeProvider
*/
public function testPropertiesStaticType(string $class, string $property, Type $type)
{
$this->assertEquals([$type], $this->extractor->getTypes($class, $property));
}

public function propertiesStaticTypeProvider(): array
{
return [
[ParentDummy::class, 'propertyTypeStatic', new Type(Type::BUILTIN_TYPE_OBJECT, false, ParentDummy::class)],
[Dummy::class, 'propertyTypeStatic', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)],
];
}

/**
* @dataProvider propertiesParentTypeProvider
*/
public function testPropertiesParentType(string $class, string $property, ?array $types)
{
$this->assertEquals($types, $this->extractor->getTypes($class, $property));
}

public function propertiesParentTypeProvider(): array
{
return [
[ParentDummy::class, 'parentAnnotationNoParent', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'parent')]],
[Dummy::class, 'parentAnnotation', [new Type(Type::BUILTIN_TYPE_OBJECT, false, ParentDummy::class)]],
];
}

protected function isPhpDocumentorV5()
{
if (class_exists(InvalidTag::class)) {
Expand Down
Expand Up @@ -24,6 +24,8 @@
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php71DummyExtended;
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php71DummyExtended2;
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php74Dummy;
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy;
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php7ParentDummy;
use Symfony\Component\PropertyInfo\Type;

/**
Expand Down Expand Up @@ -66,12 +68,15 @@ public function testGetProperties()
'arrayWithKeys',
'arrayWithKeysAndComplexValue',
'arrayOfMixed',
'parentAnnotation',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
'propertyTypeStatic',
'parentAnnotationNoParent',
'a',
'DOB',
'Id',
Expand Down Expand Up @@ -118,12 +123,15 @@ public function testGetPropertiesWithCustomPrefixes()
'arrayWithKeys',
'arrayWithKeysAndComplexValue',
'arrayOfMixed',
'parentAnnotation',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
'propertyTypeStatic',
'parentAnnotationNoParent',
'date',
'c',
'd',
Expand Down Expand Up @@ -159,12 +167,15 @@ public function testGetPropertiesWithNoPrefixes()
'arrayWithKeys',
'arrayWithKeysAndComplexValue',
'arrayOfMixed',
'parentAnnotation',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
'propertyTypeStatic',
'parentAnnotationNoParent',
],
$noPrefixExtractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')
);
Expand Down Expand Up @@ -200,20 +211,21 @@ public function typesProvider()
/**
* @dataProvider php7TypesProvider
*/
public function testExtractPhp7Type($property, array $type = null)
public function testExtractPhp7Type(string $class, string $property, array $type = null)
{
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy', $property, []));
$this->assertEquals($type, $this->extractor->getTypes($class, $property, []));
}

public function php7TypesProvider()
{
return [
['foo', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]],
['bar', [new Type(Type::BUILTIN_TYPE_INT)]],
['baz', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
['buz', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy')]],
['biz', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'stdClass')]],
['donotexist', null],
[Php7Dummy::class, 'foo', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]],
[Php7Dummy::class, 'bar', [new Type(Type::BUILTIN_TYPE_INT)]],
[Php7Dummy::class, 'baz', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
[Php7Dummy::class, 'buz', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy')]],
[Php7Dummy::class, 'biz', [new Type(Type::BUILTIN_TYPE_OBJECT, false, Php7ParentDummy::class)]],
[Php7Dummy::class, 'donotexist', null],
[Php7ParentDummy::class, 'parent', [new Type(Type::BUILTIN_TYPE_OBJECT, false, \stdClass::class)]],
];
}

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
Expand Up @@ -145,6 +145,11 @@ class Dummy extends ParentDummy
*/
public $arrayOfMixed;

/**
* @var parent
*/
public $parentAnnotation;

public static function getStatic()
{
}
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php
Expand Up @@ -48,6 +48,16 @@ class ParentDummy
*/
public $files;

/**
* @var static
*/
public $propertyTypeStatic;

/**
* @var parent
*/
public $parentAnnotationNoParent;

/**
* @return bool|null
*/
Expand Down
Expand Up @@ -14,7 +14,7 @@
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class Php7Dummy extends \stdClass
class Php7Dummy extends Php7ParentDummy
{
public function getFoo(): array
{
Expand Down
@@ -0,0 +1,19 @@
<?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\PropertyInfo\Tests\Fixtures;

class Php7ParentDummy extends \stdClass
{
public function getParent(): parent
{
}
}
4 changes: 4 additions & 0 deletions src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php
Expand Up @@ -172,6 +172,10 @@ private function getPhpTypeAndClass(string $docType): array
return [$docType, null];
}

if (\in_array($docType, ['parent', 'self', 'static'], true)) {
return ['object', $docType];
}

return ['object', substr($docType, 1)]; // substr to strip the namespace's `\`-prefix
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/WebLink/HttpHeaderSerializer.php
Expand Up @@ -39,14 +39,14 @@ public function serialize(iterable $links): ?string
foreach ($link->getAttributes() as $key => $value) {
if (\is_array($value)) {
foreach ($value as $v) {
$attributesParts[] = sprintf('%s="%s"', $key, $v);
$attributesParts[] = sprintf('%s="%s"', $key, preg_replace('/(?<!\\\\)"/', '\"', $v));
}

continue;
}

if (!\is_bool($value)) {
$attributesParts[] = sprintf('%s="%s"', $key, $value);
$attributesParts[] = sprintf('%s="%s"', $key, preg_replace('/(?<!\\\\)"/', '\"', $value));

continue;
}
Expand Down
Expand Up @@ -44,4 +44,12 @@ public function testSerializeEmpty()
{
$this->assertNull($this->serializer->serialize([]));
}

public function testSerializeDoubleQuotesInAttributeValue()
{
$this->assertSame('</foo>; rel="alternate"; title="\"escape me\" \"already escaped\" \"\"\""', $this->serializer->serialize([
(new Link('alternate', '/foo'))
->withAttribute('title', '"escape me" \"already escaped\" ""\"'),
]));
}
}

0 comments on commit e3b0c88

Please sign in to comment.