Skip to content

Commit 5d904e0

Browse files
authored
add docs for new mockModel method in TestCase (#8276)
1 parent 3adcb23 commit 5d904e0

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

docs/en/appendices/5-4-migration-guide.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ version is reported as `unknown`), the header is omitted.
7777
`league/container` implementation by setting `App.container` to `cake` inside your `config/app.php`.
7878
See [Dependency Injection Container](../development/dependency-injection) for more details.
7979

80+
### Collection
81+
82+
- Added [`keys()`](../core-libraries/collections#keys) and [`values()`](../core-libraries/collections#values) methods for extracting keys or re-indexing values.
83+
- Added [`implode()`](../core-libraries/collections#implode) method to concatenate elements into a string.
84+
- Added [`when()`](../core-libraries/collections#when) and [`unless()`](../core-libraries/collections#unless) methods for conditional method chaining.
85+
8086
### Commands
8187

8288
- You can use `$this->io` and `$this->args` inside your commands to access input/output and argument objects
@@ -118,6 +124,12 @@ version is reported as `unknown`), the header is omitted.
118124
`Index::BRIN`, `Index::HASH`) for these access methods.
119125
See [Reading Indexes and Constraints](../orm/schema-system#reading-indexes-and-constraints).
120126

127+
### Http
128+
129+
- Added PSR-13 Link implementation with `Cake\Http\Link\Link` and `Cake\Http\Link\LinkProvider`
130+
classes for hypermedia link support. Links added to responses are automatically emitted
131+
as HTTP `Link` headers. See [Hypermedia Links](../controllers/request-response#hypermedia-links).
132+
121133
### I18n
122134

123135
- `Number::toReadableSize()` now uses decimal units (KB = 1000 bytes) by default.
@@ -129,11 +141,9 @@ version is reported as `unknown`), the header is omitted.
129141
nested array format matching `contain()` syntax.
130142
See [Converting Request Data into Entities](../orm/saving-data#converting-request-data-into-entities).
131143

132-
### Http
144+
### Testsuite
133145

134-
- Added PSR-13 Link implementation with `Cake\Http\Link\Link` and `Cake\Http\Link\LinkProvider`
135-
classes for hypermedia link support. Links added to responses are automatically emitted
136-
as HTTP `Link` headers. See [Hypermedia Links](../controllers/request-response#hypermedia-links).
146+
- `TestCase::mockModel()` has been added to allow mocking of model classes in tests using Mockery mocks.
137147

138148
### Utility
139149

@@ -144,12 +154,6 @@ version is reported as `unknown`), the header is omitted.
144154
You can set `Security.encryptWithRawKey` to enable this behavior. See [here](https://github.com/cakephp/cakephp/pull/19325) for more details.
145155
- Added `Text::mask()` method which masks a portion of a string with a repeated character. See [Text Masking](../core-libraries/text.md#text-masking) for more details.
146156

147-
### Collection
148-
149-
- Added [`keys()`](../core-libraries/collections#keys) and [`values()`](../core-libraries/collections#values) methods for extracting keys or re-indexing values.
150-
- Added [`implode()`](../core-libraries/collections#implode) method to concatenate elements into a string.
151-
- Added [`when()`](../core-libraries/collections#when) and [`unless()`](../core-libraries/collections#unless) methods for conditional method chaining.
152-
153157
### View
154158

155159
- Added `{{inputId}}` template variable to `inputContainer` and `error` templates

docs/en/development/testing.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,23 @@ In your `tearDown()` method be sure to remove the mock with:
10431043
$this->getTableLocator()->clear();
10441044
```
10451045

1046+
::: info Added in version 5.4
1047+
:::
1048+
1049+
If you prefer Mockery mocks you can use `mockModel()` instead of `getMockForModel()`.
1050+
1051+
```php
1052+
public function testSendingEmails(): void
1053+
{
1054+
$model = $this->mockModel('EmailVerification');
1055+
$mock->shouldReceive('send')
1056+
->once()
1057+
->andReturn(true);
1058+
1059+
$model->verifyEmail('test@example.com');
1060+
}
1061+
```
1062+
10461063
<a id="integration-testing"></a>
10471064

10481065
## Controller Integration Testing

0 commit comments

Comments
 (0)