@@ -37,4 +37,85 @@ public function testReplacementParamsQuery()
37
37
$ result = $ traced ->getSqlWithParams ();
38
38
$ this ->assertEquals ($ expected , $ result );
39
39
}
40
- }
40
+
41
+ public function testReplacementParamsContainingBackReferenceSyntaxGeneratesCorrectString ()
42
+ {
43
+ $ hashedPassword = '$2y$10$S3Y/kSsx8Z5BPtdd9.k3LOkbQ0egtsUHBT9EGQ.spxsmaEWbrxBW2 ' ;
44
+ $ sql = "UPDATE user SET password = :password " ;
45
+
46
+ $ params = array (
47
+ ':password ' => $ hashedPassword ,
48
+ );
49
+
50
+ $ traced = new TracedStatement ($ sql , $ params );
51
+
52
+ $ result = $ traced ->getSqlWithParams ();
53
+
54
+ $ expected = "UPDATE user SET password = < $ hashedPassword> " ;
55
+
56
+ $ this ->assertEquals ($ expected , $ result );
57
+ }
58
+
59
+ public function testReplacementParamsContainingPotentialAdditionalQuestionMarkPlaceholderGeneratesCorrectString ()
60
+ {
61
+ $ hasQuestionMark = "Asking a question? " ;
62
+ $ string = "Asking for a friend " ;
63
+
64
+ $ sql = "INSERT INTO questions SET question = ?, detail = ? " ;
65
+
66
+ $ params = array ($ hasQuestionMark , $ string );
67
+
68
+ $ traced = new TracedStatement ($ sql , $ params );
69
+
70
+ $ result = $ traced ->getSqlWithParams ();
71
+
72
+ $ expected = "INSERT INTO questions SET question = < $ hasQuestionMark>, detail = < $ string> " ;
73
+
74
+ $ this ->assertEquals ($ expected , $ result );
75
+
76
+ $ result = $ traced ->getSqlWithParams ("' " );
77
+
78
+ $ expected = "INSERT INTO questions SET question = ' $ hasQuestionMark', detail = ' $ string' " ;
79
+
80
+ $ this ->assertEquals ($ expected , $ result );
81
+
82
+ $ result = $ traced ->getSqlWithParams ('" ' );
83
+
84
+ $ expected = "INSERT INTO questions SET question = \"$ hasQuestionMark \", detail = \"$ string \"" ;
85
+
86
+ $ this ->assertEquals ($ expected , $ result );
87
+ }
88
+
89
+ public function testReplacementParamsContainingPotentialAdditionalNamedPlaceholderGeneratesCorrectString ()
90
+ {
91
+ $ hasQuestionMark = "Asking a question with a :string inside " ;
92
+ $ string = "Asking for a friend " ;
93
+
94
+ $ sql = "INSERT INTO questions SET question = :question, detail = :string " ;
95
+
96
+ $ params = array (
97
+ ':question ' => $ hasQuestionMark ,
98
+ ':string ' => $ string ,
99
+ );
100
+
101
+ $ traced = new TracedStatement ($ sql , $ params );
102
+
103
+ $ result = $ traced ->getSqlWithParams ();
104
+
105
+ $ expected = "INSERT INTO questions SET question = < $ hasQuestionMark>, detail = < $ string> " ;
106
+
107
+ $ this ->assertEquals ($ expected , $ result );
108
+
109
+ $ result = $ traced ->getSqlWithParams ("' " );
110
+
111
+ $ expected = "INSERT INTO questions SET question = ' $ hasQuestionMark', detail = ' $ string' " ;
112
+
113
+ $ this ->assertEquals ($ expected , $ result );
114
+
115
+ $ result = $ traced ->getSqlWithParams ('" ' );
116
+
117
+ $ expected = "INSERT INTO questions SET question = \"$ hasQuestionMark \", detail = \"$ string \"" ;
118
+
119
+ $ this ->assertEquals ($ expected , $ result );
120
+ }
121
+ }
0 commit comments