BaseTestCase::getEnvironmentSetUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace Moo\FlashCard\Tests;
4
5
use Moo\FlashCard\Entity\Card;
6
use Moo\FlashCard\Entity\Category;
7
use Moo\FlashCard\ServiceProvider;
8
use Orchestra\Testbench\TestCase as Orchestra;
9
use Spatie\QueryBuilder\QueryBuilderServiceProvider;
10
11
abstract class BaseTestCase extends Orchestra
12
{
13
    protected function getPackageProviders($app)
14
    {
15
        return [ServiceProvider::class, QueryBuilderServiceProvider::class];
16
    }
17
    /**
18
     * Define environment setup.
19
     *
20
     * @param \Illuminate\Foundation\Application $app
21
     *
22
     * @return void
23
     */
24
    protected function getEnvironmentSetUp($app)
25
    {
26
        $app['config']->set('database.default', 'testbench');
27
        $app['config']->set('database.connections.testbench', [
28
            'driver'   => 'sqlite',
29
            'database' => ':memory:',
30
            'prefix'   => '',
31
        ]);
32
    }
33
34
    protected function setUp()
35
    {
36
        parent::setUp();
37
38
        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
39
40
        include __DIR__ . '/../routes/api.php';
41
42
        $this->artisan('migrate', ['--database' => 'testbench']);
43
    }
44
45
    protected function card(array $args = [])
46
    {
47
        $categoryId = '';
48
        if (!array_key_exists('category_id', $args)) {
49
            $categoryId = $this->category()->id;
50
        }
51
        $card = new Card(array_replace([
52
            'title'            => 'Cool card',
53
            'active'           => true,
54
            'content'          => 'Content',
55
            'meta_description' => '',
56
            'category_id'      => $categoryId,
57
        ], $args));
58
59
        $card->save();
60
61
        return $card;
62
    }
63
64
    protected function category(array $args = [])
65
    {
66
        $category = new Category(array_replace([
67
            'title'       => 'Category 1',
68
            'description' => '',
69
            'active'      => true,
70
            'color'       => 'red',
71
            'parent'      => 0,
72
        ], $args));
73
74
        $category->save();
75
76
        return $category;
77
    }
78
}
79