Skip to content

Commit 751c7e8

Browse files
committed
add more tests
1 parent 5cc6840 commit 751c7e8

17 files changed

+240
-128
lines changed

src/BackpackServiceProvider.php

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public function publishFiles()
163163
*/
164164
public function setupRoutes(Router $router)
165165
{
166+
if (app()->runningUnitTests()) {
167+
$this->loadRoutesFrom(__DIR__.'/routes/backpack/testing.php');
168+
169+
return;
170+
}
166171
// by default, use the routes file provided in vendor
167172
$routeFilePathInUse = __DIR__.$this->routeFilePath;
168173

src/app/Http/Controllers/CrudController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ public function __construct()
3333
// It's done inside a middleware closure in order to have
3434
// the complete request inside the CrudPanel object.
3535
$this->middleware(function ($request, $next) {
36-
$this->crud = app()->make('crud');
36+
$this->crud = app('crud');
3737

3838
$this->crud->setRequest($request);
3939

4040
$this->setupDefaults();
4141
$this->setup();
4242
$this->setupConfigurationForCurrentOperation();
43-
4443
return $next($request);
4544
});
4645
}
@@ -96,6 +95,7 @@ protected function setupDefaults()
9695
protected function setupConfigurationForCurrentOperation()
9796
{
9897
$operationName = $this->crud->getCurrentOperation();
98+
9999
$setupClassName = 'setup'.Str::studly($operationName).'Operation';
100100

101101
/*
@@ -109,7 +109,7 @@ protected function setupConfigurationForCurrentOperation()
109109
* write is done after the default, so you can remove default settings, etc;
110110
*/
111111
$this->crud->applyConfigurationFromSettings($operationName);
112-
112+
113113
/*
114114
* THEN, run the corresponding setupXxxOperation if it exists.
115115
*/

src/app/Library/CrudPanel/CrudPanel.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ private function getSchema()
148148
* DEPRECATION NOTICE: This method is no longer used and will be removed in future versions of Backpack
149149
*
150150
* @deprecated
151+
* @codeCoverageIgnore
151152
*
152153
* @return bool
153154
*/
@@ -307,16 +308,18 @@ public function getFirstOfItsTypeInArray($type, $array)
307308
});
308309
}
309310

310-
// ------------
311-
// TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED IN THIS FILE
312-
// ------------
313-
//
314-
// TODO:
315-
// - figure out if they are really needed
316-
// - comments inside the function to explain how they work
317-
// - write docblock for them
318-
// - place in the correct section above (CREATE, READ, UPDATE, DELETE, ACCESS, MANIPULATION)
319-
311+
/**
312+
* TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED IN THIS FILE
313+
*
314+
* TODO:
315+
* - figure out if they are really needed
316+
* - comments inside the function to explain how they work
317+
* - write docblock for them
318+
* - place in the correct section above (CREATE, READ, UPDATE, DELETE, ACCESS, MANIPULATION)
319+
*
320+
* @deprecated
321+
* @codeCoverageIgnore
322+
*/
320323
public function sync($type, $fields, $attributes)
321324
{
322325
if (! empty($this->{$type})) {

src/app/Library/CrudPanel/Traits/HasViewNamespaces.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Backpack\CRUD\ViewNamespaces;
66

7+
/**
8+
* @codeCoverageIgnore
9+
*/
710
trait HasViewNamespaces
811
{
912
/**

src/app/Library/CrudPanel/Traits/SaveActions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function orderSaveActions(array $saveActions)
212212
/**
213213
* Return the ordered save actions to use in the crud panel.
214214
*
215-
* @return void
215+
* @return array
216216
*/
217217
public function getOrderedSaveActions()
218218
{
@@ -228,7 +228,7 @@ public function getOrderedSaveActions()
228228
/**
229229
* Returns the save actions that passed the visible callback.
230230
*
231-
* @return void
231+
* @return array
232232
*/
233233
public function getVisibleSaveActions()
234234
{

src/routes/backpack/testing.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Backpack Testing Routes
8+
|--------------------------------------------------------------------------
9+
| This routes are loaded only when running unit tests.
10+
|
11+
*/
12+
13+
Route::group([
14+
(array) config('backpack.base.web_middleware', 'web'),
15+
(array) config('backpack.base.middleware_key', 'admin'),
16+
'prefix' => config('backpack.base.route_prefix', 'admin'),
17+
],
18+
function () {
19+
Route::crud('users', 'Backpack\CRUD\Tests\Unit\Http\Controllers\UserCrudController');
20+
}
21+
);

0 commit comments

Comments
 (0)