Passed
Push — master ( 538ee6...8952ad )
by Yunus Emre
03:24
created

ProductMock   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 34
dl 0
loc 82
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getExtraMeta() 0 7 1
A all() 0 10 1
A find() 0 13 1
A generateResponseMultiple() 0 3 1
A create() 0 8 1
A generateResponse() 0 3 1
A update() 0 8 1
A delete() 0 8 1
1
<?php
2
3
namespace TarfinLabs\Parasut\Tests\Mocks;
4
5
use Faker\Factory;
6
use Illuminate\Http\Response;
7
use TarfinLabs\Parasut\Models\BaseModel;
8
use TarfinLabs\Parasut\Models\Product;
9
10
class ProductMock extends BaseMock
11
{
12
    public static function all(int $count = 3): void
13
    {
14
        self::fakeAuthentication();
15
16
        $response = self::generateResponseMultiple();
17
18
        self::fakeHttp(
19
            'products',
20
            $response,
21
            Response::HTTP_OK
22
        );
23
    }
24
25
    public static function create(BaseModel $product): void
26
    {
27
        self::fakeAuthentication();
28
29
        self::fakeHttp(
30
            'products',
31
            self::generateResponse($product),
32
            Response::HTTP_OK
33
        );
34
    }
35
36
    public static function find(): int
37
    {
38
        self::fakeAuthentication();
39
40
        $response = self::generateResponse();
41
42
        self::fakeHttp(
43
            'products/'.$response['data']['id'],
44
            $response,
45
            Response::HTTP_OK
46
        );
47
48
        return $response['data']['id'];
49
    }
50
51
    public static function update(BaseModel $product): void
52
    {
53
        self::fakeAuthentication();
54
55
        self::fakeHttp(
56
            'products'.'/'.$product->id,
57
            self::generateResponse($product),
58
            Response::HTTP_OK
59
        );
60
    }
61
62
    public static function delete(BaseModel $product): void
63
    {
64
        self::fakeAuthentication();
65
66
        self::fakeHttp(
67
            'products'.'/'.$product->id,
68
            [[]],
69
            Response::HTTP_OK
70
        );
71
    }
72
73
    // TODO: Resource isimlerini tek bir yerde topla, enum olabilir
74
75
    public static function generateResponse(BaseModel $model = null): array
76
    {
77
        return self::response($model, Product::class, 'products');
78
    }
79
80
    public static function generateResponseMultiple(int $count = 3): array
81
    {
82
        return self::responseMultiple($count, Product::class, 'products', self::getExtraMeta());
83
    }
84
85
    public static function getExtraMeta(): array
86
    {
87
        $faker = Factory::create('tr_TR');
88
89
        return [
90
            'payable_total' => $faker->randomFloat(2, 100, 1000),
91
            'collectible_total' => $faker->randomFloat(2, 100, 1000),
92
        ];
93
    }
94
}
95