11<?php
2-
32use PHPUnit \Framework \TestCase ;
43use Codegyan \Client ;
54
@@ -13,26 +12,48 @@ protected function setUp(): void
1312 $ this ->client = new Client ('YOUR_API_KEY ' , 'YOUR_CLIENT_ID ' );
1413 }
1514
16- public function testCompilerCompile ()
15+ public function testCompilePHPCode ()
1716 {
18- $ result = $ this ->client ->compilerApiClient ->compile ([
19- 'language ' => 'php ' ,
20- 'code ' => '<?php echo "Hello, world!"; ' ,
21- ]);
22-
23- $ this ->assertEquals ('Hello, world! ' , $ result ['output ' ]);
17+ // PHP code to be compiled
18+ $ lang = 'php ' ;
19+ $ code = '<?php echo "Hello, world!"; ?> ' ;
20+
21+ // Compile the PHP code
22+ $ result = $ this ->client ->compilerApiClient ->compile ($ lang ,$ code );
23+
24+ // Decode the JSON string into an associative array
25+ $ resultArray = json_decode ($ result , true );
26+
27+ // Perform assertions on the compiled code
28+ $ this ->assertNotEmpty ($ result );
29+ $ this ->assertIsString ($ result );
30+ $ this ->assertStringNotContainsString ('<?php ' , $ result ); // Compiled code should contain PHP opening tag
31+ $ this ->assertStringContainsString ('Hello, world! ' , $ result ); // Compiled code should contain the original code
32+ $ this ->assertEquals ('Hello, world! ' , $ resultArray ['output ' ]);
2433 }
2534
26- public function testToolsApiClientDomainAvailability ()
35+ public function testDomainAvailability ()
2736 {
28- $ result = $ this ->client ->toolsApiClient ->domainAvailability ([
29- 'domain ' => 'codegyan.in ' ,
30- ]);
31-
32- $ this ->assertEquals ('1 ' , $ result ['status ' ]);
33- $ this ->assertEquals ('codegyan.in ' , $ result ['domain ' ]);
34- $ this ->assertEquals ('co.in ' , $ result ['tld ' ]);
35- $ this ->assertEquals ('1 ' , $ result ['available ' ]);
37+ // PHP code to be compiled
38+ $ domain = 'codegyan.in ' ;
39+
40+ // Compile the PHP code
41+ $ result = $ this ->client ->toolsApiClient ->domainAvailability ($ domain );
42+
43+ // Decode the JSON string into an associative array
44+ $ resultArray = json_decode ($ result , true );
45+
46+ // Perform assertions on the response
47+ $ this ->assertNotEmpty ($ resultArray );
48+ $ this ->assertArrayHasKey ('status ' , $ resultArray );
49+ $ this ->assertArrayHasKey ('domain ' , $ resultArray );
50+ $ this ->assertArrayHasKey ('tld ' , $ resultArray );
51+ $ this ->assertArrayHasKey ('available ' , $ resultArray );
52+
53+ // Check if the domain is available
54+ $ this ->assertEquals ('0 ' , $ resultArray ['status ' ]);
55+ $ this ->assertEquals ($ domain , $ resultArray ['domain ' ]);
56+ $ this ->assertEquals ('in ' , $ resultArray ['tld ' ]);
57+ $ this ->assertEquals ('0 ' , $ resultArray ['available ' ]);
3658 }
37-
3859}
0 commit comments