GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CategoryTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 93
Duplicated Lines 15.05 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 14
loc 93
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testDeleteAllCategories() 14 14 1
A testImportCategories() 0 18 1
A testImportSubCategories() 0 21 1
B it_preserves_default_categories_on_payees_table_after_importing_categories() 0 31 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Tests\Feature\MmexClient;
4
5
use App\Models\Category;
6
use App\Models\Payee;
7
8
class CategoryTest extends MmexTestCase
9
{
10 View Code Duplication
    public function testDeleteAllCategories()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
    {
12
        // Arrange
13
        $categorie = factory(Category::class)->create(['user_id' => $this->user->id]);
14
15
        $url = $this->buildUrl(['delete_category' => 'true']);
16
17
        // Act
18
        $response = $this->get($url);
19
20
        // Assert
21
        $this->assertSeeMmexSuccess($response);
22
        $this->assertIsSoftDeletedInDatabase('categories', ['user_id' => $this->user->id, 'name' => $categorie->name]);
23
    }
24
25
    public function testImportCategories()
26
    {
27
        // Arrange
28
        $data = ['MMEX_Post' => '{ "Categories" : [ { "CategoryName" : "Bills", "SubCategoryName" : "Telecom" }, { "CategoryName" : "Bills", "SubCategoryName" : "Water" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Maintenance" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Parking" } ] }'];
29
        $url = $this->buildUrl(['import_category' => 'true']);
30
31
        // Act
32
        $response = $this->postJson($url, $data);
33
34
        // Assert
35
        $this->assertSeeMmexSuccess($response);
36
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Bills']);
37
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Telecom']);
38
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Water']);
39
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Automobile']);
40
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Maintenance']);
41
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Parking']);
42
    }
43
44
    public function testImportSubCategories()
45
    {
46
        // Arrange
47
        $data = ['MMEX_Post' => '{ "Categories" : [ { "CategoryName" : "Bills", "SubCategoryName" : "Telecom" }, { "CategoryName" : "Bills", "SubCategoryName" : "Water" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Maintenance" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Parking" } ] }'];
48
        $url = $this->buildUrl(['import_category' => 'true']);
49
50
        $bills = factory(Category::class)->create(['user_id' => $this->user->id, 'name' => 'Bills']);
51
        $automobile = factory(Category::class)->create(['user_id' => $this->user->id, 'name' => 'Automobile']);
52
53
        // Act
54
        $response = $this->postJson($url, $data);
55
56
        // Assert
57
        $this->assertSeeMmexSuccess($response);
58
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Bills', 'id' => $bills->id]);
59
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Telecom', 'parent_id' => $bills->id]);
60
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Water', 'parent_id' => $bills->id]);
61
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Automobile', 'id' => $automobile->id]);
62
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Maintenance', 'parent_id' => $automobile->id]);
63
        $this->assertDatabaseHas('categories', ['user_id' => $this->user->id, 'name' => 'Parking', 'parent_id' => $automobile->id]);
64
    }
65
66
    /**
67
     * @test
68
     */
69
    public function it_preserves_default_categories_on_payees_table_after_importing_categories()
70
    {
71
        // Arrange
72
        $category1 = factory(Category::class)->create(['user_id' => $this->user->id, 'name' => 'Bills']);
73
        $subcategory1 = factory(Category::class)->create(['user_id' => $this->user->id, 'name' => 'Services', 'parent_id' => $category1->id]);
74
        $category2 = factory(Category::class)->create(['user_id' => $this->user->id, 'name' => 'Food']);
75
        $subcategory2 = factory(Category::class)->create(['user_id' => $this->user->id, 'name' => 'Purchase', 'parent_id' => $category2->id]);
76
77
        $payee1 = factory(Payee::class)->create(['user_id' => $this->user->id, 'last_category_id' => $subcategory1->id]);
78
        $payee2 = factory(Payee::class)->create(['user_id' => $this->user->id, 'last_category_id' => $subcategory2->id]);
79
80
        $data = ['MMEX_Post' => '{ "Categories" : [ { "CategoryName" : "Bills", "SubCategoryName" : "Services" }, { "CategoryName" : "Food", "SubCategoryName" : "Purchase" } ] }'];
81
82
        // Act
83
        $deletePayeesUrl = $this->buildUrl(['delete_category' => 'true']);
84
        $this->getJson($deletePayeesUrl);
85
86
        $url = $this->buildUrl(['import_category' => 'true']);
87
        $response = $this->postJson($url, $data);
88
89
        // Assert
90
        $this->assertSeeMmexSuccess($response);
91
        $category1 = $this->assertDatabaseHasOnceAndReturnFirst('categories', ['id' => $category1->id, 'name' => 'Bills', 'deleted_at' => null]);
92
        $subcategory1 = $this->assertDatabaseHasOnceAndReturnFirst('categories', ['id' => $subcategory1->id, 'name' => 'Services', 'parent_id' => $category1->id, 'deleted_at' => null]);
93
94
        $category2 = $this->assertDatabaseHasOnceAndReturnFirst('categories', ['id' => $category2->id, 'name' => 'Food', 'deleted_at' => null]);
95
        $subcategory2 = $this->assertDatabaseHasOnceAndReturnFirst('categories', ['id' => $subcategory2->id, 'name' => 'Purchase', 'parent_id' => $category2->id, 'deleted_at' => null]);
96
97
        $this->assertDatabaseHas('payees', ['id' => $payee1->id, 'last_category_id' => $subcategory1->id]);
98
        $this->assertDatabaseHas('payees', ['id' => $payee2->id, 'last_category_id' => $subcategory2->id]);
99
    }
100
}
101