Skip to content

Commit b974043

Browse files
committed
wip (skip tests in lower versions)
1 parent 3304231 commit b974043

File tree

1 file changed

+52
-41
lines changed

1 file changed

+52
-41
lines changed

tests/ComponentTest.php

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Illuminate\Support\Traits\Macroable;
4+
use Illuminate\Testing\TestComponent;
35
use PHPUnit\Framework\AssertionFailedError;
46
use Sinnbeck\DomAssertions\Asserts\AssertElement;
57
use Tests\Views\Components\BrokenComponent;
@@ -9,51 +11,54 @@
911
use Tests\Views\Components\LivewireComponent;
1012
use Tests\Views\Components\NestedComponent;
1113

14+
$testComponentMacroable = in_array(Macroable::class, class_uses(TestComponent::class) ?? []);
15+
$testComponentMacroableMsg = 'Testing Blade components is unavailable in this version of Laravel';
16+
1217
it('can handle an empty component', function () {
1318
$this->component(EmptyComponent::class)
1419
->assertElementExists();
1520
})->throws(
1621
AssertionFailedError::class,
1722
'The component is empty!'
18-
);
23+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
1924

2025
it('can handle an empty body', function () {
2126
$this->component(EmptyBodyComponent::class)
2227
->assertElementExists();
2328
})->throws(
2429
AssertionFailedError::class,
2530
'No element found with selector: body'
26-
);
31+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
2732

2833
it('can parse broken html', function () {
2934
$this->component(BrokenComponent::class)
3035
->assertElementExists();
31-
});
36+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
3237

3338
it('can find the element', function () {
3439
$this->component(NestedComponent::class)
3540
->assertElementExists();
36-
});
41+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
3742

3843
it('can find the body', function () {
3944
$this->component(NestedComponent::class)
4045
->assertElementExists('body', function (AssertElement $assert) {
4146
$assert->is('body');
4247
});
43-
});
48+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
4449

4550
it('can check for html5', function () {
4651
$this->component(Html5Component::class)
4752
->assertHtml5();
48-
});
53+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
4954

5055
it('can fail checking for html5', function () {
5156
$this->component(NestedComponent::class)
5257
->assertHtml5();
5358
})->throws(
5459
AssertionFailedError::class,
5560
'Not a html5 doctype!'
56-
);
61+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
5762

5863
it('can fail finding a class', function () {
5964
$this->component(Html5Component::class)
@@ -62,7 +67,7 @@
6267
$element->doesntHave('class');
6368
});
6469
});
65-
});
70+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
6671

6772
it('can fail finding a href with exact match', function () {
6873
$this->component(Html5Component::class)
@@ -72,7 +77,7 @@
7277
->doesntHave('href', '/bar');
7378
});
7479
});
75-
});
80+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
7681

7782
it('can fail when finding a id that isnt expected', function () {
7883
$this->component(Html5Component::class)
@@ -84,7 +89,7 @@
8489
})->throws(
8590
AssertionFailedError::class,
8691
'Found an attribute "id"'
87-
);
92+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
8893

8994
it('can fail when finding a href with matching value that isnt expected', function () {
9095
$this->component(Html5Component::class)
@@ -96,27 +101,27 @@
96101
})->throws(
97102
AssertionFailedError::class,
98103
'Found an attribute "href" with value "/foo"'
99-
);
104+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
100105

101106
it('can find an element by selector', function () {
102107
$this->component(Html5Component::class)
103108
->assertElementExists('#nav');
104-
});
109+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
105110

106111
it('can fail finding anything', function () {
107112
$this->component(Html5Component::class)
108113
->assertElementExists('div > nav');
109114
})->throws(
110115
AssertionFailedError::class,
111116
'No element found with selector: div > nav'
112-
);
117+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
113118

114119
it('can check the element has the correct type', function () {
115120
$this->component(Html5Component::class)
116121
->assertElementExists('#nav', function (AssertElement $element) {
117122
$element->is('nav');
118123
});
119-
});
124+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
120125

121126
it('can fail matching element type', function () {
122127
$this->component(Html5Component::class)
@@ -126,19 +131,22 @@
126131
})->throws(
127132
AssertionFailedError::class,
128133
'Element is not of type "div"'
129-
);
134+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
130135

131136
it('can fail with wrong type of selector', function () {
132137
$this->view('form')
133138
->assertElementExists(['div']);
134-
})->throws(AssertionFailedError::class, 'Invalid selector!');
139+
})->throws(
140+
AssertionFailedError::class,
141+
'Invalid selector!'
142+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
135143

136144
it('can find a nested element', function () {
137145
$this->component(Html5Component::class)
138146
->assertElementExists(function (AssertElement $element) {
139147
$element->containsDiv();
140148
});
141-
});
149+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
142150

143151
it('can find a nested element with content', function () {
144152
$this->component(Html5Component::class)
@@ -147,42 +155,42 @@
147155
'class' => 'foobar',
148156
]);
149157
});
150-
});
158+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
151159

152160
it('can match text content', function () {
153161
$this->component(Html5Component::class)
154162
->assertElementExists('span.bar', function (AssertElement $element) {
155163
$element->has('text', 'Foo');
156164
});
157-
});
165+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
158166

159167
it('can match text content with duplicate spaces and vertical whitespace', function () {
160168
$this->component(Html5Component::class)
161169
->assertElementExists('p.foo.bar', function (AssertElement $element) {
162170
$element->has('text', 'Foo Bar');
163171
});
164-
});
172+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
165173

166174
it('can match text content containing a string', function () {
167175
$this->component(Html5Component::class)
168176
->assertElementExists('p.foo.bar', function (AssertElement $element) {
169177
$element->containsText('Bar');
170178
});
171-
});
179+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
172180

173181
it('can match text content containing a string ignoring case', function () {
174182
$this->component(Html5Component::class)
175183
->assertElementExists('p.foo.bar', function (AssertElement $element) {
176184
$element->containsText('bar', true);
177185
});
178-
});
186+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
179187

180188
it('can match text content not containing a string', function () {
181189
$this->component(Html5Component::class)
182190
->assertElementExists('p.foo.bar', function (AssertElement $element) {
183191
$element->doesntContainText('bar');
184192
});
185-
});
193+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
186194

187195
it('can match a class no matter the order', function () {
188196
$this->component(Html5Component::class)
@@ -194,7 +202,7 @@
194202
$span->has('class', 'foo bar');
195203
});
196204
});
197-
});
205+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
198206

199207
it('can match a partial class', function () {
200208
$this->component(Html5Component::class)
@@ -206,21 +214,21 @@
206214
$span->has('class', 'bar');
207215
});
208216
});
209-
});
217+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
210218

211219
it('can find multiple identical items', function () {
212220
$this->component(Html5Component::class)
213221
->assertElementExists(function (AssertElement $element) {
214222
$element->contains('div', [], 4);
215223
});
216-
});
224+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
217225

218226
it('can find multiple identical items simplified', function () {
219227
$this->component(Html5Component::class)
220228
->assertElementExists(function (AssertElement $element) {
221229
$element->contains('div', 4);
222230
});
223-
});
231+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
224232

225233
it('can find multiple identical items with content', function () {
226234
$this->component(Html5Component::class)
@@ -229,7 +237,7 @@
229237
'x-data' => 'foobar',
230238
], 2);
231239
});
232-
});
240+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
233241

234242
it('can find multiple identical items with content ensuring no wrong matches', function () {
235243
$this->component(Html5Component::class)
@@ -238,7 +246,7 @@
238246
'x-data' => 'foobar',
239247
], 1);
240248
});
241-
});
249+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
242250

243251
it('can fail finding a nested element with content', function () {
244252
$this->component(Html5Component::class)
@@ -247,7 +255,10 @@
247255
'class' => 'foo',
248256
]);
249257
});
250-
})->throws(AssertionFailedError::class, 'Could not find a matching "div" with data:');
258+
})->throws(
259+
AssertionFailedError::class,
260+
'Could not find a matching "div" with data:'
261+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
251262

252263
it('can find a nested element with content functional', function () {
253264
$this->component(Html5Component::class)
@@ -256,7 +267,7 @@
256267
$element->is('div');
257268
});
258269
});
259-
});
270+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
260271

261272
it('can find a nested element multiple levels', function () {
262273
$this->component(Html5Component::class)
@@ -271,7 +282,7 @@
271282
});
272283
});
273284
});
274-
});
285+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
275286

276287
it('can find a nested element multiple levels by query', function () {
277288
$this->component(Html5Component::class)
@@ -286,7 +297,7 @@
286297
});
287298
});
288299
});
289-
});
300+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
290301

291302
it('can find a nested element multiple levels by query and attributes', function () {
292303
$this->component(Html5Component::class)
@@ -298,7 +309,7 @@
298309
]);
299310
});
300311
});
301-
});
312+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
302313

303314
it('can find a nested element and ensure doesnt contain', function () {
304315
$this->component(Html5Component::class)
@@ -308,7 +319,7 @@
308319
$element->doesntContain('nav');
309320
});
310321
});
311-
});
322+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
312323

313324
it('can fail finding an contained element', function () {
314325
$this->component(Html5Component::class)
@@ -320,7 +331,7 @@
320331
})->throws(
321332
AssertionFailedError::class,
322333
'Found a matching element of type "div'
323-
);
334+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
324335

325336
it('can fail finding an contained element with query', function () {
326337
$this->component(Html5Component::class)
@@ -332,28 +343,28 @@
332343
})->throws(
333344
AssertionFailedError::class,
334345
'Found a matching element of type "div'
335-
);
346+
)->skip(! $testComponentMacroable, $testComponentMacroableMsg);
336347

337348
it('can match on livewire attributes', function () {
338349
$this->component(LivewireComponent::class)
339350
->assertElementExists('[wire\:model="foo"]', function (AssertElement $element) {
340351
$element->is('input');
341352
});
342-
});
353+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
343354

344355
it('can match has on livewire attributes', function () {
345356
$this->component(LivewireComponent::class)
346357
->assertElementExists('input', function (AssertElement $element) {
347358
$element->has('wire:model', 'foo');
348359
});
349-
});
360+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
350361

351362
it('can match on livewire with contains', function () {
352363
$this->component(LivewireComponent::class)
353364
->assertElementExists(function (AssertElement $element) {
354365
$element->contains('input[wire\:model="foo"]');
355366
});
356-
});
367+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);
357368

358369
it('can match on livewire contains as attribute', function () {
359370
$this->component(LivewireComponent::class)
@@ -362,4 +373,4 @@
362373
'wire:model' => 'foo',
363374
]);
364375
});
365-
});
376+
})->skip(! $testComponentMacroable, $testComponentMacroableMsg);

0 commit comments

Comments
 (0)