ContactServiceTest::create_WithData_ValidPayload()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 24
rs 9.6333
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Dolibarr\Client\Tests\Service;
4
5
use Dolibarr\Client\Domain\Contact\Contact;
6
use Dolibarr\Client\Domain\Contact\ContactId;
7
use Dolibarr\Client\Service\ContactService;
8
9
final class ContactServiceTest extends ServiceTest
10
{
11
    /**
12
     * @var ContactService
13
     */
14
    private $service;
15
16
    /**
17
     * Setup the service.
18
     */
19
    protected function setUp()
20
    {
21
        parent::setUp();
22
        $this->service = new ContactService($this->mockClient(), $this->serializer());
23
    }
24
25
    /**
26
     * @test
27
     *
28
     * @throws \Exception
29
     */
30
    public function create_WithData_ValidPayload()
31
    {
32
        $this->mockClient()
33
            ->expects($this->once())
34
            ->method("post")
35
            ->with("contacts", $this->getExpectedPayload('Contacts/create'))
36
            ->willReturn($this->buildResponse('Contacts/create'));
37
38
        $contact = new Contact('test_last name');
39
        $contact->setFirstname('Test');
40
        $contact->setCivilityCode('Mr');
41
        $contact->setPhone('0000000000');
42
        $contact->setEmail('[email protected]');
43
        $contact->setAddress('add');
44
        $contact->setZip('1000');
45
        $contact->setCompanyId(1);
46
        $contact->setEnable(true);
47
        $contact->setExternalReference('AZERTY001');
48
        $contact->setTown('City');
49
50
        $id = $this->service->create($contact);
51
52
        $this->assertInstanceOf(ContactId::class, $id);
53
        $this->assertEquals(4, $id->getId());
54
    }
55
}
56