Browse Source

Merge pull request #12064 from gotoeveryone/add-assert-response-not-equals

add: assertResponseNotEquals() and test case.
Mark Story 8 years ago
parent
commit
3db1303fe8

+ 16 - 1
src/TestSuite/IntegrationTestCase.php

@@ -938,7 +938,7 @@ abstract class IntegrationTestCase extends TestCase
     }
 
     /**
-     * Asserts content exists in the response body.
+     * Asserts content in the response body equals.
      *
      * @param mixed $content The content to check for.
      * @param string $message The failure message that will be appended to the generated message.
@@ -953,6 +953,21 @@ abstract class IntegrationTestCase extends TestCase
     }
 
     /**
+     * Asserts content in the response body not equals.
+     *
+     * @param mixed $content The content to check for.
+     * @param string $message The failure message that will be appended to the generated message.
+     * @return void
+     */
+    public function assertResponseNotEquals($content, $message = '')
+    {
+        if (!$this->_response) {
+            $this->fail('No response set, cannot assert content. ' . $message);
+        }
+        $this->assertNotEquals($content, $this->_getBodyAsString(), $message);
+    }
+
+    /**
      * Asserts content exists in the response body.
      *
      * @param string $content The content to check for.

+ 26 - 0
tests/TestCase/TestSuite/IntegrationTestCaseTest.php

@@ -941,6 +941,32 @@ class IntegrationTestCaseTest extends IntegrationTestCase
      *
      * @return void
      */
+    public function testAssertResponseEquals()
+    {
+        $this->_response = new Response();
+        $this->_response = $this->_response->withStringBody('Some content');
+
+        $this->assertResponseEquals('Some content');
+    }
+
+    /**
+     * Test the negated content assertion.
+     *
+     * @return void
+     */
+    public function testAssertResponseNotEquals()
+    {
+        $this->_response = new Response();
+        $this->_response = $this->_response->withStringBody('Some content');
+
+        $this->assertResponseNotEquals('Some Content');
+    }
+
+    /**
+     * Test the content assertion.
+     *
+     * @return void
+     */
     public function testAssertResponseContains()
     {
         $this->_response = new Response();