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