You've forgotten to show the contents of your composer.json file.
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
{
}
You need to tell Composer how to autoload your src files. Merge the following into your composer.json file.
{
"autoload": {
"psr-4": {
"App\\": "src/",
}
}
}
And then run composer dump-autoload from the Terminal.
And don’t forget to compare your code against the lesson’s source code.
https://github.com/laracasts/PHP-Testing-Jargon/commit/91ca56f82eefe4dc82e3577882318fa8d851f24d
Please or to participate in this conversation.