File tree Expand file tree Collapse file tree 12 files changed +686
-0
lines changed
Endpoints/ServersEndpoint Expand file tree Collapse file tree 12 files changed +686
-0
lines changed Original file line number Diff line number Diff line change 1212 <testsuites >
1313 <testsuite name =" LKDevelopment Test Suite" >
1414 <directory >tests</directory >
15+ <exclude >./tests/server</exclude >
1516 </testsuite >
1617 </testsuites >
1718 <filter >
1819 <whitelist >
1920 <directory suffix =" .php" >src/</directory >
2021 </whitelist >
2122 </filter >
23+ <php >
24+ <env name =" TEST_SERVER_PORT" value =" 8000" />
25+ </php >
2226 <logging >
2327 <log type =" tap" target =" build/report.tap" />
2428 <log type =" junit" target =" build/report.junit.xml" />
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Created by PhpStorm.
4+ * User: lukaskammerling
5+ * Date: 30.05.18
6+ * Time: 14:59
7+ */
8+
9+ namespace Tests \Endpoints \ServersEndpoint ;
10+
11+ use LKDev \HetznerCloud \Models \Servers \Servers ;
12+ use Tests \TestCase ;
13+
14+ /**
15+ *
16+ */
17+ class ServersTest extends TestCase
18+ {
19+
20+ /**
21+ * @var Servers
22+ */
23+ protected $ endpoint ;
24+
25+ /**
26+ *
27+ */
28+ public function setUp ()
29+ {
30+ parent ::setUp (); // TODO: Change the autogenerated stub
31+ $ this ->endpoint = new Servers ();
32+ }
33+
34+ /**
35+ *
36+ */
37+ public function testAll ()
38+ {
39+ $ resp = json_encode ($ this ->endpoint ->all ());
40+
41+ $ expected = $ this ->getExpectedResponse ('servers/all ' );
42+ $ this ->assertEquals ($ expected , $ resp );
43+ }
44+
45+ /**
46+ *
47+ */
48+ /*public function testGet()
49+ {
50+
51+ }*/
52+
53+ /**
54+ *
55+ */
56+ /*public function testCreate()
57+ {
58+
59+ }*/
60+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Created by PhpStorm.
4+ * User: lukaskammerling
5+ * Date: 30.05.18
6+ * Time: 14:13
7+ */
8+
9+ namespace Tests ;
10+
11+
12+ use GuzzleHttp \Client ;
13+
14+ class Server
15+ {
16+
17+ /** @var \GuzzleHttp\Client */
18+ protected $ client ;
19+
20+ public function __construct (Client $ client )
21+ {
22+ static ::boot ();
23+ $ this ->client = $ client ;
24+ }
25+
26+ public static function boot ()
27+ {
28+ if (!file_exists (__DIR__ . '/server/vendor ' )) {
29+ exec ('cd " ' . __DIR__ . '/server"; composer install ' );
30+ }
31+ if (static ::serverHasBooted ()) {
32+ return ;
33+ }
34+ $ pid = exec ('php -S ' . static ::getServerUrl () . ' -t ./tests/server/public > /dev/null 2>&1 & echo $! ' );
35+ while (!static ::serverHasBooted ()) {
36+ usleep (1000 );
37+ }
38+ register_shutdown_function (function () use ($ pid ) {
39+ exec ('kill ' . $ pid );
40+ });
41+ }
42+
43+ public static function getServerUrl (string $ endPoint = '' ): string
44+ {
45+ return 'localhost: ' . getenv ('TEST_SERVER_PORT ' ) . '/ ' . $ endPoint ;
46+ }
47+
48+ public static function serverHasBooted (): bool
49+ {
50+ return @file_get_contents ('http:// ' . self ::getServerUrl ('booted ' )) != false ;
51+ }
52+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Created by PhpStorm.
4+ * User: lukaskammerling
5+ * Date: 30.05.18
6+ * Time: 14:13
7+ */
8+
9+ namespace Tests ;
10+
11+
12+ use GuzzleHttp \Client ;
13+ use LKDev \HetznerCloud \HetznerAPIClient ;
14+
15+ abstract class TestCase extends \PHPUnit \Framework \TestCase
16+ {
17+
18+ protected $ hetznerApi ;
19+
20+ public function setUp ()
21+ {
22+ $ this ->server = new Server (new Client ());
23+ Server::boot ();
24+ $ this ->hetznerApi = new HetznerAPIClient ('abcdef ' , 'http://localhost:8000/v1/ ' );
25+ }
26+
27+ public function getExpectedResponse ($ response ): string
28+ {
29+ $ tmp = json_decode (file_get_contents (__DIR__ . '/server/response/ ' . $ response . '.json ' ));
30+ $ mtp = \GuzzleHttp \json_encode ($ tmp );
31+
32+ return $ mtp ;
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ APP_DEBUG = true
2+ APP_KEY = KRR4MbTdLUte7Tvq4uYUyhmFHHpVzLPR
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ $ router ->group (['prefix ' => 'servers ' ], function ($ route ) {
4+
5+ $ route ->group (['prefix ' => '{server_id} ' ], function ($ route ) {
6+ $ route ->get ('/ ' , function ($ id ) {
7+ return response (file_get_contents (RESPONSE_PATH . 'servers/one.json ' ));
8+ });
9+ $ route ->put ('/ ' , function ($ id ) {
10+ return response (file_get_contents (RESPONSE_PATH . 'servers/change_name.json ' ));
11+ });
12+ });
13+ $ route ->get ('/ ' , function () {
14+ return response (file_get_contents (RESPONSE_PATH . 'servers/all.json ' ));
15+ });
16+ });
Original file line number Diff line number Diff line change 1+ {
2+ "servers" : [
3+ {
4+ "id" : 42 ,
5+ "name" : " my-server" ,
6+ "status" : " running" ,
7+ "created" : " 2016-01-30T23:50+00:00" ,
8+ "public_net" : {
9+ "ipv4" : {
10+ "ip" : " 1.2.3.4" ,
11+ "blocked" : false ,
12+ "dns_ptr" : " server01.example.com"
13+ },
14+ "ipv6" : {
15+ "ip" : " 2001:db8::/64" ,
16+ "blocked" : false ,
17+ "dns_ptr" : [
18+ {
19+ "ip" : " 2001:db8::1" ,
20+ "dns_ptr" : " server.example.com"
21+ }
22+ ]
23+ },
24+ "floating_ips" : [
25+ 478
26+ ]
27+ },
28+ "server_type" : {
29+ "id" : 1 ,
30+ "name" : " cx11" ,
31+ "description" : " CX11" ,
32+ "cores" : 1 ,
33+ "memory" : 1 ,
34+ "disk" : 25 ,
35+ "prices" : [
36+ {
37+ "location" : " fsn1" ,
38+ "price_hourly" : {
39+ "net" : " 1" ,
40+ "gross" : " 1.19"
41+ },
42+ "price_monthly" : {
43+ "net" : " 1" ,
44+ "gross" : " 1.19"
45+ }
46+ }
47+ ],
48+ "storage_type" : " local"
49+ },
50+ "datacenter" : {
51+ "id" : 1 ,
52+ "name" : " fsn1-dc8" ,
53+ "description" : " Falkenstein 1 DC 8" ,
54+ "location" : {
55+ "id" : 1 ,
56+ "name" : " fsn1" ,
57+ "description" : " Falkenstein DC Park 1" ,
58+ "country" : " DE" ,
59+ "city" : " Falkenstein" ,
60+ "latitude" : 50.47612 ,
61+ "longitude" : 12.370071
62+ },
63+ "server_types" : {
64+ "supported" : [
65+ 1 ,
66+ 2 ,
67+ 3
68+ ],
69+ "available" : [
70+ 1 ,
71+ 2 ,
72+ 3
73+ ]
74+ }
75+ },
76+ "image" : {
77+ "id" : 4711 ,
78+ "type" : " system" ,
79+ "status" : " available" ,
80+ "name" : " ubuntu-16.04" ,
81+ "description" : " Ubuntu 16.04 Standard 64 bit" ,
82+ "image_size" : 2.3 ,
83+ "disk_size" : 10 ,
84+ "created" : " 2016-01-30T23:50+00:00" ,
85+ "created_from" : {
86+ "id" : 1 ,
87+ "name" : " Server"
88+ },
89+ "bound_to" : 1 ,
90+ "os_flavor" : " ubuntu" ,
91+ "os_version" : " 16.04" ,
92+ "rapid_deploy" : false ,
93+ "protection" : {
94+ "delete" : false
95+ },
96+ "deprecated" : " 2018-02-28T00:00:00+00:00"
97+ },
98+ "iso" : {
99+ "id" : 4711 ,
100+ "name" : " FreeBSD-11.0-RELEASE-amd64-dvd1" ,
101+ "description" : " FreeBSD 11.0 x64" ,
102+ "type" : " public" ,
103+ "deprecated" : " 2018-02-28T00:00:00+00:00"
104+ },
105+ "rescue_enabled" : false ,
106+ "locked" : false ,
107+ "backup_window" : " 22-02" ,
108+ "outgoing_traffic" : 123456 ,
109+ "ingoing_traffic" : 123456 ,
110+ "included_traffic" : 654321 ,
111+ "protection" : {
112+ "delete" : false ,
113+ "rebuild" : false
114+ }
115+ }
116+ ]
117+ }
You can’t perform that action at this time.
0 commit comments