Browse Source

Fixed MailContains constraint when asserting against regexp characters

Jeremy Harris 6 years ago
parent
commit
6b06e1b016

+ 1 - 0
src/TestSuite/Constraint/Email/MailContains.php

@@ -41,6 +41,7 @@ class MailContains extends MailConstraintBase
         foreach ($emails as $email) {
             $message = implode("\r\n", (array)$email->message($this->type));
 
+            $other = preg_quote($other, '/');
             if (preg_match("/$other/", $message) > 0) {
                 return true;
             }

+ 15 - 0
tests/TestCase/TestSuite/EmailTraitTest.php

@@ -160,6 +160,21 @@ class EmailTraitTest extends TestCase
     }
 
     /**
+     * Tests asserting using RegExp characters doesn't break the assertion
+     *
+     * @return void
+     */
+    public function testAssertUsingRegExpCharacters()
+    {
+        (new Email())
+            ->setTo('to3@example.com')
+            ->setCc('cc3@example.com')
+            ->send('email with regexp chars $/[]');
+
+        $this->assertMailContains('$/[]');
+    }
+
+    /**
      * tests constraint failure messages
      *
      * @param string $assertion Assertion method