Skip to content

Commit 388aeba

Browse files
Merge pull request #34 from stevegrunwell/update/variable-names
Update $output to $markup, improve inline docs
2 parents 127dd9a + 196c6fd commit 388aeba

File tree

3 files changed

+52
-48
lines changed

3 files changed

+52
-48
lines changed

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
This library introduces the `MarkupAssertionsTrait` trait for use in [PHPUnit](https://phpunit.de) tests.
77

8-
These assertions enable you to inspect generated markup without having to muddy tests with [`DOMDocument`](http://php.net/manual/en/class.domdocument.php) or nasty regular expressions. If you're generating markup at all with PHP, the PHPUnit Markup Assertions trait aims to make the output testable.
8+
These assertions enable you to inspect generated markup without having to muddy tests with [`DOMDocument`](http://php.net/manual/en/class.domdocument.php) or nasty regular expressions. If you're generating markup at all with PHP, the PHPUnit Markup Assertions trait aims to make the output testable without making your tests fragile.
99

1010
## Example
1111

@@ -22,10 +22,10 @@ class MyUnitTest extends TestCase
2222
*/
2323
public function testRenderFormContainsInputs()
2424
{
25-
$output = render_form();
25+
$markup = render_form();
2626

27-
$this->assertContainsSelector('#first-name', $output);
28-
$this->assertContainsSelector('#last-name', $output);
27+
$this->assertContainsSelector('#first-name', $markup);
28+
$this->assertContainsSelector('#last-name', $markup);
2929
}
3030
}
3131
```
@@ -104,8 +104,8 @@ Assert that the given string contains an element matching the given selector.
104104
<dl>
105105
<dt>(string) $selector</dt>
106106
<dd>A query selector for the element to find.</dd>
107-
<dt>(string) $output</dt>
108-
<dd>The output that should contain the <code>$selector</code>.</dd>
107+
<dt>(string) $markup</dt>
108+
<dd>The markup that should contain the <code>$selector</code>.</dd>
109109
<dt>(string) $message</dt>
110110
<dd>A message to display if the assertion fails.</dd>
111111
</dl>
@@ -130,8 +130,8 @@ This method is the inverse of [`assertContainsSelector()`](#assertcontainsselect
130130
<dl>
131131
<dt>(string) $selector</dt>
132132
<dd>A query selector for the element to find.</dd>
133-
<dt>(string) $output</dt>
134-
<dd>The output that should not contain the <code>$selector</code>.</dd>
133+
<dt>(string) $markup</dt>
134+
<dd>The markup that should not contain the <code>$selector</code>.</dd>
135135
<dt>(string) $message</dt>
136136
<dd>A message to display if the assertion fails.</dd>
137137
</dl>
@@ -145,7 +145,7 @@ Assert the number of times an element matching the given selector is found.
145145
<dd>The number of matching elements expected.</dd>
146146
<dt>(string) $selector</dt>
147147
<dd>A query selector for the element to find.</dd>
148-
<dt>(string) $output</dt>
148+
<dt>(string) $markup</dt>
149149
<dd>The markup to run the assertion against.</dd>
150150
<dt>(string) $message</dt>
151151
<dd>A message to display if the assertion fails.</dd>
@@ -171,8 +171,8 @@ Assert that an element with the given attributes exists in the given markup.
171171
<dl>
172172
<dt>(array) $attributes</dt>
173173
<dd>An array of HTML attributes that should be found on the element.</dd>
174-
<dt>(string) $output</dt>
175-
<dd>The output that should contain an element with the provided <code>$attributes</code>.</dd>
174+
<dt>(string) $markup</dt>
175+
<dd>The markup that should contain an element with the provided <code>$attributes</code>.</dd>
176176
<dt>(string) $message</dt>
177177
<dd>A message to display if the assertion fails.</dd>
178178
</dl>
@@ -203,8 +203,8 @@ Assert that an element with the given attributes does not exist in the given mar
203203
<dl>
204204
<dt>(array) $attributes</dt>
205205
<dd>An array of HTML attributes that should not be found on the element.</dd>
206-
<dt>(string) $output</dt>
207-
<dd>The output that should not contain an element with the provided <code>$attributes</code>.</dd>
206+
<dt>(string) $markup</dt>
207+
<dd>The markup that should not contain an element with the provided <code>$attributes</code>.</dd>
208208
<dt>(string) $message</dt>
209209
<dd>A message to display if the assertion fails.</dd>
210210
</dl>
@@ -218,8 +218,8 @@ Assert that the element with the given selector contains a string.
218218
<dd>The string to look for within the DOM node's contents.</dd>
219219
<dt>(string) $selector</dt>
220220
<dd>A query selector for the element to find.</dd>
221-
<dt>(string) $output</dt>
222-
<dd>The output that should contain the <code>$selector</code>.</dd>
221+
<dt>(string) $markup</dt>
222+
<dd>The markup that should contain the <code>$selector</code>.</dd>
223223
<dt>(string) $message</dt>
224224
<dd>A message to display if the assertion fails.</dd>
225225
</dl>
@@ -252,8 +252,8 @@ This method is the inverse of [`assertElementContains()`](#assertelementcontains
252252
<dd>The string to look for within the DOM node's contents.</dd>
253253
<dt>(string) $selector</dt>
254254
<dd>A query selector for the element to find.</dd>
255-
<dt>(string) $output</dt>
256-
<dd>The output that should contain the <code>$selector</code>.</dd>
255+
<dt>(string) $markup</dt>
256+
<dd>The markup that should contain the <code>$selector</code>.</dd>
257257
<dt>(string) $message</dt>
258258
<dd>A message to display if the assertion fails.</dd>
259259
</dl>
@@ -269,8 +269,8 @@ This method works just like [`assertElementContains()`](#assertelementcontains),
269269
<dd>The regular expression pattern to look for within the DOM node.</dd>
270270
<dt>(string) $selector</dt>
271271
<dd>A query selector for the element to find.</dd>
272-
<dt>(string) $output</dt>
273-
<dd>The output that should contain the <code>$selector</code>.</dd>
272+
<dt>(string) $markup</dt>
273+
<dd>The markup that should contain the <code>$selector</code>.</dd>
274274
<dt>(string) $message</dt>
275275
<dd>A message to display if the assertion fails.</dd>
276276
</dl>
@@ -286,8 +286,8 @@ This method is the inverse of [`assertElementRegExp()`](#assertelementregexp) an
286286
<dd>The regular expression pattern to look for within the DOM node.</dd>
287287
<dt>(string) $selector</dt>
288288
<dd>A query selector for the element to find.</dd>
289-
<dt>(string) $output</dt>
290-
<dd>The output that should contain the <code>$selector</code>.</dd>
289+
<dt>(string) $markup</dt>
290+
<dd>The markup that should contain the <code>$selector</code>.</dd>
291291
<dt>(string) $message</dt>
292292
<dd>A message to display if the assertion fails.</dd>
293293
</dl>

src/MarkupAssertionsTrait.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ trait MarkupAssertionsTrait
2121
* @since 1.0.0
2222
*
2323
* @param string $selector A query selector for the element to find.
24-
* @param string $output The output that should contain the $selector.
24+
* @param string $markup The output that should contain the $selector.
2525
* @param string $message A message to display if the assertion fails.
2626
*
2727
* @return void
2828
*/
29-
public function assertContainsSelector($selector, $output = '', $message = '')
29+
public function assertContainsSelector($selector, $markup = '', $message = '')
3030
{
31-
$results = $this->executeDomQuery($output, $selector);
31+
$results = $this->executeDomQuery($markup, $selector);
3232

3333
$this->assertGreaterThan(0, count($results), $message);
3434
}
@@ -39,12 +39,12 @@ public function assertContainsSelector($selector, $output = '', $message = '')
3939
* @since 1.0.0
4040
*
4141
* @param string $selector A query selector for the element to find.
42-
* @param string $output The output that should not contain the $selector.
42+
* @param string $markup The output that should not contain the $selector.
4343
* @param string $message A message to display if the assertion fails.
4444
*/
45-
public function assertNotContainsSelector($selector, $output = '', $message = '')
45+
public function assertNotContainsSelector($selector, $markup = '', $message = '')
4646
{
47-
$results = $this->executeDomQuery($output, $selector);
47+
$results = $this->executeDomQuery($markup, $selector);
4848

4949
$this->assertEquals(0, count($results), $message);
5050
}
@@ -56,14 +56,14 @@ public function assertNotContainsSelector($selector, $output = '', $message = ''
5656
*
5757
* @param int $count The number of matching elements expected.
5858
* @param string $selector A query selector for the element to find.
59-
* @param string $output The markup to run the assertion against.
59+
* @param string $markup The markup to run the assertion against.
6060
* @param string $message A message to display if the assertion fails.
6161
*
6262
* @return void
6363
*/
64-
public function assertSelectorCount($count, $selector, $output = '', $message = '')
64+
public function assertSelectorCount($count, $selector, $markup = '', $message = '')
6565
{
66-
$results = $this->executeDomQuery($output, $selector);
66+
$results = $this->executeDomQuery($markup, $selector);
6767

6868
$this->assertCount($count, $results, $message);
6969
}
@@ -74,17 +74,17 @@ public function assertSelectorCount($count, $selector, $output = '', $message =
7474
* @since 1.0.0
7575
*
7676
* @param array $attributes An array of HTML attributes that should be found on the element.
77-
* @param string $output The output that should contain an element with the
77+
* @param string $markup The output that should contain an element with the
7878
* provided $attributes.
7979
* @param string $message A message to display if the assertion fails.
8080
*
8181
* @return void
8282
*/
83-
public function assertHasElementWithAttributes($attributes = [], $output = '', $message = '')
83+
public function assertHasElementWithAttributes($attributes = [], $markup = '', $message = '')
8484
{
8585
$this->assertContainsSelector(
8686
'*' . $this->flattenAttributeArray($attributes),
87-
$output,
87+
$markup,
8888
$message
8989
);
9090
}
@@ -95,17 +95,17 @@ public function assertHasElementWithAttributes($attributes = [], $output = '', $
9595
* @since 1.0.0
9696
*
9797
* @param array $attributes An array of HTML attributes that should be found on the element.
98-
* @param string $output The output that should not contain an element with the
98+
* @param string $markup The output that should not contain an element with the
9999
* provided $attributes.
100100
* @param string $message A message to display if the assertion fails.
101101
*
102102
* @return void
103103
*/
104-
public function assertNotHasElementWithAttributes($attributes = [], $output = '', $message = '')
104+
public function assertNotHasElementWithAttributes($attributes = [], $markup = '', $message = '')
105105
{
106106
$this->assertNotContainsSelector(
107107
'*' . $this->flattenAttributeArray($attributes),
108-
$output,
108+
$markup,
109109
$message
110110
);
111111
}
@@ -117,20 +117,20 @@ public function assertNotHasElementWithAttributes($attributes = [], $output = ''
117117
*
118118
* @param string $contents The string to look for within the DOM node's contents.
119119
* @param string $selector A query selector for the element to find.
120-
* @param string $output The output that should contain the $selector.
120+
* @param string $markup The output that should contain the $selector.
121121
* @param string $message A message to display if the assertion fails.
122122
*
123123
* @return void
124124
*/
125-
public function assertElementContains($contents, $selector = '', $output = '', $message = '')
125+
public function assertElementContains($contents, $selector = '', $markup = '', $message = '')
126126
{
127127
$method = method_exists($this, 'assertStringContainsString')
128128
? 'assertStringContainsString'
129129
: 'assertContains';
130130

131131
$this->$method(
132132
$contents,
133-
$this->getInnerHtmlOfMatchedElements($output, $selector),
133+
$this->getInnerHtmlOfMatchedElements($markup, $selector),
134134
$message
135135
);
136136
}
@@ -142,20 +142,20 @@ public function assertElementContains($contents, $selector = '', $output = '', $
142142
*
143143
* @param string $contents The string to look for within the DOM node's contents.
144144
* @param string $selector A query selector for the element to find.
145-
* @param string $output The output that should not contain the $selector.
145+
* @param string $markup The output that should not contain the $selector.
146146
* @param string $message A message to display if the assertion fails.
147147
*
148148
* @return void
149149
*/
150-
public function assertElementNotContains($contents, $selector = '', $output = '', $message = '')
150+
public function assertElementNotContains($contents, $selector = '', $markup = '', $message = '')
151151
{
152152
$method = method_exists($this, 'assertStringNotContainsString')
153153
? 'assertStringNotContainsString'
154154
: 'assertNotContains';
155155

156156
$this->$method(
157157
$contents,
158-
$this->getInnerHtmlOfMatchedElements($output, $selector),
158+
$this->getInnerHtmlOfMatchedElements($markup, $selector),
159159
$message
160160
);
161161
}
@@ -167,20 +167,20 @@ public function assertElementNotContains($contents, $selector = '', $output = ''
167167
*
168168
* @param string $regexp The regular expression pattern to look for within the DOM node.
169169
* @param string $selector A query selector for the element to find.
170-
* @param string $output The output that should contain the $selector.
170+
* @param string $markup The output that should contain the $selector.
171171
* @param string $message A message to display if the assertion fails.
172172
*
173173
* @return void
174174
*/
175-
public function assertElementRegExp($regexp, $selector = '', $output = '', $message = '')
175+
public function assertElementRegExp($regexp, $selector = '', $markup = '', $message = '')
176176
{
177177
$method = method_exists($this, 'assertMatchesRegularExpression')
178178
? 'assertMatchesRegularExpression'
179179
: 'assertRegExp';
180180

181181
$this->$method(
182182
$regexp,
183-
$this->getInnerHtmlOfMatchedElements($output, $selector),
183+
$this->getInnerHtmlOfMatchedElements($markup, $selector),
184184
$message
185185
);
186186
}
@@ -192,20 +192,20 @@ public function assertElementRegExp($regexp, $selector = '', $output = '', $mess
192192
*
193193
* @param string $regexp The regular expression pattern to look for within the DOM node.
194194
* @param string $selector A query selector for the element to find.
195-
* @param string $output The output that should not contain the $selector.
195+
* @param string $markup The output that should not contain the $selector.
196196
* @param string $message A message to display if the assertion fails.
197197
*
198198
* @return void
199199
*/
200-
public function assertElementNotRegExp($regexp, $selector = '', $output = '', $message = '')
200+
public function assertElementNotRegExp($regexp, $selector = '', $markup = '', $message = '')
201201
{
202202
$method = method_exists($this, 'assertDoesNotMatchRegularExpression')
203203
? 'assertDoesNotMatchRegularExpression'
204204
: 'assertNotRegExp';
205205

206206
$this->$method(
207207
$regexp,
208-
$this->getInnerHtmlOfMatchedElements($output, $selector),
208+
$this->getInnerHtmlOfMatchedElements($markup, $selector),
209209
$message
210210
);
211211
}

tests/MarkupAssertionsTraitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ public function provideAttributes()
287287

288288
/**
289289
* Data provider for testGetInnerHtmlOfMatchedElements().
290+
*
291+
* @return array<string,array<string>>
290292
*/
291293
public function provideInnerHtml()
292294
{
@@ -311,6 +313,8 @@ public function provideInnerHtml()
311313

312314
/**
313315
* Data provider for testAssertContainsSelector().
316+
*
317+
* @return array<string,array<string>>
314318
*/
315319
public function provideSelectorVariants()
316320
{

0 commit comments

Comments
 (0)