ProductTest::user_can_view_a_product()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 16
rs 9.9666
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TarfinLabs\Parasut\Tests;
4
5
use TarfinLabs\Parasut\Mocks\ProductMock;
6
use TarfinLabs\Parasut\Models\Product;
7
use TarfinLabs\Parasut\Repositories\ProductRepository;
8
9
class ProductTest extends TestCase
10
{
11
    /** @test */
12
    public function user_can_list_products(): void
13
    {
14
        ProductMock::all();
15
16
        $productRepository = new ProductRepository();
17
18
        $products = $productRepository->all();
19
20
        $this->assertNotNull(Product::all());
21
        $this->assertInstanceOf(Product::class, $products->first());
22
    }
23
24
    /** @test */
25
    public function user_can_create_a_new_product(): void
26
    {
27
        $product = factory(Product::class)
28
            ->states(['creation', 'response'])
29
            ->make();
30
31
        ProductMock::create($product);
0 ignored issues
show
Bug introduced by
It seems like $product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $product of TarfinLabs\Parasut\Mocks\ProductMock::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        ProductMock::create(/** @scrutinizer ignore-type */ $product);
Loading history...
32
33
        $ProductRepository = new ProductRepository();
34
35
        $productReturned = $ProductRepository->create($product);
0 ignored issues
show
Bug introduced by
It seems like $product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $model of TarfinLabs\Parasut\Repos...aseRepository::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $productReturned = $ProductRepository->create(/** @scrutinizer ignore-type */ $product);
Loading history...
36
37
        $this->assertInstanceOf(
38
            Product::class,
39
            $product
40
        );
41
42
        $this->assertEquals(
43
            $product->name,
44
            $productReturned->name
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on TarfinLabs\Parasut\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
45
        );
46
    }
47
48
    /** @test */
49
    public function user_can_view_a_product(): void
50
    {
51
        $productId = ProductMock::find();
52
53
        $ProductRepository = new ProductRepository();
54
55
        $product = $ProductRepository->find($productId);
56
57
        $this->assertInstanceOf(
58
            Product::class,
59
            $product
60
        );
61
62
        $this->assertEquals(
63
            $productId,
64
            $product->id
65
        );
66
    }
67
68
    /** @test */
69
    public function user_can_edit_a_product(): void
70
    {
71
        $product = factory(Product::class)
72
            ->states(['creation', 'response'])
73
            ->make();
74
75
        ProductMock::create($product);
0 ignored issues
show
Bug introduced by
It seems like $product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $product of TarfinLabs\Parasut\Mocks\ProductMock::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

75
        ProductMock::create(/** @scrutinizer ignore-type */ $product);
Loading history...
76
        $ProductRepository = new ProductRepository();
77
        $product = $ProductRepository->create($product);
0 ignored issues
show
Bug introduced by
It seems like $product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $model of TarfinLabs\Parasut\Repos...aseRepository::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
        $product = $ProductRepository->create(/** @scrutinizer ignore-type */ $product);
Loading history...
78
79
        $newProduct = factory(Product::class)->make();
80
        $newProduct->id = $product->id;
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloquent\Collection.
Loading history...
81
82
        ProductMock::update($product);
83
        $updatedContact = $ProductRepository->update($newProduct);
0 ignored issues
show
Bug introduced by
It seems like $newProduct can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $model of TarfinLabs\Parasut\Repos...aseRepository::update() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

83
        $updatedContact = $ProductRepository->update(/** @scrutinizer ignore-type */ $newProduct);
Loading history...
84
85
        $this->assertInstanceOf(
86
            Product::class,
87
            $updatedContact
88
        );
89
90
        $this->assertEquals(
91
            $updatedContact->name,
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on TarfinLabs\Parasut\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
92
            $newProduct->name
93
        );
94
    }
95
96
    /** @test */
97
    public function user_can_delete_a_product(): void
98
    {
99
        $product = factory(Product::class)
100
            ->states(['creation', 'response'])
101
            ->make();
102
103
        ProductMock::create($product);
0 ignored issues
show
Bug introduced by
It seems like $product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $product of TarfinLabs\Parasut\Mocks\ProductMock::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

103
        ProductMock::create(/** @scrutinizer ignore-type */ $product);
Loading history...
104
        $ProductRepository = new ProductRepository();
105
        $product = $ProductRepository->create($product);
0 ignored issues
show
Bug introduced by
It seems like $product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $model of TarfinLabs\Parasut\Repos...aseRepository::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

105
        $product = $ProductRepository->create(/** @scrutinizer ignore-type */ $product);
Loading history...
106
107
        ProductMock::delete($product);
108
        $result = $ProductRepository->delete($product);
109
110
        $this->assertTrue($result);
111
    }
112
}
113