From 0b499f828b3cbbb8069eab214fa020bf8af1657d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 8 Nov 2023 15:37:36 -0800 Subject: [PATCH] MenuXmlTest - Improve debug output. Use richer helpers. In automated test-runs, the e2e test for `mixin/menu-xml@1` (`MenuXmlTest`) has been failing sporadically. The failure always involves one of the HTTP sub-requests, but it's never clear what actually happened in the HTTP sub-request. This patch improves debug info. Before ------- Send HTTP sub-request with simple primitives (`cv` + `file_get_contents`). No detailed information about the failed request. After ----- Send HTTP sub-request with `HttpTestTrait` (`guzzle`). Use rich assertions that log more detailed information. --- .../example/tests/mixin/MenuXmlTest.php | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/mixin/menu-xml@1/example/tests/mixin/MenuXmlTest.php b/mixin/menu-xml@1/example/tests/mixin/MenuXmlTest.php index 4e50f8b0ab..c8bc65cc8f 100644 --- a/mixin/menu-xml@1/example/tests/mixin/MenuXmlTest.php +++ b/mixin/menu-xml@1/example/tests/mixin/MenuXmlTest.php @@ -2,6 +2,8 @@ namespace Civi\Shimmy\Mixins; +use Civi\Test\HttpTestTrait; + /** * Assert that the `xml/Menu/*.xml` mixin is working properly. * @@ -12,11 +14,7 @@ namespace Civi\Shimmy\Mixins; */ class MenuXmlTest extends \PHPUnit\Framework\Assert { - /** - * The URL of hte example route, `civicrm/shimmy/foobar`. - * @var string - */ - protected $url; + use HttpTestTrait; public function testPreConditions($cv): void { $this->assertFileExists(static::getPath('/xml/Menu/shimmy.xml'), 'The shimmy extension must have a Menu XML file.'); @@ -27,21 +25,18 @@ class MenuXmlTest extends \PHPUnit\Framework\Assert { $items = $cv->api4('Route', 'get', ['where' => [['path', '=', 'civicrm/shimmy/foobar']]]); $this->assertEquals('CRM_Shimmy_Page_FooBar', $items[0]['page_callback']); - // And the menu item works... - $this->url = cv('url civicrm/shimmy/foobar'); - $this->assertTrue(is_string($this->url)); - $response = file_get_contents($this->url); - $this->assertMatchesRegularExpression(';hello world;', $response); + $response = $this->createGuzzle()->get('frontend://civicrm/shimmy/foobar'); + $this->assertStatusCode(200, $response); + $this->assertBodyRegexp(';hello world;', $response); } public function testDisabled($cv): void { $items = $cv->api4('Route', 'get', ['where' => [['path', '=', 'civicrm/shimmy/foobar']]]); $this->assertEmpty($items); - $this->assertNotEmpty($this->url); - $response = file_get_contents($this->url, FALSE, stream_context_create(['http' => ['ignore_errors' => TRUE]])); - $this->assertDoesNotMatchRegularExpression(';hello world;', $response); - $this->assertDoesNotMatchRegularExpression(';HTTP.*200.*;', $http_response_header[0]); + $response = $this->createGuzzle(['http_errors' => FALSE])->get('frontend://civicrm/shimmy/foobar'); + $this->assertPageNotShown($response); + $this->assertNotBodyRegexp(';hello world;', $response); } public function testUninstalled($cv): void { -- 2.25.1