DetailLawyerTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 55
dl 0
loc 106
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstruct() 0 25 1
A getPropertyValue() 0 7 1
A testGet() 0 6 1
A testEmpty() 0 7 1
A testLoadFromLawyer() 0 22 1
A testSet() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SomeWork\Minjust\Tests\Unit\Entity;
6
7
use PHPUnit\Framework\TestCase;
8
use ReflectionClass;
9
use ReflectionObject;
10
use SomeWork\Minjust\Entity\DetailLawyer;
11
use SomeWork\Minjust\Entity\LawFormation;
12
use SomeWork\Minjust\Entity\Lawyer;
13
use SomeWork\Minjust\Entity\Location;
14
15
/**
16
 * @coversDefaultClass DetailLawyer
17
 * @covers \SomeWork\Minjust\Entity\DetailLawyer
18
 */
19
class DetailLawyerTest extends TestCase
20
{
21
    public function testEmpty(): DetailLawyer
22
    {
23
        $lawyer = new DetailLawyer();
24
        $this->assertIsString($this->getPropertyValue($lawyer, 'chamberOfLaw'));
25
        $this->assertNull($this->getPropertyValue($lawyer, 'lawFormation'));
26
27
        return $lawyer;
28
    }
29
30
    protected function getPropertyValue(object $object, string $property)
31
    {
32
        $ref = new ReflectionObject($object);
33
        $property = $ref->getProperty($property);
34
        $property->setAccessible(true);
35
36
        return $property->getValue($object);
37
    }
38
39
    /**
40
     * @depends testEmpty
41
     *
42
     * @param DetailLawyer $lawyer
43
     *
44
     * @return DetailLawyer
45
     */
46
    public function testSet(DetailLawyer $lawyer): DetailLawyer
47
    {
48
        $lawFormation = (new LawFormation())->setName('testLawFormation');
49
50
        $lawyer
51
            ->setChamberOfLaw('testChamberOfLaw')
52
            ->setLawFormation($lawFormation);
53
54
        $this->assertEquals('testChamberOfLaw', $this->getPropertyValue($lawyer, 'chamberOfLaw'));
55
        $this->assertEquals($lawFormation, $this->getPropertyValue($lawyer, 'lawFormation'));
56
57
        return $lawyer;
58
    }
59
60
    /**
61
     * @depends testSet
62
     *
63
     * @param DetailLawyer $lawyer
64
     */
65
    public function testGet(DetailLawyer $lawyer): void
66
    {
67
        $lawFormation = $this->getPropertyValue($lawyer, 'lawFormation');
68
69
        $this->assertEquals('testChamberOfLaw', $lawyer->getChamberOfLaw());
70
        $this->assertEquals($lawFormation, $lawyer->getLawFormation());
71
    }
72
73
    public function testLoadFromLawyer(): void
74
    {
75
        $location = (new Location())
76
            ->setId('01')
77
            ->setName('testLocation');
78
79
        $lawyer = (new Lawyer())
80
            ->setUrl('testUrl')
81
            ->setFullName('testFullName')
82
            ->setStatus('testStatus')
83
            ->setRegisterNumber('testRegisterNumber')
84
            ->setCertificateNumber('testCertificateNumber')
85
            ->setLocation($location);
86
87
        $detailLawyer = (new DetailLawyer())->loadFromLawyer($lawyer);
88
89
        $this->assertEquals($lawyer->getUrl(), $detailLawyer->getUrl());
90
        $this->assertEquals($lawyer->getFullName(), $detailLawyer->getFullName());
91
        $this->assertEquals($lawyer->getStatus(), $detailLawyer->getStatus());
92
        $this->assertEquals($lawyer->getRegisterNumber(), $detailLawyer->getRegisterNumber());
93
        $this->assertEquals($lawyer->getCertificateNumber(), $detailLawyer->getCertificateNumber());
94
        $this->assertEquals($lawyer->getLocation(), $detailLawyer->getLocation());
95
    }
96
97
    /**
98
     * @covers ::__construct
99
     */
100
    public function testConstruct(): void
101
    {
102
        $location = (new Location())
103
            ->setId('01')
104
            ->setName('test Location');
105
106
        $lawyer = (new Lawyer())
107
            ->setUrl('testUrl')
108
            ->setFullName('testFullName')
109
            ->setStatus('testStatus')
110
            ->setRegisterNumber('testRegisterNumber')
111
            ->setCertificateNumber('testCertificateNumber')
112
            ->setLocation($location);
113
114
        $detailLawyer = $this->createPartialMock(DetailLawyer::class, ['loadFromLawyer']);
115
116
        $detailLawyer
117
            ->expects($this->once())
118
            ->method('loadFromLawyer')
119
            ->with($lawyer)
120
            ->willReturn($detailLawyer);
121
122
        $reflectedClass = new ReflectionClass(DetailLawyer::class);
123
        $constructor = $reflectedClass->getConstructor();
124
        $constructor->invoke($detailLawyer, $lawyer);
125
    }
126
}
127