Passed
Push — master ( 0facf0...5efa68 )
by Yunus Emre
03:38
created

ContactMock::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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\Contact;
9
use TarfinLabs\Parasut\Enums\ResourceNames;
10
11
class ContactMock 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::CONTACT,
21
            $response,
22 1
            Response::HTTP_OK
23
        );
24 1
    }
25
26 3
    public static function create(BaseModel $contact): void
27
    {
28 3
        self::fakeAuthentication();
29
30 3
        self::fakeHttp(
31 3
            ResourceNames::CONTACT,
32 3
            self::generateResponse($contact),
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(
45 1
                ResourceNames::CONTACT,
46 1
                $response['data']['id']
47
            ),
48
            $response,
49 1
            Response::HTTP_OK
50
        );
51
52 1
        return $response['data']['id'];
53
    }
54
55 1
    public static function update(BaseModel $contact): void
56
    {
57 1
        self::fakeAuthentication();
58
59 1
        self::fakeHttp(
60 1
            ResourceNames::buildEndpoint(ResourceNames::CONTACT, (string) $contact->id),
61 1
            self::generateResponse($contact),
62 1
            Response::HTTP_OK
63
        );
64 1
    }
65
66 1
    public static function delete(BaseModel $contact): void
67
    {
68 1
        self::fakeAuthentication();
69
70 1
        self::fakeHttp(
71 1
            ResourceNames::buildEndpoint(ResourceNames::CONTACT, (string) $contact->id),
72 1
            [[]],
73 1
            Response::HTTP_OK
74
        );
75 1
    }
76
77 4
    public static function generateResponse(BaseModel $model = null): array
78
    {
79 4
        return self::response($model, Contact::class, ResourceNames::CONTACT);
80
    }
81
82 1
    public static function generateResponseMultiple(int $count = 3): array
83
    {
84 1
        return self::responseMultiple($count, Contact::class, ResourceNames::CONTACT, self::getExtraMeta());
85
    }
86
87 1
    public static function getExtraMeta(): array
88
    {
89 1
        $faker = Factory::create('tr_TR');
90
91
        return [
92 1
            'payable_total' => $faker->randomFloat(2, 100, 1000),
93 1
            'collectible_total' => $faker->randomFloat(2, 100, 1000),
94
        ];
95
    }
96
}
97