webfactory / symfony-application-tests

Contains several generic test scenarios that can be applied to Symfony applications.
MIT License
10 stars 1 forks source link

Autoloading of annotations in data providers #8

Closed MalteWunsch closed 9 years ago

MalteWunsch commented 9 years ago

After configuring PHPUnit to use the newly installed tests, I get failures like this:

1) Warning
The data provider specified for Webfactory\Tests\Integration\SecureAnnotationTest::testSecureAnnotationsReferenceExistingRoles is invalid.
[Semantical Error] The annotation "@Sensio\Bundle\FrameworkExtraBundle\Configuration\Route" in method KleineAufmerksamkeiten\WebsiteBundle\Controller\StartseiteController::startseiteAction() does not exist, or could not be auto-loaded.

Same with the autoloading of the @Doctrine\ORM\Mapping\Entity annotation.

Matthimatiker commented 9 years ago

How does your phpunit.xml look like?

This is an example configuration depending on the Symfony Standard Edition:

<phpunit
    backupGlobals               = "false"
    backupStaticAttributes      = "false"
    colors                      = "true"
    convertErrorsToExceptions   = "true"
    convertNoticesToExceptions  = "true"
    convertWarningsToExceptions = "true"
    processIsolation            = "false"
    stopOnFailure               = "false"
    syntaxCheck                 = "false"
    bootstrap                   = "bootstrap.php.cache" >

    <testsuites>
        <testsuite name="Functional App Tests">
            <directory>Tests</directory>
            <directory>../vendor/webfactory/symfony-application-tests/src/Webfactory/Tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

It uses Symfony's autoload file, which configures annotation loading properly.

MalteWunsch commented 9 years ago

Thank you, that does the trick! I had bootstrap = "vendor/autoload.php".

Do you think this might be a mistake common enough to mention it in the readme? I tend to say no, as the default value is fine and anybody changing that should know what they're doing :smile:

mpdude commented 9 years ago

Where does the bootstrap.php.cache come from?

MalteWunsch commented 9 years ago

@mpdude In vanilla Symfony, the generated bootstrap.php.cache contains definitions of many core classes to reduce disc I/O and therefore increase performance. Here, it is used slightly different for bootstrapping the loading of required classes.