From 063d765e9445331c41d18ccd4fa2df11137461c3 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 29 May 2018 17:26:18 +1200 Subject: [PATCH 1/2] Add test assertion for response instance This prevents middlewares that return null (like the example delegate in this test) from killing a testsuite --- tests/php/Control/DirectorTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/php/Control/DirectorTest.php b/tests/php/Control/DirectorTest.php index 0070f2a50..ac45e6351 100644 --- a/tests/php/Control/DirectorTest.php +++ b/tests/php/Control/DirectorTest.php @@ -593,6 +593,7 @@ class DirectorTest extends SapphireTest }, 'http://www.mysite.com:9090/some-url'); // Middleware returns non-exception redirect + $this->assertInstanceOf(HTTPResponse::class, $response); $this->assertEquals('https://www.mysite.com:9090/some-url', $response->getHeader('Location')); $this->assertEquals(301, $response->getStatusCode()); } From 7a8a24d1755249eb2ee3624aa11bb112c4bd896f Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 29 May 2018 17:34:22 +1200 Subject: [PATCH 2/2] Reset force SSL domain/patterns in setup to prevent global state pollution --- tests/php/Control/DirectorTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/php/Control/DirectorTest.php b/tests/php/Control/DirectorTest.php index ac45e6351..5e34f2cdd 100644 --- a/tests/php/Control/DirectorTest.php +++ b/tests/php/Control/DirectorTest.php @@ -31,8 +31,13 @@ class DirectorTest extends SapphireTest Director::config()->set('alternate_base_url', 'http://www.mysite.com:9090/'); // Ensure redirects enabled on all environments - CanonicalURLMiddleware::singleton()->setEnabledEnvs(true); + $middleware = CanonicalURLMiddleware::singleton()->setEnabledEnvs(true); $this->expectedRedirect = null; + + // Ensure global state doesn't affect this test + $middleware + ->setForceSSLDomain(null) + ->setForceSSLPatterns([]); } protected function getExtraRoutes()