Browse Source

Adapt assertRedirectNotContains to use constraints.

Refs #12447
Refs #12446
Mark Story 7 years ago
parent
commit
de8c639ed5

+ 3 - 8
src/TestSuite/IntegrationTestTrait.php

@@ -35,6 +35,7 @@ use Cake\TestSuite\Constraint\Response\FileSent;
 use Cake\TestSuite\Constraint\Response\FileSentAs;
 use Cake\TestSuite\Constraint\Response\HeaderContains;
 use Cake\TestSuite\Constraint\Response\HeaderEquals;
+use Cake\TestSuite\Constraint\Response\HeaderNotContains;
 use Cake\TestSuite\Constraint\Response\HeaderNotSet;
 use Cake\TestSuite\Constraint\Response\HeaderSet;
 use Cake\TestSuite\Constraint\Response\StatusCode;
@@ -864,14 +865,8 @@ trait IntegrationTestTrait
      */
     public function assertRedirectNotContains($url, $message = '')
     {
-        if (!$this->_response) {
-            $this->fail('No response set, cannot assert location header. ' . $message);
-        }
-        $result = $this->_response->header();
-        if (empty($result['Location'])) {
-            $this->fail('No location header set. ' . $message);
-        }
-        $this->assertNotContains($url, $result['Location'], $message);
+        $this->assertThat(null, new HeaderSet($this->_response, 'Location'), $message);
+        $this->assertThat(null, new HeaderNotContains($this->_response, 'Location'), $message);
     }
 
     /**

+ 1 - 1
tests/TestCase/TestSuite/IntegrationTestTraitTest.php

@@ -949,7 +949,7 @@ class IntegrationTestTraitTest extends IntegrationTestCase
     public function testAssertRedirectNotContains()
     {
         $this->_response = new Response();
-        $this->_response->header('Location', 'http://localhost/tasks/index');
+        $this->_response = $this->_response->withHeader('Location', 'http://localhost/tasks/index');
         $this->assertRedirectNotContains('test');
     }