Browse Source

Fix up Constraints.

mscherer 6 years ago
parent
commit
e45d2bd956

+ 1 - 1
src/TestSuite/Constraint/Response/BodyRegExp.php

@@ -47,6 +47,6 @@ class BodyRegExp extends ResponseBase
      */
     public function failureDescription($other)
     {
-        return $other . ' ' . $this->toString();
+        return '`' . $other . '`' . ' ' . $this->toString();
     }
 }

+ 1 - 1
src/TestSuite/Constraint/Response/ContentType.php

@@ -43,6 +43,6 @@ class ContentType extends ResponseBase
      */
     public function toString()
     {
-        return 'was set as the Content-Type';
+        return 'was set as the Content-Type (`' . $this->response->getType() . '`)';
     }
 }

+ 1 - 1
src/TestSuite/Constraint/Response/HeaderContains.php

@@ -38,6 +38,6 @@ class HeaderContains extends HeaderEquals
      */
     public function toString()
     {
-        return sprintf('is in header \'%s\'', $this->headerName);
+        return sprintf('is in header \'%s\' (`%s`)', $this->headerName, $this->response->getHeaderLine($this->headerName));
     }
 }

+ 4 - 8
src/TestSuite/Constraint/Response/HeaderEquals.php

@@ -28,11 +28,6 @@ class HeaderEquals extends ResponseBase
     protected $headerName;
 
     /**
-     * @var string|null
-     */
-    protected $responseHeader;
-
-    /**
      * Constructor.
      *
      * @param Response $response Response
@@ -43,7 +38,6 @@ class HeaderEquals extends ResponseBase
         parent::__construct($response);
 
         $this->headerName = $headerName;
-        $this->responseHeader = $this->response->getHeaderLine($this->headerName);
     }
 
     /**
@@ -54,7 +48,7 @@ class HeaderEquals extends ResponseBase
      */
     public function matches($other)
     {
-        return $this->responseHeader === $other;
+        return $this->response->getHeaderLine($this->headerName) === $other;
     }
 
     /**
@@ -64,6 +58,8 @@ class HeaderEquals extends ResponseBase
      */
     public function toString()
     {
-        return sprintf('equals content in header \'%s\': `%s`', $this->headerName, $this->responseHeader);
+        $responseHeader = $this->response->getHeaderLine($this->headerName);
+
+        return sprintf('equals content in header \'%s\' (`%s`)', $this->headerName, $responseHeader);
     }
 }

+ 1 - 1
src/TestSuite/Constraint/Response/HeaderNotContains.php

@@ -38,6 +38,6 @@ class HeaderNotContains extends HeaderContains
      */
     public function toString()
     {
-        return sprintf("is not in header '%s'", $this->headerName);
+        return sprintf("is not in header '%s' (`%s`)", $this->headerName, $this->response->getHeaderLine($this->headerName));
     }
 }

+ 1 - 1
src/TestSuite/Constraint/View/LayoutFileEquals.php

@@ -27,6 +27,6 @@ class LayoutFileEquals extends TemplateFileEquals
      */
     public function toString()
     {
-        return sprintf('equals layout file %s', $this->filename);
+        return sprintf('equals layout file `%s`', $this->filename);
     }
 }

+ 1 - 1
src/TestSuite/Constraint/View/TemplateFileEquals.php

@@ -57,6 +57,6 @@ class TemplateFileEquals extends Constraint
      */
     public function toString()
     {
-        return sprintf('equals template file %s', $this->filename);
+        return sprintf('equals template file `%s`', $this->filename);
     }
 }

+ 10 - 9
tests/TestCase/TestSuite/IntegrationTestTraitTest.php

@@ -1497,7 +1497,7 @@ class IntegrationTestTraitTest extends IntegrationTestCase
         $templateDir = TEST_APP . 'TestApp' . DS . 'Template' . DS;
 
         return [
-            'assertContentType' => ['assertContentType', 'Failed asserting that \'test\' was set as the Content-Type.', '/posts/index', 'test'],
+            'assertContentType' => ['assertContentType', 'Failed asserting that \'test\' was set as the Content-Type (`text/html`).', '/posts/index', 'test'],
             'assertContentTypeVerbose' => ['assertContentType', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', 'test'],
             'assertCookie' => ['assertCookie', 'Failed asserting that \'test\' was in cookie \'remember_me\'.', '/posts/index', 'test', 'remember_me'],
             'assertCookieVerbose' => ['assertCookie', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', 'test', 'remember_me'],
@@ -1506,15 +1506,16 @@ class IntegrationTestTraitTest extends IntegrationTestCase
             'assertCookieNotSet' => ['assertCookieNotSet', 'Failed asserting that \'remember_me\' cookie was not set.', '/posts/index', 'remember_me'],
             'assertFileResponse' => ['assertFileResponse', 'Failed asserting that \'test\' file was sent.', '/posts/file', 'test'],
             'assertFileResponseVerbose' => ['assertFileResponse', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', 'test'],
-            'assertHeader' => ['assertHeader', 'Failed asserting that \'test\' equals content in header \'X-Cake\': `custom header`.', '/posts/header', 'X-Cake', 'test'],
-            'assertHeaderContains' => ['assertHeaderContains', 'Failed asserting that \'test\' is in header \'X-Cake\'', '/posts/header', 'X-Cake', 'test'],
+            'assertHeader' => ['assertHeader', 'Failed asserting that \'test\' equals content in header \'X-Cake\' (`custom header`).', '/posts/header', 'X-Cake', 'test'],
+            'assertHeaderContains' => ['assertHeaderContains', 'Failed asserting that \'test\' is in header \'X-Cake\' (`custom header`)', '/posts/header', 'X-Cake', 'test'],
+            'assertHeaderNotContains' => ['assertHeaderNotContains', 'Failed asserting that \'custom header\' is not in header \'X-Cake\' (`custom header`)', '/posts/header', 'X-Cake', 'custom header'],
             'assertHeaderContainsVerbose' => ['assertHeaderContains', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', 'X-Cake', 'test'],
             'assertHeaderNotContainsVerbose' => ['assertHeaderNotContains', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', 'X-Cake', 'test'],
-            'assertLayout' => ['assertLayout', 'Failed asserting that \'custom_layout\' equals layout file ' . $templateDir . 'Layout' . DS . 'default.ctp.', '/posts/index', 'custom_layout'],
+            'assertLayout' => ['assertLayout', 'Failed asserting that \'custom_layout\' equals layout file `' . $templateDir . 'Layout' . DS . 'default.ctp`.', '/posts/index', 'custom_layout'],
             'assertLayoutVerbose' => ['assertLayout', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', 'custom_layout'],
-            'assertRedirect' => ['assertRedirect', 'Failed asserting that \'http://localhost/\' equals content in header \'Location\': `http://localhost/app/Posts`.', '/posts/flashNoRender', '/'],
+            'assertRedirect' => ['assertRedirect', 'Failed asserting that \'http://localhost/\' equals content in header \'Location\' (`http://localhost/app/Posts`).', '/posts/flashNoRender', '/'],
             'assertRedirectVerbose' => ['assertRedirect', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', '/'],
-            'assertRedirectContains' => ['assertRedirectContains', 'Failed asserting that \'/posts/somewhere-else\' is in header \'Location\'.', '/posts/flashNoRender', '/posts/somewhere-else'],
+            'assertRedirectContains' => ['assertRedirectContains', 'Failed asserting that \'/posts/somewhere-else\' is in header \'Location\' (`http://localhost/app/Posts`).', '/posts/flashNoRender', '/posts/somewhere-else'],
             'assertRedirectContainsVerbose' => ['assertRedirectContains', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', '/posts/somewhere-else'],
             'assertRedirectNotContainsVerbose' => ['assertRedirectNotContains', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', '/posts/somewhere-else'],
             'assertResponseCode' => ['assertResponseCode', 'Failed asserting that 302 matches response status code 200.', '/posts/index', 302],
@@ -1527,14 +1528,14 @@ class IntegrationTestTraitTest extends IntegrationTestCase
             'assertResponseNotContains' => ['assertResponseNotContains', 'Failed asserting that \'index\' is not in response body.', '/posts/index', 'index'],
             'assertResponseNotEmpty' => ['assertResponseNotEmpty', 'Failed asserting that response body is not empty.', '/posts/empty_response'],
             'assertResponseNotEquals' => ['assertResponseNotEquals', 'Failed asserting that \'posts index\' does not match response body.', '/posts/index/error', 'posts index'],
-            'assertResponseNotRegExp' => ['assertResponseNotRegExp', 'Failed asserting that /index/ PCRE pattern not found in response body.', '/posts/index/error', '/index/'],
+            'assertResponseNotRegExp' => ['assertResponseNotRegExp', 'Failed asserting that `/index/` PCRE pattern not found in response body.', '/posts/index/error', '/index/'],
             'assertResponseNotRegExpVerbose' => ['assertResponseNotRegExp', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', '/index/'],
             'assertResponseOk' => ['assertResponseOk', 'Failed asserting that 404 is between 200 and 204.', '/posts/missing', '/index/'],
-            'assertResponseRegExp' => ['assertResponseRegExp', 'Failed asserting that /test/ PCRE pattern found in response body.', '/posts/index/error', '/test/'],
+            'assertResponseRegExp' => ['assertResponseRegExp', 'Failed asserting that `/test/` PCRE pattern found in response body.', '/posts/index/error', '/test/'],
             'assertResponseSuccess' => ['assertResponseSuccess', 'Failed asserting that 404 is between 200 and 308.', '/posts/missing'],
             'assertResponseSuccessVerbose' => ['assertResponseSuccess', 'Possibly related to Cake\Controller\Exception\MissingActionException: "Action PostsController::missing() could not be found, or is not accessible."', '/posts/missing'],
             'assertSession' => ['assertSession', 'Failed asserting that \'test\' is in session path \'Missing.path\'.', '/posts/index', 'test', 'Missing.path'],
-            'assertTemplate' => ['assertTemplate', 'Failed asserting that \'custom_template\' equals template file ' . $templateDir . 'Posts' . DS . 'index.ctp.', '/posts/index', 'custom_template'],
+            'assertTemplate' => ['assertTemplate', 'Failed asserting that \'custom_template\' equals template file `' . $templateDir . 'Posts' . DS . 'index.ctp`.', '/posts/index', 'custom_template'],
             'assertTemplateVerbose' => ['assertTemplate', 'Possibly related to Cake\Routing\Exception\MissingRouteException: "A route matching "/notfound" could not be found."', '/notfound', 'custom_template'],
             'assertFlashMessage' => ['assertFlashMessage', 'Failed asserting that \'missing\' was in \'flash\' message.', '/posts/index', 'missing'],
             'assertFlashMessageWithKey' => ['assertFlashMessage', 'Failed asserting that \'missing\' was in \'auth\' message.', '/posts/index', 'missing', 'auth'],