BaseMenuTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 7
c 5
b 0
f 3
lcom 1
cbo 7
dl 0
loc 126
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A getPackageProviders() 0 10 1
A getPackageAliases() 0 7 1
A getEnvironmentSetUp() 0 11 1
A resetDatabase() 0 20 1
A createMenu() 0 13 1
B createMenuItemForMenu() 0 27 1
1
<?php namespace Modules\Menu\Tests;
2
3
use Faker\Factory;
4
use Illuminate\Contracts\Console\Kernel;
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Str;
7
use Maatwebsite\Sidebar\SidebarServiceProvider;
8
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
9
use Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider;
10
use Modules\Core\Providers\CoreServiceProvider;
11
use Modules\Menu\Providers\MenuServiceProvider;
12
use Modules\Menu\Repositories\MenuItemRepository;
13
use Modules\Menu\Repositories\MenuRepository;
14
use Orchestra\Testbench\TestCase;
15
use Pingpong\Modules\ModulesServiceProvider;
16
17
abstract class BaseMenuTest extends TestCase
18
{
19
    /**
20
     * @var MenuRepository
21
     */
22
    protected $menu;
23
    /**
24
     * @var MenuItemRepository
25
     */
26
    protected $menuItem;
27
28
    /**
29
     *
30
     */
31
    public function setUp()
32
    {
33
        parent::setUp();
34
35
        $this->resetDatabase();
36
37
        $this->menu = app(MenuRepository::class);
38
        $this->menuItem = app(MenuItemRepository::class);
39
    }
40
41
    protected function getPackageProviders($app)
42
    {
43
        return [
44
            ModulesServiceProvider::class,
45
            CoreServiceProvider::class,
46
            MenuServiceProvider::class,
47
            LaravelLocalizationServiceProvider::class,
48
            SidebarServiceProvider::class,
49
        ];
50
    }
51
52
    protected function getPackageAliases($app)
53
    {
54
        return [
55
            'Eloquent' => Model::class,
56
            'LaravelLocalization' => LaravelLocalization::class,
57
        ];
58
    }
59
60
    protected function getEnvironmentSetUp($app)
61
    {
62
        $app['path.base'] = __DIR__ . '/..';
63
        $app['config']->set('database.default', 'sqlite');
64
        $app['config']->set('database.connections.sqlite', array(
65
            'driver' => 'sqlite',
66
            'database' => ':memory:',
67
            'prefix' => '',
68
        ));
69
        $app['config']->set('translatable.locales', ['en', 'fr']);
70
    }
71
72
    private function resetDatabase()
73
    {
74
        // Relative to the testbench app folder: vendors/orchestra/testbench/src/fixture
75
        $migrationsPath = 'Database/Migrations';
76
        $artisan = $this->app->make(Kernel::class);
77
        // Makes sure the migrations table is created
78
        $artisan->call('migrate', [
79
            '--database' => 'sqlite',
80
            '--path'     => $migrationsPath,
81
        ]);
82
        // We empty all tables
83
        $artisan->call('migrate:reset', [
84
            '--database' => 'sqlite',
85
        ]);
86
        // Migrate
87
        $artisan->call('migrate', [
88
            '--database' => 'sqlite',
89
            '--path'     => $migrationsPath,
90
        ]);
91
    }
92
93
    public function createMenu($name, $title)
94
    {
95
        $data = [
96
            'name' => $name,
97
            'primary' => true,
98
            'en' => [
99
                'title' => $title,
100
                'status' => 1,
101
            ],
102
        ];
103
104
        return $this->menu->create($data);
105
    }
106
107
    /**
108
     * Create a menu item for the given menu and position
109
     *
110
     * @param  int    $menuId
111
     * @param  int    $position
112
     * @param  null   $parentId
113
     * @return object
114
     */
115
    protected function createMenuItemForMenu($menuId, $position, $parentId = null)
116
    {
117
        $faker = Factory::create();
118
119
        $title = implode(' ', $faker->words(3));
0 ignored issues
show
Unused Code introduced by
The call to Generator::words() has too many arguments starting with 3.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
120
        $slug = Str::slug($title);
121
122
        $data = [
123
            'menu_id' => $menuId,
124
            'position' => $position,
125
            'parent_id' => $parentId,
126
            'target' => '_self',
127
            'module_name' => 'blog',
128
            'en' => [
129
                'status' => 1,
130
                'title' => $title,
131
                'uri' => $slug,
132
            ],
133
            'fr' => [
134
                'status' => 1,
135
                'title' => $title,
136
                'uri' => $slug,
137
            ],
138
        ];
139
140
        return $this->menuItem->create($data);
141
    }
142
}
143