ServerRequestFromGlobalsTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. declare(strict_types=1);
  3. namespace GuzzleHttp\Tests\Psr7\Integration;
  4. use PHPUnit\Framework\TestCase;
  5. class ServerRequestFromGlobalsTest extends TestCase
  6. {
  7. protected function setUp(): void
  8. {
  9. if (false === $this->getServerUri()) {
  10. self::markTestSkipped();
  11. }
  12. parent::setUp();
  13. }
  14. public function testBodyExists(): void
  15. {
  16. $curl = curl_init();
  17. curl_setopt($curl, CURLOPT_URL, $this->getServerUri());
  18. curl_setopt($curl, CURLOPT_POST, 1);
  19. curl_setopt($curl, CURLOPT_POSTFIELDS, 'foobar');
  20. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  21. $response = curl_exec($curl);
  22. curl_close($curl);
  23. self::assertNotFalse($response);
  24. $data = json_decode($response, true);
  25. self::assertIsArray($data);
  26. self::assertArrayHasKey('method', $data);
  27. self::assertArrayHasKey('uri', $data);
  28. self::assertArrayHasKey('body', $data);
  29. self::assertEquals('foobar', $data['body']);
  30. }
  31. private function getServerUri()
  32. {
  33. return $_SERVER['TEST_SERVER'] ?? false;
  34. }
  35. }