Issues (25)

tests/ContactTest.php (3 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);
32
33
        $contactRepository = new ContactRepository();
34
35
        $contactReturned = $contactRepository->create($contact);
36
37
        $this->assertInstanceOf(
38
            Contact::class,
39
            $contact
40
        );
41
42
        $this->assertEquals(
43
            $contact->name,
44
            $contactReturned->name
0 ignored issues
show
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);
76
        $contactRepository = new ContactRepository();
77
        $contact = $contactRepository->create($contact);
78
79
        $newContact = factory(Contact::class)->make();
80
        $newContact->id = $contact->id;
0 ignored issues
show
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);
84
85
        $this->assertInstanceOf(
86
            Contact::class,
87
            $updatedContact
88
        );
89
90
        $this->assertEquals(
91
            $updatedContact->name,
0 ignored issues
show
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);
104
        $contactRepository = new ContactRepository();
105
        $contact = $contactRepository->create($contact);
106
107
        ContactMock::delete($contact);
108
        $result = $contactRepository->delete($contact);
109
110
        $this->assertTrue($result);
111
    }
112
}
113