Skip to content

Commit e8eb901

Browse files
authored
Merge pull request #9 from peter279k/assertion_enhancement
Using the assertSame to make assert equals strict
2 parents bd6c9f9 + e7e4b16 commit e8eb901

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

tests/CommandTest.php

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,44 @@ public function getNewCommand(): Command
1919
public function testBuildMinimal(): void
2020
{
2121
$command = new Command();
22-
$this->assertEquals('curl', $command->build());
22+
$this->assertSame('curl', $command->build());
2323
}
2424

2525
public function testBuildWithUrl(): void
2626
{
2727
$command = new Command();
2828
$command->setUrl('http://example.com/test');
29-
$this->assertEquals('curl http://example.com/test', $command->build());
29+
$this->assertSame('curl http://example.com/test', $command->build());
3030
}
3131

3232
public function testBuildWithOption(): void
3333
{
3434
$command = new Command();
3535
$command->addOption('-v');
36-
$this->assertEquals('curl -v', $command->build());
36+
$this->assertSame('curl -v', $command->build());
3737
}
3838

3939
public function testBuildWithOptions(): void
4040
{
4141
$command = new Command();
4242
$command->addOption('-v');
4343
$command->addOption('-L');
44-
$this->assertEquals('curl -v -L', $command->build());
44+
$this->assertSame('curl -v -L', $command->build());
4545
}
4646

4747
public function testBuildWithUrlAndOption(): void
4848
{
4949
$command = $this->getNewCommand();
5050
$command->addOption('-v');
51-
$this->assertEquals('curl -v http://example.com', $command->build());
51+
$this->assertSame('curl -v http://example.com', $command->build());
5252
}
5353

5454
public function testBuildWithUrlAndOptions(): void
5555
{
5656
$command = $this->getNewCommand();
5757
$command->addOption('-v');
5858
$command->addOption('-L');
59-
$this->assertEquals('curl -v -L http://example.com', $command->build());
59+
$this->assertSame('curl -v -L http://example.com', $command->build());
6060

6161

6262
}
@@ -66,26 +66,26 @@ public function testBuildSetOptions(): void
6666
$command = $this->getNewCommand();
6767

6868
$command->setOptions([]);
69-
$this->assertEquals('curl http://example.com', $command->build());
69+
$this->assertSame('curl http://example.com', $command->build());
7070

7171
$command->setOptions(['-L' => [null], '-v' => [null]]);
72-
$this->assertEquals('curl -L -v http://example.com', $command->build());
72+
$this->assertSame('curl -L -v http://example.com', $command->build());
7373

7474
$command->setOptions(['-L' => null, '-v' => null]);
75-
$this->assertEquals('curl -L -v http://example.com', $command->build());
75+
$this->assertSame('curl -L -v http://example.com', $command->build());
7676

7777
$command->setOptions(['-d' => 'test1', '-H' => 'test2']);
78-
$this->assertEquals("curl -d 'test1' -H 'test2' http://example.com", $command->build());
78+
$this->assertSame("curl -d 'test1' -H 'test2' http://example.com", $command->build());
7979

8080
$command->setOptions(['-H' => ['test1', 'test2']]);
81-
$this->assertEquals("curl -H 'test1' -H 'test2' http://example.com", $command->build());
81+
$this->assertSame("curl -H 'test1' -H 'test2' http://example.com", $command->build());
8282

8383
$command->setOptions(['-L', '-v']);
84-
$this->assertEquals('curl -L -v http://example.com', $command->build());
84+
$this->assertSame('curl -L -v http://example.com', $command->build());
8585

8686
// mixed format
8787
$command->setOptions(['-L', '-v' => null, '--insecure' => [null], '-d' => 'test1', '-H' => ['test2']]);
88-
$this->assertEquals("curl -L -v --insecure -d 'test1' -H 'test2' http://example.com", $command->build());
88+
$this->assertSame("curl -L -v --insecure -d 'test1' -H 'test2' http://example.com", $command->build());
8989
}
9090

9191
public function testBuildDuplicatedOptions(): void
@@ -94,7 +94,7 @@ public function testBuildDuplicatedOptions(): void
9494
$command->addOption('-v');
9595
$command->addOption('-L');
9696
$command->addOption('-L');
97-
$this->assertEquals('curl -v -L -L http://example.com', $command->build());
97+
$this->assertSame('curl -v -L -L http://example.com', $command->build());
9898
}
9999

100100
public function testBuildSetTemplate(): void
@@ -103,40 +103,40 @@ public function testBuildSetTemplate(): void
103103
$command->setTemplate(Command::TEMPLATE_COMMAND_NAME . Command::TEMPLATE_URL . Command::TEMPLATE_OPTIONS);
104104
$command->addOption('-v');
105105
$command->addOption('-L');
106-
$this->assertEquals('curl http://example.com -v -L', $command->build());
106+
$this->assertSame('curl http://example.com -v -L', $command->build());
107107

108108
$command->setTemplate(Command::TEMPLATE_COMMAND_NAME . Command::TEMPLATE_URL);
109-
$this->assertEquals('curl http://example.com', $command->build());
109+
$this->assertSame('curl http://example.com', $command->build());
110110

111111
$command->setTemplate('');
112-
$this->assertEquals('', $command->build());
112+
$this->assertSame('', $command->build());
113113
}
114114

115115
public function testBuildWithLongOptions(): void
116116
{
117117
$command = $this->getNewCommand();
118118
$command->addOption('--verbose');
119-
$this->assertEquals('curl --verbose http://example.com', $command->build());
119+
$this->assertSame('curl --verbose http://example.com', $command->build());
120120

121121
$command->addOption('--location');
122-
$this->assertEquals('curl --verbose --location http://example.com', $command->build());
122+
$this->assertSame('curl --verbose --location http://example.com', $command->build());
123123
}
124124

125125
public function testBuildWithArgumentsToOptions(): void
126126
{
127127
$command = $this->getNewCommand();
128128
$command->addOption('-d', 'arbitrary');
129-
$this->assertEquals("curl -d 'arbitrary' http://example.com", $command->build());
129+
$this->assertSame("curl -d 'arbitrary' http://example.com", $command->build());
130130

131131
// data from file
132132
$command = $this->getNewCommand();
133133
$command->addOption('-d', '@json.txt');
134-
$this->assertEquals("curl -d '@json.txt' http://example.com", $command->build());
134+
$this->assertSame("curl -d '@json.txt' http://example.com", $command->build());
135135

136136
// argument with spaces
137137
$command = $this->getNewCommand();
138138
$command->addOption('-d', 'I am your father');
139-
$this->assertEquals("curl -d 'I am your father' http://example.com", $command->build());
139+
$this->assertSame("curl -d 'I am your father' http://example.com", $command->build());
140140
}
141141

142142
public function testBuildSetQuoteCharacter(): void
@@ -145,16 +145,16 @@ public function testBuildSetQuoteCharacter(): void
145145
$command->addOption('-d', 'arbitrary');
146146

147147
// default is singe
148-
$this->assertEquals("curl -d 'arbitrary' http://example.com", $command->build());
148+
$this->assertSame("curl -d 'arbitrary' http://example.com", $command->build());
149149

150150
$command->setQuoteCharacter(Command::QUOTE_DOUBLE);
151-
$this->assertEquals('curl -d "arbitrary" http://example.com', $command->build());
151+
$this->assertSame('curl -d "arbitrary" http://example.com', $command->build());
152152

153153
$command->setQuoteCharacter(Command::QUOTE_SINGLE);
154-
$this->assertEquals("curl -d 'arbitrary' http://example.com", $command->build());
154+
$this->assertSame("curl -d 'arbitrary' http://example.com", $command->build());
155155

156156
$command->setQuoteCharacter(Command::QUOTE_NONE);
157-
$this->assertEquals('curl -d arbitrary http://example.com', $command->build());
157+
$this->assertSame('curl -d arbitrary http://example.com', $command->build());
158158
}
159159

160160
public function testBuildEscapeArguments(): void
@@ -168,7 +168,7 @@ public function testBuildEscapeArguments(): void
168168
$command = $this->getNewCommand();
169169
$command->setQuoteCharacter(Command::QUOTE_SINGLE);
170170
$command->addOption('-d', $argument);
171-
$this->assertEquals($expected, $command->build());
171+
$this->assertSame($expected, $command->build());
172172

173173
$argument = <<<ARG
174174
x=test"2
@@ -179,7 +179,7 @@ public function testBuildEscapeArguments(): void
179179
$command = $this->getNewCommand();
180180
$command->setQuoteCharacter(Command::QUOTE_SINGLE);
181181
$command->addOption('-d', $argument);
182-
$this->assertEquals($expected, $command->build());
182+
$this->assertSame($expected, $command->build());
183183

184184
$argument = <<<ARG
185185
x=test'1"2
@@ -190,7 +190,7 @@ public function testBuildEscapeArguments(): void
190190
$command = $this->getNewCommand();
191191
$command->setQuoteCharacter(Command::QUOTE_SINGLE);
192192
$command->addOption('-d', $argument);
193-
$this->assertEquals($expected, $command->build());
193+
$this->assertSame($expected, $command->build());
194194

195195
$argument = <<<ARG
196196
x=test'1
@@ -201,7 +201,7 @@ public function testBuildEscapeArguments(): void
201201
$command = $this->getNewCommand();
202202
$command->setQuoteCharacter(Command::QUOTE_DOUBLE);
203203
$command->addOption('-d', $argument);
204-
$this->assertEquals($expected, $command->build());
204+
$this->assertSame($expected, $command->build());
205205

206206
$argument = <<<ARG
207207
x=test"2
@@ -212,7 +212,7 @@ public function testBuildEscapeArguments(): void
212212
$command = $this->getNewCommand();
213213
$command->setQuoteCharacter(Command::QUOTE_DOUBLE);
214214
$command->addOption('-d', $argument);
215-
$this->assertEquals($expected, $command->build());
215+
$this->assertSame($expected, $command->build());
216216

217217
$argument = <<<ARG
218218
x=test'1"2
@@ -223,15 +223,15 @@ public function testBuildEscapeArguments(): void
223223
$command = $this->getNewCommand();
224224
$command->setQuoteCharacter(Command::QUOTE_DOUBLE);
225225
$command->addOption('-d', $argument);
226-
$this->assertEquals($expected, $command->build());
226+
$this->assertSame($expected, $command->build());
227227
}
228228

229229
public function testBuildMultipleOptions(): void
230230
{
231231
$command = $this->getNewCommand();
232232
$command->addOption('-H', 'Connection: keep-alive');
233233
$command->addOption('-H', 'Cache-Control: max-age=0');
234-
$this->assertEquals("curl -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' http://example.com", $command->build());
234+
$this->assertSame("curl -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' http://example.com", $command->build());
235235
}
236236

237237
public function testBuildAddOptions(): void
@@ -242,15 +242,15 @@ public function testBuildAddOptions(): void
242242
'-L',
243243
'-d' => 'test'
244244
]);
245-
$this->assertEquals("curl -v -L -d 'test' http://example.com", $command->build());
245+
$this->assertSame("curl -v -L -d 'test' http://example.com", $command->build());
246246
}
247247

248248
public function testBuildPsrHttpRequest(): void
249249
{
250250
$request = new Request('GET', 'http://example.com');
251251
$command = new Command();
252252
$command->setRequest($request);
253-
$this->assertEquals('curl http://example.com', $command->build());
253+
$this->assertSame('curl http://example.com', $command->build());
254254

255255
$request = new Request('POST', 'http://example.com', [
256256
'Connection' => ['keep-alive'],
@@ -262,13 +262,13 @@ public function testBuildPsrHttpRequest(): void
262262

263263
$command = new Command();
264264
$command->setRequest($request);
265-
$this->assertEquals("curl -H 'Connection: keep-alive' -H 'Accept: text/html, application/xhtml+xml' -d 'data' http://example.com", $command->build());
265+
$this->assertSame("curl -H 'Connection: keep-alive' -H 'Accept: text/html, application/xhtml+xml' -d 'data' http://example.com", $command->build());
266266

267267
$command = new Command();
268268
$command->setRequest($request, false);
269-
$this->assertEquals('curl', $command->build());
269+
$this->assertSame('curl', $command->build());
270270
$command->parseRequest();
271-
$this->assertEquals("curl -H 'Connection: keep-alive' -H 'Accept: text/html, application/xhtml+xml' -d 'data' http://example.com", $command->build());
271+
$this->assertSame("curl -H 'Connection: keep-alive' -H 'Accept: text/html, application/xhtml+xml' -d 'data' http://example.com", $command->build());
272272
}
273273

274274
public function testBuildPsrHttpRequestHeaderExceptions(): void
@@ -282,7 +282,7 @@ public function testBuildPsrHttpRequestHeaderExceptions(): void
282282

283283
$command = new Command();
284284
$command->setRequest($request);
285-
$this->assertEquals("curl -H 'Set-Cookie: test1=1; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure; HttpOnly' -H 'Set-Cookie: test2=2; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure; HttpOnly' http://example.com", $command->build());
285+
$this->assertSame("curl -H 'Set-Cookie: test1=1; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure; HttpOnly' -H 'Set-Cookie: test2=2; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure; HttpOnly' http://example.com", $command->build());
286286
}
287287

288288
public function testBuildParseRequest(): void

0 commit comments

Comments
 (0)