From 1f850ce1ffc5ec1a5ff5145e5d00af50297a236a Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 10 Apr 2024 15:39:55 +0100 Subject: [PATCH 1/4] Simplify `TestCase` --- tests/TestCase.php | 53 +++++++++------------------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 3bf34637..68092272 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,73 +3,40 @@ namespace Tests; use Illuminate\Foundation\Testing\RefreshDatabase; +use Statamic\Eloquent\ServiceProvider; +use Statamic\Extend\AddonTestCase; +use Statamic\Facades\Site; -abstract class TestCase extends \Orchestra\Testbench\TestCase +abstract class TestCase extends AddonTestCase { use RefreshDatabase; + protected string $addonServiceProvider = ServiceProvider::class; + protected $shouldFakeVersion = true; protected $shouldPreventNavBeingBuilt = true; protected $shouldUseStringEntryIds = false; - protected function setUp(): void - { - require_once __DIR__.'/ConsoleKernel.php'; - - parent::setUp(); - - $uses = array_flip(class_uses_recursive(static::class)); - - if ($this->shouldFakeVersion) { - \Facades\Statamic\Version::shouldReceive('get')->zeroOrMoreTimes()->andReturn('3.0.0-testing'); - $this->addToAssertionCount(-1); // Dont want to assert this - } - } - - public function tearDown(): void - { - parent::tearDown(); - } - - protected function getPackageProviders($app) - { - return [ - \Statamic\Providers\StatamicServiceProvider::class, - \Statamic\Eloquent\ServiceProvider::class, - \Wilderborn\Partyline\ServiceProvider::class, - ]; - } - - protected function getPackageAliases($app) - { - return ['Statamic' => 'Statamic\Statamic']; - } - protected function resolveApplicationConfiguration($app) { parent::resolveApplicationConfiguration($app); - $configs = [ - 'eloquent-driver', - ]; - - foreach ($configs as $config) { - $app['config']->set("statamic.$config", require (__DIR__."/../config/{$config}.php")); - } + $app['config']->set('statamic.eloquent-driver', require (__DIR__.'/../config/eloquent-driver.php')); } protected function getEnvironmentSetUp($app) { + parent::getEnvironmentSetUp($app); + // We changed the default sites setup but the tests assume defaults like the following. - \Statamic\Facades\Site::setSites([ + Site::setSites([ 'en' => ['name' => 'English', 'locale' => 'en_US', 'url' => 'http://localhost/'], ]); $app['config']->set('auth.providers.users.driver', 'statamic'); $app['config']->set('statamic.stache.watcher', false); - $app['config']->set('statamic.users.repository', 'file'); $app['config']->set('statamic.stache.stores.users', [ 'class' => \Statamic\Stache\Stores\UsersStore::class, 'directory' => __DIR__.'/__fixtures__/users', From 2eccd194fc5796c3da0b8c5173b8e0d458415a50 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 10 Apr 2024 15:41:21 +0100 Subject: [PATCH 2/4] Remove `partialMock` method from `TestCase` I'm not sure which "earlier versions of Laravel" this is referring to but the test suite seems to pass without it so I presume it's no longer needed. --- tests/TestCase.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 68092272..27d4b4fe 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -92,15 +92,6 @@ protected function assertContainsHtml($string) $this->assertNotEmpty($matches, 'Failed asserting that string contains HTML.'); } - // This method is unavailable on earlier versions of Laravel. - public function partialMock($abstract, ?\Closure $mock = null) - { - $mock = \Mockery::mock(...array_filter(func_get_args()))->makePartial(); - $this->app->instance($abstract, $mock); - - return $mock; - } - protected function isUsingSqlite() { $connection = config('database.default'); From 4b01c9dd60e76c8cb9815524f97a05fe6afc310d Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 10 Apr 2024 15:42:35 +0100 Subject: [PATCH 3/4] doesn't look like we're using this method either --- tests/TestCase.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 27d4b4fe..2b3a7d17 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -85,13 +85,6 @@ protected function assertEveryItemIsInstanceOf($class, $items) $this->assertEquals(count($items), $matches, 'Failed asserting that every item is an instance of '.$class); } - protected function assertContainsHtml($string) - { - preg_match('/<[^<]+>/', $string, $matches); - - $this->assertNotEmpty($matches, 'Failed asserting that string contains HTML.'); - } - protected function isUsingSqlite() { $connection = config('database.default'); From ca34bd218a4809c1989551ec3e800741015d240f Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 10 Apr 2024 15:46:09 +0100 Subject: [PATCH 4/4] The `ConsoleKernel` isn't needed --- tests/ConsoleKernel.php | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 tests/ConsoleKernel.php diff --git a/tests/ConsoleKernel.php b/tests/ConsoleKernel.php deleted file mode 100644 index ddd12f2d..00000000 --- a/tests/ConsoleKernel.php +++ /dev/null @@ -1,41 +0,0 @@ -command('inspire') - // ->hourly(); - } - - /** - * Register the commands for the application. - * - * @return void - */ - protected function commands() - { - // $this->load(__DIR__.'/Commands'); - - // require base_path('routes/console.php'); - } -}