Fix Invalid asset builder test by using guzzle
authorSeamus Lee <seamuslee001@gmail.com>
Sun, 5 May 2019 01:43:12 +0000 (11:43 +1000)
committerTim Otten <totten@civicrm.org>
Thu, 6 Jun 2019 09:16:27 +0000 (02:16 -0700)
tests/phpunit/E2E/Core/AssetBuilderTest.php

index 19df9a3c1cd28fab06a15850ec0a9c9d63fa1c2e..4e5e0bac0caee94fb1ff2488f0481a7fbd90a773 100644 (file)
@@ -162,9 +162,14 @@ class AssetBuilderTest extends \CiviEndToEndTestCase {
   public function testInvalid() {
     \Civi::service('asset_builder')->setCacheEnabled(FALSE);
     $url = \Civi::service('asset_builder')->getUrl('invalid.json');
-    $this->assertEmpty(file_get_contents($url));
-    $this->assertNotEmpty(preg_grep(';HTTP/1.1 404;', $http_response_header),
-      'Expect to find HTTP 404. Found: ' . json_encode(preg_grep(';^HTTP;', $http_response_header)));
+    try {
+      $guzzleClient = new \GuzzleHttp\Client();
+      $guzzleResponse = $guzzleClient->request('GET', $url, array('timeout' => 1));
+    }
+    catch (\GuzzleHttp\Exception\ClientException $e) {
+      $this->assertNotEmpty(preg_match(';404;', $e->getMessage()),
+        'Expect to find HTTP 404. Found: ' . json_encode(preg_match(';^HTTP;', $e->getMessage())));
+    }
   }
 
 }