After I installed laravel-dusk following the official Laravel documentation and run this command:
php artisan make:component CardComponentTest
Then try to run immediately:
php artisan dusk tests/Browser/Components/CardComponentTest.php
I get this error:
Class 'TestsBrowserComponentsCardComponentTest' could not be found in '/var/www/html/tests/Browser/Components/CardComponentTest.php'.
I tested file and path are correct:
ls -l /var/www/html/tests/Browser/Components/CardComponentTest.php
And it says:
-rw-r--r-- 1 djw djw 6917 Dec 3 11:25 /var/www/html/tests/Browser/Components/CardComponentTest.php
So it is exists and readable.
I checked the namespace in the file:
<?php
namespace TestsBrowserComponents;
It also looks good.
I checked the composer.json
and in this I have this section:
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
So the file exists, the namespace is good and the namespace is picked up in the composer.json.
I tried to run composer dump-autoload
too. All good.
Any ide what’s wrong whit this?
2
Answers
If you take a look at the documentation, the Component is not a test itself. Hence, you should not name the component "*Test" and you should not try to run the component like a dusk test.
You will use your component in your dusk test as described here:
https://laravel.com/docs/9.x/dusk#using-components
Components are for repeated actions, like selecting a date in a picker, which is then further used in your test case for example in a form or maybe some change in your UX happens that is assertable.
the error:
indicate you don’t have CardComponentTest test case. Because CardComponentTest is not test case but just an component/part of test.
As aless said, component is not a test itself. But if you really want to test
CardComponentTest
you can replaceto :
after you do that you can run
php artisan dusk tests/Browser/Components/CardComponentTest.php
, You just need to add test method first like. An example:But create test case in component folder is not best practice. You should create test case like official documentation said. Run
dusk:make
instead ofdusk:component
. An example:and now you can run