File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ public function __toString(): string
2222
2323 public function __toPHP (): string
2424 {
25- return sprintf ('new %s("%s" ) ' , self ::class, $ this ->pattern );
25+ return sprintf ('new %s( \' %s \' ) ' , self ::class, addslashes ( $ this ->pattern ) );
2626 }
2727
2828 public function validate (mixed $ value ): Result
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ public function toStringTest(): void
3232 }
3333
3434 #[Test]
35- public function toPHPTest (): void
35+ #[DataProvider('provideRegularExpresions ' )]
36+ public function toPHPTest (string $ regex ): void
3637 {
3738 $ sut = new Regex ('/[abc]/i ' );
3839
@@ -41,6 +42,14 @@ public function toPHPTest(): void
4142 self ::assertEquals ($ sut , eval ('return ' . $ actual . '; ' ));
4243 }
4344
45+ public static function provideRegularExpresions (): array
46+ {
47+ return [
48+ 'simple regex ' => ['/[abc]/i ' ],
49+ 'regex with special chars ' => ['#^[^$ \'"]$# ' ]
50+ ];
51+ }
52+
4453 public static function dataSetsWithIncorrectTypes (): array
4554 {
4655 return [
You can’t perform that action at this time.
0 commit comments