Jan 10, 2020
0
Level 1
PHP Fatal error: Cannot declare class SeasonFactory, because the name is already in use in /database/factories/SeasonFactory.php on line 8
Laravel Framework 6.10.1
PHPUnit 8.5.2
I have a factory class as follows:
SeasonFactory.php
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Season;
use App\Contestant;
class SeasonFactory
{
public $contestantsCount = 0;
public function withContestants($count)
{
$this->contestantsCount = $count;
return $this;
}
public function create()
{
$season = factory(Season::class)->create();
factory(Contestant::class, $this->contestantsCount)->create([
'season_id' => $season->id,
]);
return $season;
}
}
I'm trying to execute a test case as follows
public function will_example_work() {
$season = app(SeasonFactory::class)
->withContestants(20)
->create();
}
It gives the following error: PHP Fatal error: Cannot declare class SeasonFactory, because the name is already in use in /database/factories/SeasonFactory.php on line 8
How can I fix this issue?
Note: this command I have executed already: php artisan clear-compiled && php artisan cache:clear && php artisan view:clear && php artisan route:clear && composer dump-autoload && php artisan optimize && php artisan config:clear
Please or to participate in this conversation.