ContactTest::user_can_view_a_contact()   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
c 1
b 0
f 0
dl 0
loc 16
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TarfinLabs\Parasut\Tests;
4
5
use TarfinLabs\Parasut\Mocks\ContactMock;
6
use TarfinLabs\Parasut\Models\Contact;
7
use TarfinLabs\Parasut\Repositories\ContactRepository;
8
9
class ContactTest extends TestCase
10
{
11
    /** @test */
12
    public function user_can_list_contacts(): void
13
    {
14
        ContactMock::all();
15
16
        $contactRepository = new ContactRepository();
17
18
        $contacts = $contactRepository->all();
19
20
        $this->assertNotNull(Contact::all());
21
        $this->assertInstanceOf(Contact::class, $contacts->first());
22
    }
23
24
    /** @test */
25
    public function user_can_create_a_new_contact(): void
26
    {
27
        $contact = factory(Contact::class)
28
            ->states(['creation', 'response'])
29
            ->make();
30
31
        ContactMock::create($contact);
0 ignored issues
show
Bug introduced by
It seems like $contact can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $contact of TarfinLabs\Parasut\Mocks\ContactMock::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
        ContactMock::create(/** @scrutinizer ignore-type */ $contact);
Loading history...
32
33
        $contactRepository = new ContactRepository();
34
35
        $contactReturned = $contactRepository->create($contact);
0 ignored issues
show
Bug introduced by
It seems like $contact 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
        $contactReturned = $contactRepository->create(/** @scrutinizer ignore-type */ $contact);
Loading history...
36
37
        $this->assertInstanceOf(
38
            Contact::class,
39
            $contact
40
        );
41
42
        $this->assertEquals(
43
            $contact->name,
44
            $contactReturned->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_contact(): void
50
    {
51
        $contactId = ContactMock::find();
52
53
        $contactRepository = new ContactRepository();
54
55
        $contact = $contactRepository->find($contactId);
56
57
        $this->assertInstanceOf(
58
            Contact::class,
59
            $contact
60
        );
61
62
        $this->assertEquals(
63
            $contactId,
64
            $contact->id
65
        );
66
    }
67
68
    /** @test */
69
    public function user_can_edit_a_contact(): void
70
    {
71
        $contact = factory(Contact::class)
72
            ->states(['creation', 'response'])
73
            ->make();
74
75
        ContactMock::create($contact);
0 ignored issues
show
Bug introduced by
It seems like $contact can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $contact of TarfinLabs\Parasut\Mocks\ContactMock::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
        ContactMock::create(/** @scrutinizer ignore-type */ $contact);
Loading history...
76
        $contactRepository = new ContactRepository();
77
        $contact = $contactRepository->create($contact);
0 ignored issues
show
Bug introduced by
It seems like $contact 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
        $contact = $contactRepository->create(/** @scrutinizer ignore-type */ $contact);
Loading history...
78
79
        $newContact = factory(Contact::class)->make();
80
        $newContact->id = $contact->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
        ContactMock::update($contact);
83
        $updatedContact = $contactRepository->update($newContact);
0 ignored issues
show
Bug introduced by
It seems like $newContact 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 = $contactRepository->update(/** @scrutinizer ignore-type */ $newContact);
Loading history...
84
85
        $this->assertInstanceOf(
86
            Contact::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
            $newContact->name
93
        );
94
    }
95
96
    /** @test */
97
    public function user_can_delete_a_contact(): void
98
    {
99
        $contact = factory(Contact::class)
100
            ->states(['creation', 'response'])
101
            ->make();
102
103
        ContactMock::create($contact);
0 ignored issues
show
Bug introduced by
It seems like $contact can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $contact of TarfinLabs\Parasut\Mocks\ContactMock::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
        ContactMock::create(/** @scrutinizer ignore-type */ $contact);
Loading history...
104
        $contactRepository = new ContactRepository();
105
        $contact = $contactRepository->create($contact);
0 ignored issues
show
Bug introduced by
It seems like $contact 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
        $contact = $contactRepository->create(/** @scrutinizer ignore-type */ $contact);
Loading history...
106
107
        ContactMock::delete($contact);
108
        $result = $contactRepository->delete($contact);
109
110
        $this->assertTrue($result);
111
    }
112
}
113