Skip to content

Commit 9220708

Browse files
committed
Added BillStateTest
1 parent 6ae9d3c commit 9220708

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

tests/unit/bill/BillStateTest.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace hiqdev\php\billing\tests\unit\bill;
4+
5+
use hiqdev\php\billing\bill\BillState;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class BillStateTest extends TestCase
9+
{
10+
public function testGetName()
11+
{
12+
$billState = BillState::new();
13+
$this->assertEquals(BillState::STATE_NEW, $billState->getName());
14+
15+
$billState = BillState::finished();
16+
$this->assertEquals(BillState::STATE_FINISHED, $billState->getName());
17+
}
18+
19+
public function testIsNew()
20+
{
21+
$billState = BillState::new();
22+
$this->assertTrue($billState->isNew());
23+
$this->assertFalse($billState->isFinished());
24+
25+
$billState = BillState::finished();
26+
$this->assertFalse($billState->isNew());
27+
}
28+
29+
public function testIsFinished()
30+
{
31+
$billState = BillState::finished();
32+
$this->assertTrue($billState->isFinished());
33+
$this->assertFalse($billState->isNew());
34+
35+
$billState = BillState::new();
36+
$this->assertFalse($billState->isFinished());
37+
}
38+
39+
public function testNew()
40+
{
41+
$billState = BillState::new();
42+
$this->assertInstanceOf(BillState::class, $billState);
43+
$this->assertEquals(BillState::STATE_NEW, $billState->getName());
44+
}
45+
46+
public function testFinished()
47+
{
48+
$billState = BillState::finished();
49+
$this->assertInstanceOf(BillState::class, $billState);
50+
$this->assertEquals(BillState::STATE_FINISHED, $billState->getName());
51+
}
52+
53+
public function testFromString()
54+
{
55+
$billState = BillState::fromString(BillState::STATE_NEW);
56+
$this->assertEquals(BillState::STATE_NEW, $billState->getName());
57+
58+
$billState = BillState::fromString(BillState::STATE_FINISHED);
59+
$this->assertEquals(BillState::STATE_FINISHED, $billState->getName());
60+
}
61+
62+
public function testFromStringWithInvalidState()
63+
{
64+
$this->expectException(\Exception::class);
65+
$this->expectExceptionMessage("wrong bill state 'invalid'");
66+
67+
BillState::fromString('invalid');
68+
}
69+
70+
/**
71+
* Helper method to access protected property
72+
*/
73+
private function getStateProperty(BillState $billState)
74+
{
75+
$reflection = new \ReflectionClass($billState);
76+
$property = $reflection->getProperty('state');
77+
$property->setAccessible(true);
78+
79+
return $property->getValue($billState);
80+
}
81+
}

0 commit comments

Comments
 (0)