Skip to content

Testing doesn't work by default #10350

Closed
Closed
@hackzilla

Description

@hackzilla

I've just created a project using Symfony flex, and installed the test-pack.
When running bin/phpunit, my classes could not be found.

Error: Class 'App\Model\Manufacturer' not found

I have read the testing documentation (https://symfony.com/doc/master/testing.html) but can see no answers. It seems it should just work.

The issue appears to be that the autoloader is not found. I got no phpunit.xml.dist as part of the test-pack installation. (which I expected).

There are numerous other people struggling with this.
https://stackoverflow.com/questions/48440291/phpunit-error-class-not-found/52352887#52352887

I found the solution was to create my own phpunit.xml.dist file and specify bootstrap as the autoload.php file.

<!-- http://phpunit.de/manual/6.0/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd"
         bootstrap="vendor/autoload.php"
>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

</phpunit>

The solution should be to create this file or at least mention this in the documentation.

Please, can you also confirm that this is the correct solution to the issue?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions