Skip to content

Commit d5c930a

Browse files
committed
Update Nova test setup.
1 parent b3ed791 commit d5c930a

10 files changed

+109
-127
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=7.2.5",
18+
"php": ">=7.3",
1919
"genealabs/laravel-pivot-events": "^0.3.0",
2020
"illuminate/cache": "^7.0",
2121
"illuminate/config": "^7.0",
@@ -27,17 +27,17 @@
2727
"predis/predis": "^1.1"
2828
},
2929
"require-dev": {
30+
"doctrine/dbal": "^2.10",
3031
"fzaninotto/faker": "^1.9",
31-
"laravel/nova": "3.*",
32+
"laravel/nova": "^3.0",
3233
"orchestra/testbench-browser-kit": "^5.0",
3334
"orchestra/testbench": "^5.0",
3435
"php-coveralls/php-coveralls" : "^2.2",
3536
"phpmd/phpmd": "^2.7",
3637
"phpunit/phpunit": "^8.0",
3738
"sebastian/phpcpd": "^5.0",
3839
"squizlabs/php_codesniffer": "^3.4",
39-
"symfony/thanks": "^1.2",
40-
"doctrine/dbal": "^2.10"
40+
"symfony/thanks": "^1.2"
4141
},
4242
"autoload": {
4343
"psr-4": {

phpunit.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
stopOnFailure="true"
1212
>
1313
<testsuites>
14-
<testsuite name="Setup">
15-
<directory>./tests/AlwaysRunFirstTest.php</directory>
16-
</testsuite>
1714
<testsuite name="Feature">
1815
<directory suffix="Test.php">./tests/Feature</directory>
1916
</testsuite>
2017
<testsuite name="Integration">
2118
<directory suffix="Test.php">./tests/Integration</directory>
2219
</testsuite>
20+
<testsuite name="Nova">
21+
<directory suffix="Test.php">./tests/Nova</directory>
22+
</testsuite>
2323
</testsuites>
2424
<filter>
2525
<whitelist processUncoveredFilesFromWhitelist="false">

tests/CreatesApplication.php

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests;
22

33
use GeneaLabs\LaravelModelCaching\Providers\Service as LaravelModelCachingService;
4+
use Illuminate\Auth\Middleware\Authenticate;
5+
use Illuminate\Support\Facades\Artisan;
6+
use Laravel\Nova\Http\Middleware\Authorize;
7+
use Laravel\Nova\Http\Middleware\BootTools;
8+
use Laravel\Nova\Http\Middleware\DispatchServingNovaEvent;
49

510
trait CreatesApplication
611
{
7-
use EnvironmentSetup;
8-
use MigrateBaselineDatabase;
12+
private static $baseLineDatabaseMigrated = false;
913

1014
protected $cache;
1115
protected $testingSqlitePath;
@@ -24,24 +28,26 @@ protected function cache()
2428
public function setUp() : void
2529
{
2630
parent::setUp();
31+
2732
$this->setUpBaseLineSqlLiteDatabase();
2833

2934
$databasePath = __DIR__ . "/database";
3035
$this->testingSqlitePath = "{$databasePath}/";
3136
$baselinePath = "{$databasePath}/baseline.sqlite";
3237
$testingPath = "{$databasePath}/testing.sqlite";
3338

34-
! file_exists($testingPath) ?: unlink($testingPath);
39+
! file_exists($testingPath)
40+
?: unlink($testingPath);
3541
copy($baselinePath, $testingPath);
3642

3743
require(__DIR__ . '/routes/web.php');
3844

3945
$this->withFactories(__DIR__ . '/database/factories');
46+
4047
view()->addLocation(__DIR__ . '/resources/views', 'laravel-model-caching');
4148

4249
$this->cache = app('cache')
4350
->store(config('laravel-model-caching.store'));
44-
4551
$this->cache()->flush();
4652
}
4753

@@ -54,4 +60,82 @@ protected function getPackageProviders($app)
5460
LaravelModelCachingService::class,
5561
];
5662
}
63+
64+
public function setUpBaseLineSqlLiteDatabase()
65+
{
66+
if (self::$baseLineDatabaseMigrated) {
67+
return;
68+
}
69+
70+
self::$baseLineDatabaseMigrated = true;
71+
72+
$file = __DIR__ . '/database/baseline.sqlite';
73+
$this->app['config']->set('database.default', 'baseline');
74+
$this->app['config']->set('database.connections.baseline', [
75+
'driver' => 'sqlite',
76+
"url" => null,
77+
'database' => $file,
78+
'prefix' => '',
79+
"foreign_key_constraints" => false,
80+
]);
81+
82+
! file_exists($file)
83+
?: unlink($file);
84+
touch($file);
85+
86+
$this->withFactories(__DIR__ . '/database/factories');
87+
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
88+
89+
Artisan::call('db:seed', [
90+
'--class' => 'DatabaseSeeder',
91+
'--database' => 'baseline',
92+
]);
93+
94+
$this->app['config']->set('database.default', 'testing');
95+
}
96+
97+
protected function getEnvironmentSetUp($app)
98+
{
99+
$app['config']->set('database.default', 'testing');
100+
$app['config']->set('database.connections.testing', [
101+
'driver' => 'sqlite',
102+
'database' => __DIR__ . '/database/testing.sqlite',
103+
'prefix' => '',
104+
"foreign_key_constraints" => false,
105+
]);
106+
$app['config']->set('database.redis.client', "predis");
107+
$app['config']->set('database.redis.cache', [
108+
'host' => env('REDIS_HOST', '127.0.0.1'),
109+
'port' => env('REDIS_PORT', 6379),
110+
]);
111+
$app['config']->set('database.redis.default', [
112+
'host' => env('REDIS_HOST', '127.0.0.1'),
113+
'port' => env('REDIS_PORT', 6379),
114+
]);
115+
$app['config']->set('database.redis.model-cache', [
116+
'host' => env('REDIS_HOST', '127.0.0.1'),
117+
'password' => env('REDIS_PASSWORD', null),
118+
'port' => env('REDIS_PORT', 6379),
119+
'database' => 1,
120+
]);
121+
$app['config']->set('cache.stores.model', [
122+
'driver' => 'redis',
123+
'connection' => 'model-cache',
124+
]);
125+
$app['config']->set('laravel-model-caching.store', 'model');
126+
$app['config']->set("nova", [
127+
'name' => 'Nova Site',
128+
'url' => env('APP_URL', '/'),
129+
'path' => '/nova',
130+
'guard' => env('NOVA_GUARD', null),
131+
'middleware' => [
132+
'web',
133+
Authenticate::class,
134+
DispatchServingNovaEvent::class,
135+
BootTools::class,
136+
Authorize::class,
137+
],
138+
'pagination' => 'simple',
139+
]);
140+
}
57141
}

tests/EnvironmentSetup.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

tests/MigrateBaselineDatabase.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/Feature/Nova/BelongsToManyTest.php renamed to tests/Nova/BelongsToManyTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
44
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store;
5+
use GeneaLabs\LaravelModelCaching\Tests\NovaTestCase;
56

6-
/** @group nova */
77
class BelongsToManyTest extends NovaTestCase
88
{
99
public function testAttachRelationFlushesCache()
1010
{
1111
$beforeStore = Store::with(['books'])->get()->first();
1212
$beforeBooks = $beforeStore->books;
1313

14-
/** @var Book $beforeBook */
1514
$beforeBook = $beforeStore->books->first()->replicate();
1615
$beforeBook->title = 'new foo';
1716
$beforeBook->save();
@@ -37,10 +36,7 @@ public function testAttachRelationFlushesCache()
3736

3837
public function testDetachRelationFlushesCache()
3938
{
40-
/** @var Store $store */
4139
$store = Store::with(['books'])->get()->first();
42-
43-
/** @var Book $beforeBook */
4440
$newBook = $store->books->first()->replicate();
4541
$newBook->title = 'new foo';
4642
$newBook->save();

tests/Feature/Nova/CreateTest.php renamed to tests/Nova/CreateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Feature\Nova;
22

33
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4+
use GeneaLabs\LaravelModelCaching\Tests\NovaTestCase;
45

5-
/** @group nova */
66
class CreateTest extends NovaTestCase
77
{
88
public function testCreateFlushesCacheForModel()

tests/Feature/Nova/DeleteTest.php renamed to tests/Nova/DeleteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Feature\Nova;
22

33
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4+
use GeneaLabs\LaravelModelCaching\Tests\NovaTestCase;
45

5-
/** @group nova */
66
class DeleteTest extends NovaTestCase
77
{
88
public function testDeleteFlushesCacheForModel()

tests/Feature/Nova/UpdateTest.php renamed to tests/Nova/UpdateTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Feature\Nova;
22

33
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4+
use GeneaLabs\LaravelModelCaching\Tests\NovaTestCase;
45

5-
/** @group nova */
66
class UpdateTest extends NovaTestCase
77
{
88
public function testUpdateFlushesCacheForModel()
99
{
1010
$beforeAuthors = (new Author)->get();
11-
12-
/** @var Author $author */
1311
$author = $beforeAuthors->first();
1412

1513
$this->putJson('nova-api/authors/' . $author->id, [
@@ -23,7 +21,6 @@ public function testUpdateFlushesCacheForModel()
2321
$this->assertCount(10, $beforeAuthors);
2422
$this->assertCount(10, $authors);
2523

26-
/** @var Author $updatedAuthor */
2724
$updatedAuthor = $authors->first();
2825
$this->assertTrue($updatedAuthor->is($author));
2926
$this->assertSame('foo', $updatedAuthor->name);

tests/Feature/Nova/NovaTestCase.php renamed to tests/NovaTestCase.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
<?php
22

3-
namespace GeneaLabs\LaravelModelCaching\Tests\Feature\Nova;
3+
namespace GeneaLabs\LaravelModelCaching\Tests;
44

5-
use GeneaLabs\LaravelModelCaching\Tests\FeatureTestCase;
65
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Nova\AuthorResource;
76
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Nova\BookResource;
87
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Nova\StoreResource;
98
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Providers\NovaServiceProvider;
109
use Illuminate\Contracts\Auth\Authenticatable;
11-
use Illuminate\Testing\TestResponse;
1210
use Laravel\Nova\Nova;
1311
use Laravel\Nova\NovaCoreServiceProvider;
1412

1513
abstract class NovaTestCase extends FeatureTestCase
1614
{
17-
/** @var TestResponse */
1815
protected $response;
1916

2017
protected $authenticatedAs;
2118

2219
public function setUp(): void
2320
{
2421
parent::setUp();
22+
2523
Nova::$tools = [];
2624
Nova::$resources = [];
2725

@@ -50,10 +48,13 @@ protected function authenticate()
5048

5149
protected function getPackageProviders($app)
5250
{
53-
return array_merge(parent::getPackageProviders($app), [
54-
NovaCoreServiceProvider::class,
55-
\Laravel\Nova\NovaServiceProvider::class,
56-
NovaServiceProvider::class,
57-
]);
51+
return array_merge(
52+
parent::getPackageProviders($app),
53+
[
54+
NovaCoreServiceProvider::class,
55+
\Laravel\Nova\NovaServiceProvider::class,
56+
NovaServiceProvider::class,
57+
]
58+
);
5859
}
5960
}

0 commit comments

Comments
 (0)