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.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 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:      *
 71:      * Asserts that no emails were sent
 72:      *
 73:      * @param string $message Message
 74:      * @return void
 75:      */
 76:     public function assertNoMailSent($message = null)
 77:     {
 78:         $this->assertThat(null, new NoMailSent(), $message);
 79:     }
 80: 
 81:     /**
 82:      * Asserts an email at a specific index was sent to an address
 83:      *
 84:      * @param int $at Email index
 85:      * @param string $address Email address
 86:      * @param string $message Message
 87:      * @return void
 88:      */
 89:     public function assertMailSentToAt($at, $address, $message = null)
 90:     {
 91:         $this->assertThat($address, new MailSentTo($at), $message);
 92:     }
 93: 
 94:     /**
 95:      * Asserts an email at a specific index was sent from an address
 96:      *
 97:      * @param int $at Email index
 98:      * @param string $address Email address
 99:      * @param string $message Message
100:      * @return void
101:      */
102:     public function assertMailSentFromAt($at, $address, $message = null)
103:     {
104:         $this->assertThat($address, new MailSentFrom($at), $message);
105:     }
106: 
107:     /**
108:      * Asserts an email at a specific index contains expected contents
109:      *
110:      * @param int $at Email index
111:      * @param string $contents Contents
112:      * @param string $message Message
113:      * @return void
114:      */
115:     public function assertMailContainsAt($at, $contents, $message = null)
116:     {
117:         $this->assertThat($contents, new MailContains($at), $message);
118:     }
119: 
120:     /**
121:      * Asserts an email at a specific index contains expected html contents
122:      *
123:      * @param int $at Email index
124:      * @param string $contents Contents
125:      * @param string $message Message
126:      * @return void
127:      */
128:     public function assertMailContainsHtmlAt($at, $contents, $message = null)
129:     {
130:         $this->assertThat($contents, new MailContainsHtml($at), $message);
131:     }
132: 
133:     /**
134:      * Asserts an email at a specific index contains expected text contents
135:      *
136:      * @param int $at Email index
137:      * @param string $contents Contents
138:      * @param string $message Message
139:      * @return void
140:      */
141:     public function assertMailContainsTextAt($at, $contents, $message = null)
142:     {
143:         $this->assertThat($contents, new MailContainsText($at), $message);
144:     }
145: 
146:     /**
147:      * Asserts an email at a specific index contains the expected value within an Email getter
148:      *
149:      * @param int $at Email index
150:      * @param string $expected Contents
151:      * @param string $parameter Email getter parameter (e.g. "cc", "subject")
152:      * @param string $message Message
153:      * @return void
154:      */
155:     public function assertMailSentWithAt($at, $expected, $parameter, $message = null)
156:     {
157:         $this->assertThat($expected, new MailSentWith($at, $parameter), $message);
158:     }
159: 
160:     /**
161:      * Asserts an email was sent to an address
162:      *
163:      * @param string $address Email address
164:      * @param string $message Message
165:      * @return void
166:      */
167:     public function assertMailSentTo($address, $message = null)
168:     {
169:         $this->assertThat($address, new MailSentTo(), $message);
170:     }
171: 
172:     /**
173:      * Asserts an email was sent from an address
174:      *
175:      * @param string $address Email address
176:      * @param string $message Message
177:      * @return void
178:      */
179:     public function assertMailSentFrom($address, $message = null)
180:     {
181:         $this->assertThat($address, new MailSentFrom(), $message);
182:     }
183: 
184:     /**
185:      * Asserts an email contains expected contents
186:      *
187:      * @param string $contents Contents
188:      * @param string $message Message
189:      * @return void
190:      */
191:     public function assertMailContains($contents, $message = null)
192:     {
193:         $this->assertThat($contents, new MailContains(), $message);
194:     }
195: 
196:     /**
197:      * Asserts an email contains expected html contents
198:      *
199:      * @param string $contents Contents
200:      * @param string $message Message
201:      * @return void
202:      */
203:     public function assertMailContainsHtml($contents, $message = null)
204:     {
205:         $this->assertThat($contents, new MailContainsHtml(), $message);
206:     }
207: 
208:     /**
209:      * Asserts an email contains an expected text content
210:      *
211:      * @param string $expectedText Expected text.
212:      * @param string $message Message to display if assertion fails.
213:      * @return void
214:      */
215:     public function assertMailContainsText($expectedText, $message = null)
216:     {
217:         $this->assertThat($expectedText, new MailContainsText(), $message);
218:     }
219: 
220:     /**
221:      * Asserts an email contains the expected value within an Email getter
222:      *
223:      * @param string $expected Contents
224:      * @param string $parameter Email getter parameter (e.g. "cc", "subject")
225:      * @param string $message Message
226:      * @return void
227:      */
228:     public function assertMailSentWith($expected, $parameter, $message = null)
229:     {
230:         $this->assertThat($expected, new MailSentWith(null, $parameter), $message);
231:     }
232: }
233: 
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