|
5 | 5 | - [Test Environment](#test-environment)
|
6 | 6 | - [Calling Routes From Tests](#calling-routes-from-tests)
|
7 | 7 | - [Mocking Facades](#mocking-facades)
|
| 8 | +- [Framework Assertions](#framework-assertions) |
8 | 9 | - [Helper Methods](#helper-methods)
|
9 | 10 |
|
10 | 11 | <a name="introduction"></a>
|
@@ -105,6 +106,48 @@ We can mock the call to the `Event` class by using the `shouldReceive` method on
|
105 | 106 |
|
106 | 107 | > **Note:** You should not mock the `Request` facade. Instead, pass the input you desire into the `call` method when running your test.
|
107 | 108 |
|
| 109 | +<a name="framework-assertions"></a> |
| 110 | +## Framework Assertions |
| 111 | + |
| 112 | +Laravel ships with several `assert` methods to make testing a little easier: |
| 113 | + |
| 114 | +**Asserting Responses Are OK** |
| 115 | + |
| 116 | + public function testMethod() |
| 117 | + { |
| 118 | + $this->call('GET', '/'); |
| 119 | + |
| 120 | + $this->assertRepsonseIsOk(); |
| 121 | + } |
| 122 | + |
| 123 | +**Asserting Responses Are Redirects** |
| 124 | + |
| 125 | + $this->assertRedirectedTo('foo'); |
| 126 | + |
| 127 | + $this->assertRedirectedToRoute('route.name'); |
| 128 | + |
| 129 | + $this->assertRedirectedToAction('Controller@method'); |
| 130 | + |
| 131 | +**Asserting A View Has Some Data** |
| 132 | + |
| 133 | + public function testMethod() |
| 134 | + { |
| 135 | + $this->call('GET', '/'); |
| 136 | + |
| 137 | + $this->assertViewHas('name'); |
| 138 | + $this->assertViewHas('age', $value); |
| 139 | + } |
| 140 | + |
| 141 | +**Asserting The Session Has Some Data** |
| 142 | + |
| 143 | + public function testMethod() |
| 144 | + { |
| 145 | + $this->call('GET', '/'); |
| 146 | + |
| 147 | + $this->assertSessionHas('name'); |
| 148 | + $this->assertSessionHas('age', $value); |
| 149 | + } |
| 150 | + |
108 | 151 | <a name="helper-methods"></a>
|
109 | 152 | ## Helper Methods
|
110 | 153 |
|
|
0 commit comments