BaseBlogTestCase   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
lcom 1
cbo 0
dl 0
loc 76
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A createBlogPost() 0 23 1
A createTag() 0 23 1
1
<?php namespace Modules\Blog\Tests;
2
3
use Faker\Factory;
4
use Illuminate\Support\Str;
5
use Modules\Core\Tests\BaseTestCase;
6
7
abstract class BaseBlogTestCase extends BaseTestCase
8
{
9
    /**
10
     * @var \Modules\Blog\Repositories\PostRepository
11
     */
12
    protected $post;
13
14
    /**
15
     * @var \Modules\Blog\Repositories\TagRepository
16
     */
17
    protected $tag;
18
19
    public function setUp()
20
    {
21
        parent::setUp();
22
23
        /** @var \Illuminate\Console\Application $artisan */
24
        $artisan = $this->app->make('Illuminate\Console\Application');
25
        $artisan->call('module:migrate', ['module' => 'Blog']);
26
27
        $this->post = app('Modules\Blog\Repositories\PostRepository');
28
        $this->tag = app('Modules\Blog\Repositories\TagRepository');
29
    }
30
31
    /**
32
     * Helper method to create a blog post
33
     * @return object
34
     */
35
    public function createBlogPost()
36
    {
37
        $faker = Factory::create();
38
39
        $title = implode(' ', $faker->words(3));
40
        $slug = Str::slug($title);
41
42
        $data = [
43
            'en' => [
44
                'title' => $title,
45
                'slug' => $slug,
46
                'content' => $faker->paragraph(),
47
            ],
48
            'fr' => [
49
                'title' => $title,
50
                'slug' => $slug,
51
                'content' => $faker->paragraph(),
52
            ],
53
            'category_id' => 1,
54
        ];
55
56
        return $this->post->create($data);
57
    }
58
59
    public function createTag()
60
    {
61
        $faker = Factory::create();
62
63
        $enName = $faker->word;
64
        $enSlug = Str::slug($enName);
65
66
        $frName = $faker->word;
67
        $frSlug = Str::slug($enName);
68
69
        $data = [
70
            'en' => [
71
                'name' => $enName,
72
                'slug' => $enSlug,
73
            ],
74
            'fr' => [
75
                'name' => $frName,
76
                'slug' => $frSlug,
77
            ],
78
        ];
79
80
        return $this->tag->create($data);
81
    }
82
}
83