Skip to content

Commit 4583b0e

Browse files
authored
Merge pull request #22 from lucatume/v04-space-to-underscore-in-dataset-name
Space to _ in data set name
2 parents cf9a994 + c00f0a4 commit 4583b0e

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.5.0] - 2025-07-01
11+
12+
### Changed
13+
14+
- White spaces in names of datasets will be converted to underscores to improve the snapshot copy-and-paste-ability.
15+
1016
## [0.4.1] - 2025-06-27
1117

1218
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class WidgetTest extends Codeception\TestCase\Test
2525

2626
## Requirements
2727

28-
The package is based on the snapshot support added in Codeception since version `2.5.0`, as such the library requirments are:
28+
The package is based on the snapshot support added in Codeception since version `2.5.0`, as such the library requirements are:
2929
* PHP 5.6+
3030
* Codeception 2.5+
3131

src/AbstractSnapshot.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ protected function getFileName()
155155
$testCase = $match['object'];
156156
$dataName = $this->getDataName($testCase);
157157
if ($dataName !== '') {
158+
$dataName = preg_replace('/\\s+/', '_', $dataName);
158159
$dataSetFrag = '__' . $dataName;
159160
}
160161
}
@@ -196,7 +197,7 @@ protected static function getTraitMethods()
196197
}
197198

198199
/**
199-
* Returns the counter, an integer, for a class, methdo and data-set combination.
200+
* Returns the counter, an integer, for a class, method and data-set combination.
200201
*
201202
* @param string $class The class to return the counter for.
202203
* @param string $function The function/method to return the counter for.
@@ -340,7 +341,7 @@ protected function fetchData()
340341
/**
341342
* Whether the data is empty or not.
342343
*
343-
* Extending classes can override this method to implement more sofisticated checks.
344+
* Extending classes can override this method to implement more sophisticated checks.
344345
*
345346
* @param mixed $data The data to check.
346347
*

src/StringSnapshot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function stringify($value)
6868
/**
6969
*
7070
*
71-
* @param mixed $data The data to check for emptyness.
71+
* @param mixed $data The data to check for emptiness.
7272
*
7373
* @return bool
7474
* @since TBD
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace tad\Codeception\SnapshotAssertions;
4+
5+
class DataSetNamingTest extends BaseTestCase
6+
{
7+
use SnapshotAssertions;
8+
9+
/**
10+
* @before
11+
*/
12+
public function cleanUp()
13+
{
14+
$this->_after();
15+
}
16+
17+
public static function stringSnapshotDataProvider()
18+
{
19+
return [
20+
'snake_case_dataset' => ['snake_case', 'snake_case_dataset'],
21+
'camelCaseDataset' => ['camelCase', 'camelCaseDataset'],
22+
'PascalCaseDataset' => ['PascalCase', 'PascalCaseDataset'],
23+
'kebab-case-dataset' => ['kebab-case', 'kebab-case-dataset'],
24+
'spaces between words dataset' => ['spaces_between_words', 'spaces_between_words_dataset'],
25+
'double spaces between words dataset' => ['double_spaces_between_words_dataset', 'double_spaces_between_words_dataset'],
26+
];
27+
}
28+
29+
/**
30+
* Should name snapshot files with slugs
31+
*
32+
* @test
33+
* @dataProvider stringSnapshotDataProvider
34+
*/
35+
public function should_name_snapshot_files_with_slugs($testString, $expected)
36+
{
37+
$expectedSnapshotFileName = __DIR__ . '/__snapshots__/DataSetNamingTest__should_name_snapshot_files_with_slugs__' . $expected . '__0.snapshot.txt';
38+
$this->unlinkAfter[]= $expectedSnapshotFileName;
39+
40+
$this->assertMatchesStringSnapshot($testString);
41+
42+
$this->assertFileExists($expectedSnapshotFileName);
43+
}
44+
}

0 commit comments

Comments
 (0)