Skip to content

Commit

Permalink
Statamic 5: Simplify TestCase (#267)
Browse files Browse the repository at this point in the history
* Simplify `TestCase`

* 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.

* doesn't look like we're using this method either

* The `ConsoleKernel` isn't needed
  • Loading branch information
duncanmcclean authored Apr 10, 2024
1 parent ebbdd24 commit ee259e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 100 deletions.
41 changes: 0 additions & 41 deletions tests/ConsoleKernel.php

This file was deleted.

69 changes: 10 additions & 59 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -118,22 +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.');
}

// 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');
Expand Down

0 comments on commit ee259e8

Please sign in to comment.