|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Saikootau\ApiBundle\Tests\Resource; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeInterface; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Saikootau\ApiBundle\Resource\Error; |
|
10
|
|
|
use Saikootau\ApiBundle\Resource\Request; |
|
11
|
|
|
use Saikootau\ApiBundle\Resource\Service; |
|
12
|
|
|
|
|
13
|
|
|
class ServiceTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testInitializesWithOneError(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$request = $this->prophesize(Request::class)->reveal(); |
|
18
|
|
|
$error = $this->prophesize(Error::class)->reveal(); |
|
19
|
|
|
|
|
20
|
|
|
$service = new Service($request, $error); |
|
21
|
|
|
|
|
22
|
|
|
$this->assertSame(Service::DEFAULT_VERSION, $service->getVersion()); |
|
23
|
|
|
$this->assertInstanceOf(DateTimeInterface::class, $service->getTimestamp()); |
|
24
|
|
|
$this->assertSame($request, $service->getRequest()); |
|
25
|
|
|
$this->assertCount(1, $service->getErrors()); |
|
26
|
|
|
$this->assertContains($error, $service->getErrors()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testInitializesWithMultipleErrors(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$request = $this->prophesize(Request::class)->reveal(); |
|
32
|
|
|
$error = $this->prophesize(Error::class)->reveal(); |
|
33
|
|
|
$error2 = $this->prophesize(Error::class)->reveal(); |
|
34
|
|
|
|
|
35
|
|
|
$service = new Service($request, $error, $error2); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertSame(Service::DEFAULT_VERSION, $service->getVersion()); |
|
38
|
|
|
$this->assertInstanceOf(DateTimeInterface::class, $service->getTimestamp()); |
|
39
|
|
|
$this->assertSame($request, $service->getRequest()); |
|
40
|
|
|
$this->assertCount(2, $service->getErrors()); |
|
41
|
|
|
$this->assertContains($error, $service->getErrors()); |
|
42
|
|
|
$this->assertContains($error2, $service->getErrors()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testVersionCanBeChanged(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$request = $this->prophesize(Request::class)->reveal(); |
|
48
|
|
|
$error = $this->prophesize(Error::class)->reveal(); |
|
49
|
|
|
|
|
50
|
|
|
$service = new Service($request, $error); |
|
51
|
|
|
|
|
52
|
|
|
$service->setVersion('2.0'); |
|
53
|
|
|
$this->assertSame('2.0', $service->getVersion()); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|