|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace InvoiceNinjaModuleTest\Strategy; |
|
5
|
|
|
|
|
6
|
|
|
use InvoiceNinjaModule\Model\Interfaces\InvoiceItemInterface; |
|
7
|
|
|
use InvoiceNinjaModule\Strategy\InvoiceItemsStrategy; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Zend\Hydrator\HydratorInterface; |
|
10
|
|
|
|
|
11
|
|
|
class InvoiceItemsStrategyTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
private $hydratorMock; |
|
14
|
|
|
/** @var InvoiceItemsStrategy */ |
|
15
|
|
|
private $strategy; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() :void |
|
19
|
|
|
{ |
|
20
|
|
|
parent::setUp(); |
|
21
|
|
|
$this->hydratorMock = $this->createMock(HydratorInterface::class); |
|
22
|
|
|
$this->strategy = new InvoiceItemsStrategy($this->hydratorMock); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testCreate() :void |
|
26
|
|
|
{ |
|
27
|
|
|
self::assertInstanceOf(InvoiceItemsStrategy::class, $this->strategy); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testExtractEmpty() :void |
|
31
|
|
|
{ |
|
32
|
|
|
$testValue = []; |
|
33
|
|
|
|
|
34
|
|
|
$result = $this->strategy->extract($testValue); |
|
35
|
|
|
self::assertEmpty($result); |
|
36
|
|
|
self::assertInternalType('array', $result); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testExtract() :void |
|
40
|
|
|
{ |
|
41
|
|
|
$testValue = [ |
|
42
|
|
|
$this->createMock(InvoiceItemInterface::class) |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
$result = $this->strategy->extract($testValue); |
|
46
|
|
|
self::assertNotEmpty($result); |
|
47
|
|
|
self::assertInternalType('array', $result); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testHydrateEmpty() :void |
|
51
|
|
|
{ |
|
52
|
|
|
$testValue = [ |
|
53
|
|
|
]; |
|
54
|
|
|
|
|
55
|
|
|
$result = $this->strategy->hydrate($testValue); |
|
56
|
|
|
self::assertEmpty($result); |
|
57
|
|
|
self::assertInternalType('array', $result); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testHydrate() :void |
|
61
|
|
|
{ |
|
62
|
|
|
$testValue = [ |
|
63
|
|
|
[ 'id' => 1] |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
$result = $this->strategy->hydrate($testValue); |
|
67
|
|
|
self::assertNotEmpty($result); |
|
68
|
|
|
self::assertInternalType('array', $result); |
|
69
|
|
|
self::assertInstanceOf(InvoiceItemInterface::class, $result[0]); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|