Hi,
I'm setting up an environment to test a new package for a newsletter.
I need to use Orchestra to run tests on the package but when I try to vendor/bin/phpunit vendor/agpretto/newsletter I get a PHP Fatal error: Class 'Agpretto\Newsletter\Tests\Integration\IntegrationTestCase' not found in /var/www/vhosts/xxx.com/vendor/agpretto/newsletter/tests/Integration/NewsletterTest.php on line 7
It's strange because with a normal PHPUnit\TestCase the test runs but obviously doesn't load migrations ect.. ect..
The structure of the folder is similar to the Laravel Cashier package. The config.json is setup:
"require-dev": {
"mockery/mockery": "^1.0",
"orchestra/testbench": "^3.8|^4.0|^5.0",
"phpunit/phpunit": "^7.5|^8.0"
},
"autoload": {
"psr-4": {
"Agpretto\Newsletter\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Agpretto\Newsletter\Tests\": "tests/"
}
},
also phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
inside /tests folder I have a test case:
<?php
namespace Agpretto\Newsletter\Tests;
use Agpretto\Newsletter\NewsletterServiceProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
abstract class TestCase extends OrchestraTestCase
{
protected function getPackageProviders($app)
{
return [NewsletterServiceProvider::class];
}
}
then inside /tests/Integration I have the IntegrationTestCase:
<?php
namespace Agpretto\Newsletter\Tests\Integration;
use Agpretto\Newsletter\Tests\TestCase;
use Illuminate\Database\Eloquent\Model as Eloquent;
abstract class IntegrationTestCase extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Eloquent::unguard();
$this->loadLaravelMigrations();
$this->artisan('migrate')->run();
}
}
and finally the test to be performed:
<?php
namespace Agpretto\Newsletter\Tests\Integration;
use Agpretto\Newsletter\Newsletter;
class NewsletterTest extends IntegrationTestCase
{
public function test_Newsletter_CanBeCreated()
{
$newsletter = new Newsletter();
$newsletter = $newsletter->subscribe('[email protected]');
$this->assertEquals(1, count(Newsletter::all()));
}
}
simple.. but It doesn't work.. I try with composer dump-autoload, I installed the Orchestra package on the main laravel installation but still don't work. Where can I found a possible error? How can I setup my environment?
Thank you