Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PropertyInfo] Error with phpdocumentor/reflection in test mode #23576

Closed
aumel opened this issue Jul 18, 2017 · 4 comments
Closed

[PropertyInfo] Error with phpdocumentor/reflection in test mode #23576

aumel opened this issue Jul 18, 2017 · 4 comments

Comments

@aumel
Copy link

aumel commented Jul 18, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.8.25

I am not sure if the problem is related directly to Symfony.

I encounter an error with PropertyInfo component on a new install of symfony 2.8.25 and phpunit tests. The problem does not seem to appear in production mode.

This is a simple test to reproduce:

<?php

namespace AppBundle\Tests;

use AppBundle\Entity\MyClass;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;

class PropertyInfoTest extends \PHPUnit_Framework_TestCase
{
    public function testPropertyInfo()
    {
        $phpDocExtractor = new PhpDocExtractor();
        $reflectionExtractor = new ReflectionExtractor();

        $listExtractors = array($reflectionExtractor);

        $typeExtractors = array($phpDocExtractor, $reflectionExtractor);

        $descriptionExtractors = array($phpDocExtractor);

        $accessExtractors = array($reflectionExtractor);

        $propertyInfo = new PropertyInfoExtractor(
            $listExtractors,
            $typeExtractors,
            $descriptionExtractors,
            $accessExtractors
        );

        $object = new MyClass();
        // this part throws an error
        $types = $propertyInfo->getTypes(get_class($object), 'property');
    }
}

When I execute the test with phpunit, I get this error:

Fatal error:  Cannot use phpDocumentor\Reflection\DocBlock\Location as Location because the name is already in use in test_property_info/vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/FileReflector.php on line 19

Is there a problem with autoload PSR-4 ?

@Simperfit
Copy link
Contributor

@aumel Could you please do the following, so we could get a reproducer ?

@aumel
Copy link
Author

aumel commented Aug 11, 2017

@Simperfit I forked the Symfony Standard Edition and I made modification to reproduce the bug on branch issue-23576

Link of the forked repo: https://github.com/aumel/symfony-standard

To reproduce bug, you must execute the test phpunit -c app src/AppBundle/Tests/Entity/

You will get this error:

Fatal error:  Cannot use phpDocumentor\Reflection\DocBlock\Location as Location because the name is already in use in /vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/FileReflector.php on line 19

For info, I tested with PHP 5.6.x and phpunit 5.7.21.

@jakzal
Copy link
Contributor

jakzal commented Oct 25, 2017

@aumel thanks for taking time to reproduce this issue. Seems that the original problem is replaced by a new one. This is what I'm getting now (on PHP 7.1.10 with PHPUnit 5.7.23):

There was 1 error:

1) AppBundle\Tests\Entity\PropertyInfoTest::testPropertyInfo
TypeError: Argument 2 passed to phpDocumentor\Reflection\DocBlock::__construct() must be an instance of phpDocumentor\Reflection\DocBlock\Description or null, instance of phpDocumentor\Reflection\DocBlock\Context given, called in /project/vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/BaseReflector.php on line 131

/project/vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/BaseReflector.php:131
/project/vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/ClassReflector/PropertyReflector.php:105
/project/vendor/symfony/symfony/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php:231
/project/vendor/symfony/symfony/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php:179
/project/vendor/symfony/symfony/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php:86
/project/vendor/symfony/symfony/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php:115
/project/vendor/symfony/symfony/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php:84
/project/src/AppBundle/Tests/Entity/PropertyInfoTest.php:39

The problem is caused by PHPUnit coming with phpdocumentor/reflection-dockblock. If you run it as a phar the version might be different to the one installed in your project.

Symfony 2.8 branch relies on phpdocumentor/reflection-dockblock:^1.0.7, while PHPUnit >= 5 comes with version 3.*. Your test won't fail with phpunit 4.8.

You either have to use the legacy phpunit version, or upgrade Symfony I'm afraid.

@aumel
Copy link
Author

aumel commented Oct 30, 2017

@jakzal Thanks! I didn't notice the difference between PHPUnit and Symfony 2.8 for phpdocumentor/reflection-dockblock.

@fabpot fabpot closed this as completed Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants