Skip to content

Commit b700bd5

Browse files
committed
[TASK] add unit test for validity of filename
1 parent 2964ff5 commit b700bd5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Snapshot.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public function filename(): string
4343
$file = $this->id.'.'.$this->driver->extension();
4444
// Remove anything which isn't a word, whitespace, number
4545
// or any of the following caracters -_~,;[]().
46-
$file = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $file);
46+
$file = preg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $file);
4747
// Remove any runs of periods
48-
$file = mb_ereg_replace("([\.]{2,})", '', $file);
48+
$file = preg_replace("([\.]{2,})", '', $file);
4949
return $file;
5050
}
5151

tests/Unit/SnapshotTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,17 @@ public function it_has_a_filename_based_on_its_id_and_its_drivers_extension()
4343

4444
$this->assertEquals('abc.php', $snapshot->filename());
4545
}
46+
47+
/** @test */
48+
public function it_has_a_filename_which_is_valid_on_all_systems()
49+
{
50+
$this->driver
51+
->expects($this->once())
52+
->method('extension')
53+
->willReturn('php');
54+
55+
$snapshot = new Snapshot('ClassTest__testOne with data set "Empty"', $this->filesystem, $this->driver);
56+
57+
$this->assertEquals('ClassTest__testOne with data set Empty.php', $snapshot->filename());
58+
}
4659
}

0 commit comments

Comments
 (0)