Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ryan.mills's avatar

PHP Testing Jargon Episode 5 - Class not found

I'm stuck around two minutes in with the following error. VSCode indicates that App\Quiz is imported in QuizTest.php, but running both vendor/bin/phpunit tests --colors and vendor/bin/phpunit tests/QuizTest.php --colors gives me the same error. Any thoughts on what's going wrong?

There was 1 error:

1) Tests\QuizTest::it_consists_of_questions
Error: Class 'App\Quiz' not found

C:\testing-jargon\example-2\tests\QuizTest.php:13

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

QuizTest.php

<?php

namespace Tests;

use App\Quiz;
use PHPUnit\Framework\TestCase;

class QuizTest extends TestCase
{
	/** @test */
	public function it_consists_of_questions()
	{
		$quiz = new Quiz;

		$quiz->addQuestion(
			new Question('What is 2 + 2?', 4)
		);

		$this->assertCount(1, $quiz->questions());
	}
}

Quiz.php

<?php

namespace App;

class Quiz
{

}
0 likes
5 replies
bugsysha's avatar

You've forgotten to show the contents of your composer.json file.

1 like
ryan.mills's avatar

Sorry about that. composer.json

{
    "name": "/example-2",
    "authors": [
        {
            "name": "My Name",
            "email": "[email protected]"
        }
    ],
    "require": {
        "phpunit/phpunit": "^9.5"
    }
}
ryan.mills's avatar

Thanks, Jeffrey. After bugshaya's response, I realized what I needed to do and gave it a go, but I didn't run composer dump-autoload.

1 like
bugsysha's avatar

Best answer award stollen by the master. I guess I can live with that.

1 like

Please or to participate in this conversation.