Skip to content

Commit f6d718d

Browse files
authored
Add PHPUnit data provider set name to output filenames (#1084)
* include data set in filenames * fix phpunit 9 * snake data and truncate from left * missing ns * use str_replace() * test names unchanged * rename data provider
1 parent bd1b16c commit f6d718d

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/Concerns/ProvidesBrowser.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,13 @@ protected function getCallerName()
232232
? $this->name()
233233
: $this->getName(false); // @phpstan-ignore-line
234234

235-
return str_replace('\\', '_', substr(get_class($this), 0, 70)).'_'.substr($name, 0, 70);
235+
$parts = array_filter([
236+
str_replace('\\', '_', get_class($this)),
237+
$name,
238+
str_replace(['\\', ' '], ['', '_'], $this->dataName()),
239+
], fn ($part) => $part !== '');
240+
241+
return substr(implode('_', $parts), -140);
236242
}
237243

238244
/**

tests/Unit/ProvidesBrowserTest.php

+24-10
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ protected function tearDown(): void
1616
m::close();
1717
}
1818

19-
/**
20-
* @dataProvider testData
21-
*/
2219
public function test_capture_failures_for()
2320
{
2421
$browser = m::mock(stdClass::class);
@@ -31,34 +28,51 @@ public function test_capture_failures_for()
3128
}
3229

3330
/**
34-
* @dataProvider testData
31+
* @dataProvider data
3532
*/
36-
public function test_store_console_logs_for()
33+
public function test_capture_failures_for_data()
34+
{
35+
$browser = m::mock(stdClass::class);
36+
$browser->shouldReceive('screenshot')->with(
37+
'failure-Laravel_Dusk_Tests_Unit_ProvidesBrowserTest_test_capture_failures_for_data_foo-0'
38+
);
39+
$browsers = collect([$browser]);
40+
41+
$this->captureFailuresFor($browsers);
42+
}
43+
44+
/**
45+
* @dataProvider data
46+
*/
47+
public function test_store_console_logs_for_data()
3748
{
3849
$browser = m::mock(stdClass::class);
3950
$browser->shouldReceive('storeConsoleLog')->with(
40-
'Laravel_Dusk_Tests_Unit_ProvidesBrowserTest_test_store_console_logs_for-0'
51+
'Laravel_Dusk_Tests_Unit_ProvidesBrowserTest_test_store_console_logs_for_data_foo-0'
4152
);
4253
$browsers = collect([$browser]);
4354

4455
$this->storeConsoleLogsFor($browsers);
4556
}
4657

47-
public function test_truncate_test_name_where_that_name_is_too_long_and_might_cause_issues()
58+
/**
59+
* @dataProvider data
60+
*/
61+
public function test_truncate_test_name_where_that_name_is_really_really_really_too_long_and_might_cause_issues_data()
4862
{
4963
$browser = m::mock(stdClass::class);
5064
$browser->shouldReceive('storeConsoleLog')->with(
51-
'Laravel_Dusk_Tests_Unit_ProvidesBrowserTest_test_truncate_test_name_where_that_name_is_too_long_and_might_cause_is-0'
65+
'Dusk_Tests_Unit_ProvidesBrowserTest_test_truncate_test_name_where_that_name_is_really_really_really_too_long_and_might_cause_issues_data_foo-0'
5266
);
5367
$browsers = collect([$browser]);
5468

5569
$this->storeConsoleLogsFor($browsers);
5670
}
5771

58-
public static function testData()
72+
public static function data()
5973
{
6074
return [
61-
['foo'],
75+
'foo' => ['foo'],
6276
];
6377
}
6478

0 commit comments

Comments
 (0)