Passed
Push — master ( e0ab5f...89e278 )
by Yunus Emre
03:45
created

ContactTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 10
Bugs 0 Features 0
Metric Value
wmc 5
eloc 46
c 10
b 0
f 0
dl 0
loc 96
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A user_can_create_a_new_contact() 0 18 1
A user_can_view_a_contact() 0 16 1
A user_can_list_contacts() 0 10 1
A user_can_edit_a_contact() 0 22 1
A user_can_delete_a_contact() 0 12 1
1
<?php
2
3
namespace TarfinLabs\Parasut\Tests;
4
5
use Faker\Factory;
6
use TarfinLabs\Parasut\Models\Contact;
7
use TarfinLabs\Parasut\Repositories\ContactRepository;
8
use TarfinLabs\Parasut\Tests\Mocks\ParasutMock;
9
10
class ContactTest extends TestCase
11
{
12
    /** @test */
13
    public function user_can_list_contacts(): void
14
    {
15
        ParasutMock::allContacts();
16
17
        $contactRepository = new ContactRepository();
18
19
        $contacts = $contactRepository->all();
20
21
        $this->assertNotNull(Contact::all());
22
        $this->assertInstanceOf(Contact::class, $contacts->first());
23
    }
24
25
    /** @test */
26
    public function user_can_create_a_new_contact(): void
27
    {
28
        $contact = factory(Contact::class)->make();
29
30
        ParasutMock::createContact($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\Tests...utMock::createContact() does only seem to accept TarfinLabs\Parasut\Models\Contact, 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

30
        ParasutMock::createContact(/** @scrutinizer ignore-type */ $contact);
Loading history...
31
32
        $contactRepository = new ContactRepository();
33
34
        $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

34
        $contactReturned = $contactRepository->create(/** @scrutinizer ignore-type */ $contact);
Loading history...
35
36
        $this->assertInstanceOf(
37
            Contact::class,
38
            $contact
39
        );
40
41
        $this->assertEquals(
42
            $contact->name,
43
            $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...
44
        );
45
    }
46
47
    /** @test */
48
    public function user_can_view_a_contact(): void
49
    {
50
        $contactId = ParasutMock::findContact();
51
52
        $contactRepository = new ContactRepository();
53
54
        $contact = $contactRepository->find($contactId);
55
56
        $this->assertInstanceOf(
57
            Contact::class,
58
            $contact
59
        );
60
61
        $this->assertEquals(
62
            $contactId,
63
            $contact->id
64
        );
65
    }
66
67
    /** @test */
68
    public function user_can_edit_a_contact(): void
69
    {
70
        $contact = factory(Contact::class)->make();
71
72
        ParasutMock::createContact($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\Tests...utMock::createContact() does only seem to accept TarfinLabs\Parasut\Models\Contact, 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

72
        ParasutMock::createContact(/** @scrutinizer ignore-type */ $contact);
Loading history...
73
        $contactRepository = new ContactRepository();
74
        $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

74
        $contact = $contactRepository->create(/** @scrutinizer ignore-type */ $contact);
Loading history...
75
76
        $newContact = factory(Contact::class)->make();
77
        $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...
78
79
        ParasutMock::updateContact($contact);
80
        $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

80
        $updatedContact = $contactRepository->update(/** @scrutinizer ignore-type */ $newContact);
Loading history...
81
82
        $this->assertInstanceOf(
83
            Contact::class,
84
            $updatedContact
85
        );
86
87
        $this->assertEquals(
88
            $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...
89
            $newContact->name
90
        );
91
    }
92
93
    /** @test */
94
    public function user_can_delete_a_contact(): void
95
    {
96
        $contact = factory(Contact::class)->make();
97
98
        ParasutMock::createContact($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\Tests...utMock::createContact() does only seem to accept TarfinLabs\Parasut\Models\Contact, 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

98
        ParasutMock::createContact(/** @scrutinizer ignore-type */ $contact);
Loading history...
99
        $contactRepository = new ContactRepository();
100
        $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

100
        $contact = $contactRepository->create(/** @scrutinizer ignore-type */ $contact);
Loading history...
101
102
        ParasutMock::deleteContact($contact);
103
        $result = $contactRepository->delete($contact);
104
105
        $this->assertTrue($result);
106
    }
107
}
108