Issues (25)

tests/ContactTest.php (7 issues)

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
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
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
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
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
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;
81
82
        ContactMock::update($contact);
83
        $updatedContact = $contactRepository->update($newContact);
0 ignored issues
show
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,
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
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
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