CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • ConsoleIntegrationTestCase
  • IntegrationTestCase
  • LegacyCommandRunner
  • LegacyShellDispatcher
  • TestCase
  • TestEmailTransport
  • TestSuite

Traits

  • ConsoleIntegrationTestTrait
  • EmailAssertTrait
  • EmailTrait
  • IntegrationTestTrait
  • StringCompareTrait
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.7.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\TestSuite;
 16: 
 17: use Cake\TestSuite\Constraint\Email\MailContains;
 18: use Cake\TestSuite\Constraint\Email\MailContainsHtml;
 19: use Cake\TestSuite\Constraint\Email\MailContainsText;
 20: use Cake\TestSuite\Constraint\Email\MailCount;
 21: use Cake\TestSuite\Constraint\Email\MailSentFrom;
 22: use Cake\TestSuite\Constraint\Email\MailSentTo;
 23: use Cake\TestSuite\Constraint\Email\MailSentWith;
 24: use Cake\TestSuite\Constraint\Email\NoMailSent;
 25: 
 26: /**
 27:  * Make assertions on emails sent through the Cake\TestSuite\TestEmailTransport
 28:  *
 29:  * After adding the trait to your test case, all mail transports will be replaced
 30:  * with TestEmailTransport which is used for making assertions and will *not* actually
 31:  * send emails.
 32:  */
 33: trait EmailTrait
 34: {
 35:     /**
 36:      * Replaces all transports with the test transport during test setup
 37:      *
 38:      * @before
 39:      * @return void
 40:      */
 41:     public function setupTransports()
 42:     {
 43:         TestEmailTransport::replaceAllTransports();
 44:     }
 45: 
 46:     /**
 47:      * Resets transport state
 48:      *
 49:      * @after
 50:      * @return void
 51:      */
 52:     public function cleanupEmailTrait()
 53:     {
 54:         TestEmailTransport::clearEmails();
 55:     }
 56: 
 57:     /**
 58:      * Asserts an expected number of emails were sent
 59:      *
 60:      * @param int $count Email count
 61:      * @param string $message Message
 62:      * @return void
 63:      */
 64:     public function assertMailCount($count, $message = null)
 65:     {
 66:         $this->assertThat($count, new MailCount(), $message);
 67:     }
 68:     /**
 69:      *
 70:      * Asserts that no emails were sent
 71:      *
 72:      * @param string $message Message
 73:      * @return void
 74:      */
 75:     public function assertNoMailSent($message = null)
 76:     {
 77:         $this->assertThat(null, new NoMailSent(), $message);
 78:     }
 79: 
 80:     /**
 81:      * Asserts an email at a specific index was sent to an address
 82:      *
 83:      * @param int $at Email index
 84:      * @param string $address Email address
 85:      * @param string $message Message
 86:      * @return void
 87:      */
 88:     public function assertMailSentToAt($at, $address, $message = null)
 89:     {
 90:         $this->assertThat($address, new MailSentTo($at), $message);
 91:     }
 92: 
 93:     /**
 94:      * Asserts an email at a specific index was sent from an address
 95:      *
 96:      * @param int $at Email index
 97:      * @param string $address Email address
 98:      * @param string $message Message
 99:      * @return void
100:      */
101:     public function assertMailSentFromAt($at, $address, $message = null)
102:     {
103:         $this->assertThat($address, new MailSentFrom($at), $message);
104:     }
105: 
106:     /**
107:      * Asserts an email at a specific index contains expected contents
108:      *
109:      * @param int $at Email index
110:      * @param string $contents Contents
111:      * @param string $message Message
112:      * @return void
113:      */
114:     public function assertMailContainsAt($at, $contents, $message = null)
115:     {
116:         $this->assertThat($contents, new MailContains($at), $message);
117:     }
118: 
119:     /**
120:      * Asserts an email at a specific index contains expected html contents
121:      *
122:      * @param int $at Email index
123:      * @param string $contents Contents
124:      * @param string $message Message
125:      * @return void
126:      */
127:     public function assertMailContainsHtmlAt($at, $contents, $message = null)
128:     {
129:         $this->assertThat($contents, new MailContainsHtml($at), $message);
130:     }
131: 
132:     /**
133:      * Asserts an email at a specific index contains expected text contents
134:      *
135:      * @param int $at Email index
136:      * @param string $contents Contents
137:      * @param string $message Message
138:      * @return void
139:      */
140:     public function assertMailContainsTextAt($at, $contents, $message = null)
141:     {
142:         $this->assertThat($contents, new MailContainsText($at), $message);
143:     }
144: 
145:     /**
146:      * Asserts an email at a specific index contains the expected value within an Email getter
147:      *
148:      * @param int $at Email index
149:      * @param string $expected Contents
150:      * @param string $parameter Email getter parameter (e.g. "cc", "subject")
151:      * @param string $message Message
152:      * @return void
153:      */
154:     public function assertMailSentWithAt($at, $expected, $parameter, $message = null)
155:     {
156:         $this->assertThat($expected, new MailSentWith($at, $parameter), $message);
157:     }
158: 
159:     /**
160:      * Asserts an email was sent to an address
161:      *
162:      * @param string $address Email address
163:      * @param string $message Message
164:      * @return void
165:      */
166:     public function assertMailSentTo($address, $message = null)
167:     {
168:         $this->assertThat($address, new MailSentTo(), $message);
169:     }
170: 
171:     /**
172:      * Asserts an email was sent from an address
173:      *
174:      * @param string $address Email address
175:      * @param string $message Message
176:      * @return void
177:      */
178:     public function assertMailSentFrom($address, $message = null)
179:     {
180:         $this->assertThat($address, new MailSentFrom(), $message);
181:     }
182: 
183:     /**
184:      * Asserts an email contains expected contents
185:      *
186:      * @param string $contents Contents
187:      * @param string $message Message
188:      * @return void
189:      */
190:     public function assertMailContains($contents, $message = null)
191:     {
192:         $this->assertThat($contents, new MailContains(), $message);
193:     }
194: 
195:     /**
196:      * Asserts an email contains expected html contents
197:      *
198:      * @param string $contents Contents
199:      * @param string $message Message
200:      * @return void
201:      */
202:     public function assertMailContainsHtml($contents, $message = null)
203:     {
204:         $this->assertThat($contents, new MailContainsHtml(), $message);
205:     }
206: 
207:     /**
208:      * Asserts an email contains an expected text content
209:      *
210:      * @param string $expectedText Expected text.
211:      * @param string $message Message to display if assertion fails.
212:      * @return void
213:      */
214:     public function assertMailContainsText($expectedText, $message = null)
215:     {
216:         $this->assertThat($expectedText, new MailContainsText(), $message);
217:     }
218: 
219:     /**
220:      * Asserts an email contains the expected value within an Email getter
221:      *
222:      * @param string $expected Contents
223:      * @param string $parameter Email getter parameter (e.g. "cc", "subject")
224:      * @param string $message Message
225:      * @return void
226:      */
227:     public function assertMailSentWith($expected, $parameter, $message = null)
228:     {
229:         $this->assertThat($expected, new MailSentWith(null, $parameter), $message);
230:     }
231: }
232: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs