Class "..." not found in tests

Im using Pest to do some testing, however, my classes cannot be found. In: tests/ I have a test file, that includes the following code:
<?php

use TheThunderTurner\FilamentLatex\Database\Factories\FilamentLatexFactory;
use TheThunderTurner\FilamentLatex\Resources\FilamentLatexResource;

use function Pest\Livewire\livewire;


it('can render LaTeX List', function () {
$record = FilamentLatexFactory::factory()->create();

livewire(FilamentLatexResource\Pages\ViewFilamentLatex::class, ['record' => $record])->assertSuccessful();
});
<?php

use TheThunderTurner\FilamentLatex\Database\Factories\FilamentLatexFactory;
use TheThunderTurner\FilamentLatex\Resources\FilamentLatexResource;

use function Pest\Livewire\livewire;


it('can render LaTeX List', function () {
$record = FilamentLatexFactory::factory()->create();

livewire(FilamentLatexResource\Pages\ViewFilamentLatex::class, ['record' => $record])->assertSuccessful();
});
When running pest, I get the error Class "TheThunderTurner\FilamentLatex\Database\Factories\FilamentLatexFactory" not found. Why is it not found? Because the test file doesnt have a namespace? What am I missing? Thanks
6 Replies
Matthew
MatthewOP4mo ago
Important note: These tests are for a plugin!
Dennis Koch
Dennis Koch4mo ago
Can’t compare right now but might be good to see your test setup. TestCase, maybe PHPUnit.xml
awcodes
awcodes4mo ago
Are you running the test in the package or trying to run it from your app? I assume from inside the package in which case you need to manually add them to the autoloader. For example:
"autoload-dev": {
"psr-4": {
"Awcodes\\BadgeableColumn\\Tests\\": "tests/src",
"Awcodes\\BadgeableColumn\\Tests\\Database\\Factories\\": "tests/database/factories"
}
},
"autoload-dev": {
"psr-4": {
"Awcodes\\BadgeableColumn\\Tests\\": "tests/src",
"Awcodes\\BadgeableColumn\\Tests\\Database\\Factories\\": "tests/database/factories"
}
},
Factories in packages can get really weird since they don’t conform to Laravel’s default auto discovery for factories. So it all needs to be more manual in a package. Can also try this in the TestCase:
protected function setUp(): void
{
parent::setUp();

Factory::guessFactoryNamesUsing(
fn (string $modelName) => 'Awcodes\\Curator\\Database\\Factories\\' . class_basename($modelName) . 'Factory'
);
}
protected function setUp(): void
{
parent::setUp();

Factory::guessFactoryNamesUsing(
fn (string $modelName) => 'Awcodes\\Curator\\Database\\Factories\\' . class_basename($modelName) . 'Factory'
);
}
Matthew
MatthewOP4mo ago
Apologies for the late reply. You can have a look at my plugin here
GitHub
GitHub - thethunderturner/filament-latex: LaTeX editor built for fi...
LaTeX editor built for filamentphp. Contribute to thethunderturner/filament-latex development by creating an account on GitHub.
Matthew
MatthewOP4mo ago
Im running it from the package using composer pest I will give it a try What about filament components? Like for example resources, pages etc? Because if I make a test case that checks if the resource page asserts successful, I just get an error that its not found
awcodes
awcodes4mo ago
What branch in your repo are you working on? Where are your tests. One thing I’m not seeing is an AdminServiceProvider. That’s going to be required to mimic a panel. The filament test suite is a great place to source dive as well.

Did you find this page helpful?