-
-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call to undefined method TestCase::get() #1192
Comments
Yep, I've just run into this issue too. I switched back to phpunit. The demo tests (unit and feature) are working correctly using that. |
You guys still facing this issue? typically just means you forgot to use the "uses" function. |
@nunomaduro Sadly I gave up trying, but at the time, yes it was still not working for me. I did add that "uses" function. As mentioned above, unit tests worked but feature tests would not. Strange. |
I am facing this issue and I have no idea how to tackle it. Environment:
I tried the solutions suggested here but no luck either: #415 And finally, I downgraded in case the problem was due to a change in current versions. I installed Pest v2.34.0 and v2v.33.0 but the problem is still with us. 👎 |
Hi, Ok I got a chance to try it again. I installed all the latest versions of everything today. Sure enough, I still got that same error I started experimenting and found that is did work if I swapped out the BaseTestCase (in TestCase.php): <?php
namespace Tests;
//use PHPUnit\Framework\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
} ... and now it works as documented on https://laravel.com/docs/11.x/http-tests ....
The question is: what are the implications of using that as the BaseTestCase instead? I initially wondered if it was because phpunit was no longer a dev dependency (based on the https://pestphp.com/docs/installation which says to remove it). However it is still in /vendor, so the files do exist. |
For a Laravel application, that is the testcase class you are meant to use (for tests that require the framework). So everything is working as expected. If you extend the PHPUnit testcase, it won't have any Laravel functionality, so the I'm unsure why you ended up with a |
@owenvoke Ah, ok, I wondered if it was something like that. Yep, that's the TestCase.php that command generates. I just renamed the
The created
So that appears to explain what is happening and why feature tests don't work. |
I don't know how it works internally but I'd assume it is not correctly detecting Laravel during init and so it's defaulting to the phpunit TestCase.php. Which then causes the undefined error. https://github.com/pestphp/pest/blob/2.x/stubs/init-laravel/TestCase.php.stub |
While running the tests I'm getting this error
I tried many things but nothing works. My Unit tests run correctly with no issue. there is no get, post delete request. but my feature tests don't run at all. I tried searching for solution for days and now I'm posting my issue here. Can anyone help me identify the cause and how can I solve it?
Directory Structure
|---tests
|--- Unit
|----Features
|---------HealthTest.php
|----Pest.php
|----TestCase.php
|-phpunit.xml
Pest.php
HealthTest.php
phpunit.xml
The text was updated successfully, but these errors were encountered: