-
Hi there! We’re trying to setup basic Pest tests with Laravel plugin, and cannot run any of composer.json: {
// ... ... ...
"require-dev": {
// ... ... ...
"pestphp/pest": "^2.19",
"pestphp/pest-plugin-laravel": "^2.2",
"roave/security-advisories": "dev-latest",
"spatie/laravel-ignition": "^2.2",
// ... ... ...
},
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true,
"pestphp/pest-plugin": true
}
},
// ... ... ...
} phpunit.xml: <?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<coverage/>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
</phpunit> tests/Pest.php: <?php
/*
|--------------------------------------------------------------------------
| 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.
|
*/
//uses(Tests\TestCase::class)->in('Feature');
//uses(Tests\TestCase::class)->in('Unit');
//uses(Tests\TestCase::class)->in(__DIR__);
uses(Tests\TestCase::class);
/*
|--------------------------------------------------------------------------
| 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()
{
// ..
} tests/TestCase.php: <?php
namespace Tests;
use PHPUnit\Framework\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
} tests/Unit/ExampleTest.php: <?php
test('example', function () {
expect(true)->toBeTrue();
});
it('has home')
->get('http://localhost/')
->assertStatus(200);
I have tried all of the combinations: //uses(Tests\TestCase::class)->in('Feature');
//uses(Tests\TestCase::class)->in('Unit');
//uses(Tests\TestCase::class)->in(__DIR__);
uses(Tests\TestCase::class); The only difference is the error message:
Could anybody please help us with that? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Your Replace the use of <?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
} |
Beta Was this translation helpful? Give feedback.
Are you adding tests to an existing Laravel app? 🤔 There should be an existing
TestCase.php
which looks like this:And a
CreatesApplication.php
which looks like this:Try using those files, and it should all…