pest
pest copied to clipboard
Call to undefined method TestCase::get()
While running the tests I'm getting this error
ReflectionException: Call to undefined method PHPUnit\Framework\TestCase::get() at vendor/pestphp/pest-plugin-laravel/src/Http.php:189 at tests/Feature/HealthTest.php:8
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
<?php declare(strict_types=1);
/*
|--------------------------------------------------------------------------
| Test Case
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/
use PHPUnit\Framework\TestCase;
uses(TestCase::class)->in('Feature');
uses(TestCase::class)->in('Unit');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something()
{
// ..
}
HealthTest.php
<?php declare(strict_types=1);
//uses(Tests\TestCase::class);
use function Pest\Laravel\{get};
test('service healthy', function () {
$response = get('/');
$response->assertStatus(503);
});
test('pings', function (){
$res = get('/ping', ['Device-Id'=> '3984732984792420934231']);
$res->assertStatus(200);
});
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
color="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailures="false"
syntaxCheck="true">
<source>
<include>
<directory suffix=".php">.</directory>
</include>
</source>
<testsuites>
<testsuite name="Middlewares">
<directory phpVersion="8.3">./tests/Unit</directory>
</testsuite>
<testsuite name="Features">
<directory phpVersion="8.3">./tests/Feature</directory>
</testsuite>
</testsuites>
</phpunit>