File tree Expand file tree Collapse file tree 7 files changed +106
-14
lines changed Expand file tree Collapse file tree 7 files changed +106
-14
lines changed Original file line number Diff line number Diff line change 2828 },
2929 "require-dev" : {
3030 "fzaninotto/faker" : " ^1.9" ,
31- "laravel/nova" : " 2 .*" ,
31+ "laravel/nova" : " 3 .*" ,
3232 "orchestra/testbench-browser-kit" : " ^5.0" ,
3333 "orchestra/testbench" : " ^5.0" ,
3434 "php-coveralls/php-coveralls" : " ^2.2" ,
Original file line number Diff line number Diff line change 11<?php namespace GeneaLabs \LaravelModelCaching \Tests ;
22
33use GeneaLabs \LaravelModelCaching \Providers \Service as LaravelModelCachingService ;
4- use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Providers \NovaServiceProvider ;
54
65trait CreatesApplication
76{
@@ -54,7 +53,6 @@ protected function getPackageProviders($app)
5453 {
5554 return [
5655 LaravelModelCachingService::class,
57- NovaServiceProvider::class,
5856 ];
5957 }
6058}
Original file line number Diff line number Diff line change 11<?php namespace GeneaLabs \LaravelModelCaching \Tests ;
22
3+ use Illuminate \Auth \Middleware \Authenticate ;
4+ use Laravel \Nova \Http \Middleware \Authorize ;
5+ use Laravel \Nova \Http \Middleware \BootTools ;
6+ use Laravel \Nova \Http \Middleware \DispatchServingNovaEvent ;
7+
38trait EnvironmentSetup
49{
510 protected function getEnvironmentSetUp ($ app )
Original file line number Diff line number Diff line change 11<?php namespace GeneaLabs \LaravelModelCaching \Tests \Feature \Nova ;
22
3- use GeneaLabs \LaravelModelCaching \Tests \FeatureTestCase ;
4-
5- class BelongsToManyTest extends FeatureTestCase
3+ class BelongsToManyTest extends NovaTestCase
64{
75 /** @group test */
8- public function testCacheCanBeDisabledOnModel ()
6+ public function testBasicNovaIndexRequest ()
97 {
10- dd ( );
11- $ result = $ this -> visit ( " /nova " );
8+ $ this -> getJson ( ' nova-api/authors ' );
9+ // $response->dump( );
1210
13- dd ($ result );
11+ $ this ->response ->assertStatus (200 )
12+ ->assertJsonCount (10 , 'resources ' );
1413 }
1514}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace GeneaLabs \LaravelModelCaching \Tests \Feature \Nova ;
4+
5+ use GeneaLabs \LaravelModelCaching \Tests \FeatureTestCase ;
6+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Nova \AuthorResource ;
7+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Providers \NovaServiceProvider ;
8+ use Illuminate \Contracts \Auth \Authenticatable ;
9+ use Illuminate \Testing \TestResponse ;
10+ use Laravel \Nova \Nova ;
11+ use Laravel \Nova \NovaCoreServiceProvider ;
12+
13+ abstract class NovaTestCase extends FeatureTestCase
14+ {
15+ /** @var TestResponse */
16+ protected $ response ;
17+
18+ protected $ authenticatedAs ;
19+
20+ public function setUp (): void
21+ {
22+ parent ::setUp ();
23+ Nova::$ tools = [];
24+ Nova::$ resources = [];
25+
26+ Nova::resources ([
27+ AuthorResource::class
28+ ]);
29+
30+ Nova::auth (function () {
31+ return true ;
32+ });
33+
34+ $ this ->authenticate ();
35+ }
36+
37+ protected function authenticate ()
38+ {
39+ $ this ->actingAs ($ this ->authenticatedAs = \Mockery::mock (Authenticatable::class));
40+
41+ $ this ->authenticatedAs ->shouldReceive ('getAuthIdentifier ' )->andReturn (1 );
42+ $ this ->authenticatedAs ->shouldReceive ('getKey ' )->andReturn (1 );
43+
44+ return $ this ;
45+ }
46+
47+ protected function getPackageProviders ($ app )
48+ {
49+ return array_merge (parent ::getPackageProviders ($ app ), [
50+ NovaCoreServiceProvider::class,
51+ \Laravel \Nova \NovaServiceProvider::class,
52+ NovaServiceProvider::class,
53+ ]);
54+ }
55+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace GeneaLabs \LaravelModelCaching \Tests \Fixtures \Nova ;
4+
5+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Author ;
6+ use Illuminate \Http \Request ;
7+ use Laravel \Nova \Fields \ID ;
8+ use Laravel \Nova \Fields \Text ;
9+
10+ class AuthorResource extends Resource
11+ {
12+ public static $ model = Author::class;
13+
14+ public static $ search = ['id ' ];
15+
16+ /**
17+ * @inheritDoc
18+ */
19+ public function fields (Request $ request )
20+ {
21+ return [
22+ ID ::make ('ID ' , 'id ' ),
23+
24+ Text::make ('Name ' , 'name ' ),
25+ ];
26+ }
27+
28+ public static function uriKey ()
29+ {
30+ return 'authors ' ;
31+ }
32+ }
Original file line number Diff line number Diff line change 11<?php namespace GeneaLabs \LaravelModelCaching \Tests \Fixtures \Providers ;
22
3- use App \User ;
43use Illuminate \Support \Facades \Gate ;
54use Laravel \Nova \Nova ;
65use Laravel \Nova \NovaApplicationServiceProvider ;
@@ -30,8 +29,7 @@ protected function routes()
3029 {
3130 Nova::routes ()
3231 ->withAuthenticationRoutes ()
33- ->withPasswordResetRoutes ()
34- ->register ();
32+ ->withPasswordResetRoutes ();
3533 }
3634
3735 /**
@@ -43,7 +41,7 @@ protected function routes()
4341 */
4442 protected function gate ()
4543 {
46- Gate::define ('viewNova ' , function (User $ user ) {
44+ Gate::define ('viewNova ' , function () {
4745 return true ;
4846 });
4947 }
@@ -78,4 +76,9 @@ public function register()
7876 {
7977 //
8078 }
79+
80+ protected function resources ()
81+ {
82+ // See NovaTestCase
83+ }
8184}
You can’t perform that action at this time.
0 commit comments