Bonjour,

Depuis hier, je galère sur l'installation de PHPUnit, ça me rend fou...

J'ai bien installé PHPUnit via mon composer, ça c'est bon. Dans mes settings, j'ai coché l'option "USe Composer Autoloader", et ma version de PHPUnit (6.5.0) est bien reconnue.

Quand je vais dans la config du run/debug, j'attribue au testscope le dossier à partir duquel je fais mes tests.

C'est ici que ça se complique, déjà, en essayant le DefaultController fourni lors de l'installation, j'ai ce message d'erreur : RuntimeException : Unable to guess the Kernel directory.

Ma structure de dossiers est telle que (je restreint un peu mais je n'ai pas besoin d'utiliser autre chose):

Projet/ src/
AppBundle/
tests/

Je ne comprends pas d'où ça peut venir, j'ai regardé du côté de mon autoloader, via mon composer.json :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 
{
    "name": "agaut/museedulouvre",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "": "src/"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        },
        "files": [
            "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
        ]
    },
    "require": {
        "php": ">=5.5.9",
        "components/jquery": "^3.1",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/orm": "^2.5",
        "flosch/stripe-bundle": "^0.1.9",
        "friendsofsymfony/jsrouting-bundle": "^2.1",
        "incenteev/composer-parameter-handler": "^2.0",
        "oyejorge/less.php": "v1.7.0.14",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^3.0.2",
        "symfony/assetic-bundle": "^2.8",
        "symfony/browser-kit": "^4.0",
        "symfony/form": "4.0.*",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.3.10",
        "symfony/symfony": "3.4.*",
        "twbs/bootstrap": "^3.3",
        "twig/twig": "^1.0||^2.0"
    },
    "require-dev": {
        "phpunit/phpunit": "^6",
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    },
    "scripts": {
        "symfony-scripts": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-install-cmd": [
            "@symfony-scripts"
        ],
        "post-update-cmd": [
            "@symfony-scripts"
        ]
    },
    "config": {
        "sort-packages": true
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-bin-dir": "bin",
        "symfony-var-dir": "var",
        "symfony-web-dir": "web",
        "symfony-tests-dir": "tests",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": null
    }
}
J'ai aussi regardé du côté de mon phpunit.xml.dist
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
<?xml version="1.0" encoding="UTF-8"?>
 
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="vendor/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="KERNEL_CLASS" value="app/AppKernel" />
    </php>
 
    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
 
    <filter>
        <whitelist>
            <directory>src</directory>
            <exclude>
                <directory>src/*Bundle/Resources</directory>
                <directory>src/*/*Bundle/Resources</directory>
                <directory>src/*/Bundle/*Bundle/Resources</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>
Ces deux fichiers sont à la racine du projet.

J'ai aussi testé avec deux classes :
Email.php qui est localisé à la racine de src/ :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
<?php
declare(strict_types=1);
 
final class Email
{
    private $email;
 
    private function __construct(string $email)
    {
        $this->ensureIsValidEmail($email);
 
        $this->email = $email;
    }
 
    public static function fromString(string $email): self
    {
        return new self($email);
    }
 
    public function __toString(): string
    {
        return $this->email;
    }
 
    private function ensureIsValidEmail(string $email)
    {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            throw new InvalidArgumentException(
                sprintf(
                    '"%s" is not a valid email address',
                    $email
                )
            );
        }
    }
}
Et EmailTest.php, situé à la racine de tests/ :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
<?php
declare(strict_types=1);
 
use PHPUnit\Framework\TestCase;
 
final class EmailTest extends TestCase
{
    public function testCanBeCreatedFromValidEmailAddress()
    {
        $this->assertInstanceOf(
            Email::class,
            Email::fromString('user@example.com')
        );
    }
 
    public function testCannotBeCreatedFromInvalidEmailAddress()
    {
        $this->expectException(InvalidArgumentException::class);
 
        Email::fromString('invalid');
    }
 
    public function testCanBeUsedAsString()
    {
        $this->assertEquals(
            'user@example.com',
            Email::fromString('user@example.com')
        );
    }
}
Lorsque je lance mon run sur le fichier test, ça marche... Où que je bouge mon fichier test dans mon répertoire tests (si je crée des sous dossiers, etc...), le run va passer. Par contre, si je bouge mon fichier Email dans des sous-dossiers propres à src, là ça ne marche plus, il me dit ne plus trouver la classe Email..

Merci d'avance, je m'arrache les cheveux sur un problème tout nul mais ça me bloque tout pour mes tests...