Skip to content

Commit 4e0542a

Browse files
committed
Documentation
1 parent f6e2250 commit 4e0542a

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

README.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,27 @@ abstract class TestCase extends BaseTestCase
2626
}
2727
```
2828

29-
## Assertions
30-
This package adds several assertions helpful when writing [HTTP Tests](https://laravel.com/docs/http-tests).
31-
29+
## Documentation
30+
This package adds several assertions, matchers, and helpers aimed at making testing within Laravel easier.
3231

32+
### Assertions
3333
```php
3434
assertActionUsesFormRequest(string $controller, string $method, string $form_request)
3535
```
3636

3737
Verifies the _action_ for a given controller performs validation using the given form request.
3838

3939
```php
40-
assertRouteUsesFormRequest(string $routeName, string $formRequest)
40+
assertActionUsesMiddleware(string $controller, string $method, string|array $middleware)
4141
```
4242

43-
Verifies that the corresponding action/controller, for a given _route name_ performs the validation using the given form request.
44-
43+
Verifies the _action_ for a given controller uses the given middleware or set of middleware.
4544

4645
```php
47-
assertActionUsesMiddleware(string $controller, string $method, string|array $middleware)
46+
assertRouteUsesFormRequest(string $routeName, string $formRequest)
4847
```
4948

50-
Verifies the _action_ for a given controller uses the given middleware or set of middleware.
51-
49+
Verifies that the corresponding action/controller, for a given _route name_ performs the validation using the given form request.
5250

5351
```php
5452
assertRouteUsesMiddleware(string $routeName, array $middlewares, bool $exact)
@@ -84,8 +82,14 @@ assertViewHasNull($key)
8482

8583
Verifies the view data `$key` has an explicit value of `null`. **Note**: is a `TestResponse` assertion. It must be called on the response of a view.
8684

85+
```php
86+
assertNow(CarbonInterface $datetime, ?CarbonInterface $now = null)
87+
```
88+
89+
Verifies `$datetime` is equal to `$now`, precise to the second. `$now` defaults to `Carbon::now()` which can be faked with the `freezeNow()` [testing helper](freeze-now).
8790

88-
## Matchers
91+
92+
### Matchers
8993
```php
9094
LaravelMatchers::isModel(Model $model = null)
9195
```
@@ -104,16 +108,20 @@ LaravelMatchers::isEloquentCollection(Collection $collection = null)
104108
Matches an argument _equals_ `$collection`. When called without `$collection`, will match any argument of type `\Illuminate\Database\Eloquent\Collection`.
105109

106110

107-
## Creation Methods
108-
This package also provides methods for quickly creating common objects used within Laravel application to use when testing.
109-
110-
111+
### Helpers
111112
```php
112113
createFormRequest(string $class, array $data = [])
113114
```
114115

115116
Creates an instance of the given [Form Request](https://laravel.com/docs/7.x/validation#form-request-validation) class with the given request data.
116117

118+
```php
119+
freezeNow(bool $subseconds = false)
120+
```
121+
122+
Similar to Laravel's `freezeTime()` helper, but defaults with second precision and returns the frozen time. You may pass `true` to freeze with sub-second precision.
123+
124+
117125
## Support Policy
118126
Starting with version 2, this package will only support the latest stable version of Laravel (currently Laravel 8). If you need to support older versions of Laravel, you may use version 1 or upgrade your application ([try using Shift](https://laravelshift.com)).
119127

src/Traits/AdditionalAssertions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function assertNow(CarbonInterface $datetime, ?CarbonInterface $now = nul
119119
{
120120
$now ??= Carbon::now();
121121

122-
PHPUnitAssert::assertTrue($datetime->equalTo($now), 'Failed asserting the date time ['.$datetime->toDateTimeString().'] is equal to now ['.$now->toDateTimeString().']');
122+
PHPUnitAssert::assertTrue($datetime->equalTo($now), 'Failed asserting the date time ['.$datetime->toDateTimeString('microsecond').'] is equal to now ['.$now->toDateTimeString('microsecond').']');
123123
}
124124

125125
public function assertRouteUsesFormRequest(string $routeName, string $formRequest): void
@@ -201,11 +201,11 @@ public function createFormRequest(string $form_request, array $data = [])
201201
return $form_request::createFromBase(SymfonyRequest::create('', 'POST', $data));
202202
}
203203

204-
public function freezeNow($milliseconds = false): CarbonImmutable
204+
public function freezeNow($subseconds = false): CarbonImmutable
205205
{
206206
$now = Carbon::now();
207207

208-
if (! $milliseconds) {
208+
if (! $subseconds) {
209209
$now = $now->startOfSecond();
210210
}
211211

0 commit comments

Comments
 (0)