Skip to content

Commit 171d3ad

Browse files
[PHPUnit] Fix test suite locally
1 parent 4e09b5c commit 171d3ad

File tree

6 files changed

+104
-77
lines changed

6 files changed

+104
-77
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.phpunit.result.cache
2+
/composer.lock
3+
/vendor/

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "cristal/php-api-wrapper",
3+
"description": "Work with APIs like with Laravel Eloquent or Doctrine (no longer a dream)",
34
"type": "package",
45
"authors": [
56
{
@@ -23,5 +24,10 @@
2324
"Cristal\\ApiWrapper\\": "src"
2425
}
2526
},
26-
"license": "MIT"
27+
"license": "MIT",
28+
"require-dev": {
29+
"phpunit/phpunit": "^9.3",
30+
"mockery/mockery": "^1.4",
31+
"symfony/var-dumper": "^5.1"
32+
}
2733
}

phpunit.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
failOnRisky="true"
9+
failOnWarning="true">
10+
<coverage>
11+
<include>
12+
<directory>./src</directory>
13+
</include>
14+
</coverage>
15+
<php>
16+
<ini name="error_reporting" value="-1"/>
17+
</php>
18+
<testsuites>
19+
<testsuite name="Cristal Team - PHP API Wrapper Test Suite">
20+
<directory>./tests/</directory>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

src/Transports/Transport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function encodeBody($data)
213213
return $data;
214214
}
215215
if ($value instanceof MultipartParam) {
216-
$delimiter = '----WebKitFormBoundary'.uniqid();
216+
$delimiter = '----WebKitFormBoundary'.uniqid('', true);
217217

218218
$this->getClient()->setHeader('Content-Type', 'multipart/form-data; boundary=' . $delimiter);
219219
return join(array_map(function ($param, $name) use ($delimiter) {

tests/ApiTest.php

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
use Cristal\ApiWrapper\Transports\TransportInterface;
77
use Mockery;
88
use PHPUnit\Framework\TestCase;
9+
use TypeError;
910

1011
class ApiTest extends TestCase
1112
{
12-
const ENDPOINTS = ['client', 'catalogue', 'materiel', 'fabricant', 'type', 'tarif', 'caracteristique'];
13+
protected const ENDPOINTS = ['client', 'catalogue', 'materiel', 'fabricant', 'type', 'tarif', 'caracteristique'];
1314
protected $token;
1415
protected $entrypoint;
1516

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;
1920

2021
protected function createFakeTransport()
2122
{
@@ -27,60 +28,50 @@ protected function createFakeTransport()
2728
return $transport;
2829
}
2930

30-
public function setUp()
31+
public function setUp(): void
3132
{
3233
$this->token = 'token_jwt';
3334
$this->entrypoint = 'https://exemple/api/';
3435
}
3536

36-
public function testApiWithoutTransport()
37+
public function testApiWithoutTransport(): void
3738
{
38-
$this->expectException(\TypeError::class);
39+
$this->expectException(TypeError::class);
3940
new Api(null);
4041
}
4142

42-
public function testApiWithTransport()
43+
public function testApiWithTransport(): void
4344
{
4445
$transport = Mockery::mock(TransportInterface::class);
4546
$api = new Api($transport);
46-
$this->assertInstanceOf(TransportInterface::class, $api->getTransport());
47+
self::assertInstanceOf(TransportInterface::class, $api->getTransport());
4748
}
4849

49-
public function testGetWithoutFilters()
50+
public function testGetWithoutFilters(): void
5051
{
5152
$transport = $this->createFakeTransport();
5253
$api = new Api($transport);
5354
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'}());
5556
}
5657
}
5758

58-
public function testGetWithFilters()
59+
public function testGetWithFilters(): void
5960
{
6061
$transport = $this->createFakeTransport();
6162
$api = new Api($transport);
6263
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));
6465
}
6566
}
6667

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
7869
{
7970
$transport = $this->createFakeTransport();
8071
$api = new Api($transport);
8172
foreach (self::ENDPOINTS as $endpoint) {
8273
$entity = $api->{'get'.ucfirst($endpoint)}(self::ID_ENTITY);
83-
$this->assertInternalType('array', $entity);
74+
self::assertIsArray($entity);
8475
}
8576
}
8677
}

0 commit comments

Comments
 (0)