Skip to content

Commit a6649cb

Browse files
author
Lorenzo Paderi
committed
test: use PHPUnit for tests
1 parent 32c7016 commit a6649cb

3 files changed

Lines changed: 63 additions & 39 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
}
1818
},
1919
"require-dev": {
20-
"symfony/dotenv": "^5.3"
20+
"symfony/dotenv": "^5.3",
21+
"phpunit/phpunit": "^9.5"
2122
}
2223
}

tests/ClientTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
use OpenApi\OpenApi;
4+
use PHPUnit\Framework\TestCase;
5+
use Symfony\Component\Dotenv\Dotenv;
6+
7+
require_once 'vendor/autoload.php';
8+
9+
final class ClientTest extends TestCase {
10+
11+
public Dotenv $dotenv;
12+
public string $username;
13+
public string $api_key;
14+
public array $scopes;
15+
public OpenApi $openapi;
16+
17+
public function __construct() {
18+
parent::__construct();
19+
$this->dotenv = new Dotenv();
20+
$this->dotenv->load(__DIR__.'/../.env');
21+
22+
$this->username = $_ENV['OPENAPI_USERNAME'];
23+
$this->api_key = $_ENV['API_KEY'];
24+
25+
// Dichiaro gli scopes necessari
26+
$this->scopes = [
27+
"GET:ws.ufficiopostale.com/telegrammi",
28+
"GET:imprese.altravia.com/autocomplete",
29+
"GET:imprese.openapi.it/base",
30+
"GET:imprese.openapi.it/advance",
31+
"GET:imprese.openapi.it/pec",
32+
"GET:imprese.openapi.it/autocomplete",
33+
"GET:imprese.openapi.it/closed",
34+
"GET:imprese.openapi.it/gruppoiva",
35+
"GET:comuni.openapi.it/cap",
36+
"GET:comuni.openapi.it/istat",
37+
"GET:comuni.openapi.it/regioni",
38+
"GET:comuni.openapi.it/province",
39+
"POST:geocoding.realgest.it/geocode"
40+
];
41+
42+
$this->openapi = new OpenApi($this->scopes, $this->username, $this->api_key, 'test');
43+
}
44+
45+
46+
public function testClientInstance() {
47+
$this->assertInstanceOf('OpenApi\OpenApi', $this->openapi);
48+
}
49+
50+
public function testComuni() {
51+
// Prendi informazioni sul cap 00132
52+
$cap = $this->openapi->comuni->getCitiesByCap('00132');
53+
$this->assertIsArray($cap);
54+
}
55+
56+
public function testGeocoding() {
57+
// Prendi informazioni sul cap 00132
58+
$cap = $this->openapi->geocoding->geocode('Via Cristoforo Colombo, Roma RM');
59+
$this->assertIsArray($cap);
60+
}
61+
}

tests/example_test.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)