6
6
use Cristal \ApiWrapper \Transports \TransportInterface ;
7
7
use Mockery ;
8
8
use PHPUnit \Framework \TestCase ;
9
+ use TypeError ;
9
10
10
11
class ApiTest extends TestCase
11
12
{
12
- const ENDPOINTS = ['client ' , 'catalogue ' , 'materiel ' , 'fabricant ' , 'type ' , 'tarif ' , 'caracteristique ' ];
13
+ protected const ENDPOINTS = ['client ' , 'catalogue ' , 'materiel ' , 'fabricant ' , 'type ' , 'tarif ' , 'caracteristique ' ];
13
14
protected $ token ;
14
15
protected $ entrypoint ;
15
16
16
- const WITH_FILTER = ['with_filters ' ];
17
- const WITHOUT_FILTER = ['without_filters ' ];
18
- const ID_ENTITY = 123 ;
17
+ protected const WITH_FILTER = ['with_filters ' ];
18
+ protected const WITHOUT_FILTER = ['without_filters ' ];
19
+ protected const ID_ENTITY = 123 ;
19
20
20
21
protected function createFakeTransport ()
21
22
{
@@ -27,60 +28,50 @@ protected function createFakeTransport()
27
28
return $ transport ;
28
29
}
29
30
30
- public function setUp ()
31
+ public function setUp (): void
31
32
{
32
33
$ this ->token = 'token_jwt ' ;
33
34
$ this ->entrypoint = 'https://exemple/api/ ' ;
34
35
}
35
36
36
- public function testApiWithoutTransport ()
37
+ public function testApiWithoutTransport (): void
37
38
{
38
- $ this ->expectException (\ TypeError::class);
39
+ $ this ->expectException (TypeError::class);
39
40
new Api (null );
40
41
}
41
42
42
- public function testApiWithTransport ()
43
+ public function testApiWithTransport (): void
43
44
{
44
45
$ transport = Mockery::mock (TransportInterface::class);
45
46
$ api = new Api ($ transport );
46
- $ this -> assertInstanceOf (TransportInterface::class, $ api ->getTransport ());
47
+ self :: assertInstanceOf (TransportInterface::class, $ api ->getTransport ());
47
48
}
48
49
49
- public function testGetWithoutFilters ()
50
+ public function testGetWithoutFilters (): void
50
51
{
51
52
$ transport = $ this ->createFakeTransport ();
52
53
$ api = new Api ($ transport );
53
54
foreach (self ::ENDPOINTS as $ endpoint ) {
54
- $ this -> assertEquals (self ::WITHOUT_FILTER , $ api ->{'get ' .ucfirst ($ endpoint ).'s ' }());
55
+ self :: assertEquals (self ::WITHOUT_FILTER , $ api ->{'get ' .ucfirst ($ endpoint ).'s ' }());
55
56
}
56
57
}
57
58
58
- public function testGetWithFilters ()
59
+ public function testGetWithFilters (): void
59
60
{
60
61
$ transport = $ this ->createFakeTransport ();
61
62
$ api = new Api ($ transport );
62
63
foreach (self ::ENDPOINTS as $ endpoint ) {
63
- $ this -> assertEquals (self ::WITH_FILTER , $ api ->{'get ' .ucfirst ($ endpoint ).'s ' }(self ::WITH_FILTER ));
64
+ self :: assertEquals (self ::WITH_FILTER , $ api ->{'get ' .ucfirst ($ endpoint ).'s ' }(self ::WITH_FILTER ));
64
65
}
65
66
}
66
67
67
- public function testTryToGetSpecificEntityWithoutIdAsArgument ()
68
- {
69
- $ this ->expectException (\TypeError::class);
70
- $ transport = $ this ->createFakeTransport ();
71
- $ api = new Api ($ transport );
72
- foreach (self ::ENDPOINTS as $ endpoint ) {
73
- $ api ->{'get ' .ucfirst ($ endpoint )}();
74
- }
75
- }
76
-
77
- public function testTryToGetSpecificEntity ()
68
+ public function testTryToGetSpecificEntity (): void
78
69
{
79
70
$ transport = $ this ->createFakeTransport ();
80
71
$ api = new Api ($ transport );
81
72
foreach (self ::ENDPOINTS as $ endpoint ) {
82
73
$ entity = $ api ->{'get ' .ucfirst ($ endpoint )}(self ::ID_ENTITY );
83
- $ this -> assertInternalType ( ' array ' , $ entity );
74
+ self :: assertIsArray ( $ entity );
84
75
}
85
76
}
86
77
}
0 commit comments