Skip to content

Commit 4255e94

Browse files
mhujersebastianbergmann
authored andcommitted
replace assertEquals() in examples with assertSame()
1 parent 52bb5e2 commit 4255e94

File tree

7 files changed

+56
-55
lines changed

7 files changed

+56
-55
lines changed

src/annotations.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ specify which method(s) a test method wants to test:
264264
*/
265265
public function testBalanceIsInitiallyZero()
266266
{
267-
$this->assertEquals(0, $this->ba->getBalance());
267+
$this->assertSame(0, $this->ba->getBalance());
268268
}
269269
270270
If provided, only the code coverage information for the specified
@@ -728,7 +728,7 @@ annotation in a method's DocBlock to mark it as a test method.
728728
*/
729729
public function initialBalanceShouldBe0()
730730
{
731-
$this->assertEquals(0, $this->ba->getBalance());
731+
$this->assertSame(0, $this->ba->getBalance());
732732
}
733733
734734
.. _appendixes.annotations.testdox:
@@ -752,7 +752,7 @@ The ``@testdox`` annotation can be applied to both test classes and test methods
752752
*/
753753
public function balanceIsInitiallyZero()
754754
{
755-
$this->assertEquals(0, $this->ba->getBalance());
755+
$this->assertSame(0, $this->ba->getBalance());
756756
}
757757
}
758758
@@ -783,7 +783,7 @@ you can define a data set using the ``@testWith`` annotation.
783783
*/
784784
public function testStringLength(string $input, int $expectedLength)
785785
{
786-
$this->assertEquals($expectedLength, strlen($input));
786+
$this->assertSame($expectedLength, strlen($input));
787787
}
788788
789789
.. _appendixes.annotations.ticket:

src/code-coverage-analysis.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ shows an example.
216216
*/
217217
public function testBalanceIsInitiallyZero()
218218
{
219-
$this->assertEquals(0, $this->ba->getBalance());
219+
$this->assertSame(0, $this->ba->getBalance());
220220
}
221221
222222
/**
@@ -229,7 +229,7 @@ shows an example.
229229
}
230230
231231
catch (BankAccountException $e) {
232-
$this->assertEquals(0, $this->ba->getBalance());
232+
$this->assertSame(0, $this->ba->getBalance());
233233
234234
return;
235235
}
@@ -247,7 +247,7 @@ shows an example.
247247
}
248248
249249
catch (BankAccountException $e) {
250-
$this->assertEquals(0, $this->ba->getBalance());
250+
$this->assertSame(0, $this->ba->getBalance());
251251
252252
return;
253253
}
@@ -262,11 +262,11 @@ shows an example.
262262
*/
263263
public function testDepositWithdrawMoney()
264264
{
265-
$this->assertEquals(0, $this->ba->getBalance());
265+
$this->assertSame(0, $this->ba->getBalance());
266266
$this->ba->depositMoney(1);
267-
$this->assertEquals(1, $this->ba->getBalance());
267+
$this->assertSame(1, $this->ba->getBalance());
268268
$this->ba->withdrawMoney(1);
269-
$this->assertEquals(0, $this->ba->getBalance());
269+
$this->assertSame(0, $this->ba->getBalance());
270270
}
271271
}
272272
?>

src/database.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ following way:
206206
{
207207
public function testCalculate()
208208
{
209-
$this->assertEquals(2, 1 + 1);
209+
$this->assertSame(2, 1 + 1);
210210
}
211211
}
212212
?>
@@ -1340,7 +1340,7 @@ which has to be returned from the
13401340
13411341
public function testGetRowCount()
13421342
{
1343-
$this->assertEquals(2, $this->getConnection()->getRowCount('guestbook'));
1343+
$this->assertSame(2, $this->getConnection()->getRowCount('guestbook'));
13441344
}
13451345
}
13461346
?>
@@ -1379,12 +1379,12 @@ examples, but a third one:
13791379
13801380
public function testAddEntry()
13811381
{
1382-
$this->assertEquals(2, $this->getConnection()->getRowCount('guestbook'), "Pre-Condition");
1382+
$this->assertSame(2, $this->getConnection()->getRowCount('guestbook'), "Pre-Condition");
13831383
13841384
$guestbook = new Guestbook();
13851385
$guestbook->addEntry("suzy", "Hello world!");
13861386
1387-
$this->assertEquals(3, $this->getConnection()->getRowCount('guestbook'), "Inserting failed");
1387+
$this->assertSame(3, $this->getConnection()->getRowCount('guestbook'), "Inserting failed");
13881388
}
13891389
}
13901390
?>

src/fixtures.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ creation of the ``array`` fixture into the
4040
``setUp()`` method. Finally, we remove the redundant code
4141
from the test methods and use the newly introduced instance variable,
4242
``$this->stack``, instead of the method-local variable
43-
``$stack`` with the ``assertEquals()``
43+
``$stack`` with the ``assertSame()``
4444
assertion method.
4545

4646
.. code-block:: php
@@ -67,14 +67,14 @@ assertion method.
6767
public function testPush()
6868
{
6969
array_push($this->stack, 'foo');
70-
$this->assertEquals('foo', $this->stack[count($this->stack)-1]);
70+
$this->assertSame('foo', $this->stack[count($this->stack)-1]);
7171
$this->assertFalse(empty($this->stack));
7272
}
7373
7474
public function testPop()
7575
{
7676
array_push($this->stack, 'foo');
77-
$this->assertEquals('foo', array_pop($this->stack));
77+
$this->assertSame('foo', array_pop($this->stack));
7878
$this->assertTrue(empty($this->stack));
7979
}
8080
}

src/test-doubles.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ the example. This leads to more readable and "fluent" code.
113113
114114
// Calling $stub->doSomething() will now return
115115
// 'foo'.
116-
$this->assertEquals('foo', $stub->doSomething());
116+
$this->assertSame('foo', $stub->doSomething());
117117
}
118118
}
119119
?>
@@ -146,7 +146,7 @@ the same best practice defaults used by ``createMock()``.
146146
public function testStub()
147147
{
148148
// Create a stub for the SomeClass class.
149-
$stub = $this->getMockBuilder($originalClassName)
149+
$stub = $this->getMockBuilder(SomeClass::class)
150150
->disableOriginalConstructor()
151151
->disableOriginalClone()
152152
->disableArgumentCloning()
@@ -159,7 +159,7 @@ the same best practice defaults used by ``createMock()``.
159159
160160
// Calling $stub->doSomething() will now return
161161
// 'foo'.
162-
$this->assertEquals('foo', $stub->doSomething());
162+
$this->assertSame('foo', $stub->doSomething());
163163
}
164164
}
165165
?>
@@ -194,10 +194,10 @@ can achieve this using ``returnArgument()`` instead of
194194
->will($this->returnArgument(0));
195195
196196
// $stub->doSomething('foo') returns 'foo'
197-
$this->assertEquals('foo', $stub->doSomething('foo'));
197+
$this->assertSame('foo', $stub->doSomething('foo'));
198198
199199
// $stub->doSomething('bar') returns 'bar'
200-
$this->assertEquals('bar', $stub->doSomething('bar'));
200+
$this->assertSame('bar', $stub->doSomething('bar'));
201201
}
202202
}
203203
?>
@@ -264,8 +264,8 @@ an example.
264264
265265
// $stub->doSomething() returns different values depending on
266266
// the provided arguments.
267-
$this->assertEquals('d', $stub->doSomething('a', 'b', 'c'));
268-
$this->assertEquals('h', $stub->doSomething('e', 'f', 'g'));
267+
$this->assertSame('d', $stub->doSomething('a', 'b', 'c'));
268+
$this->assertSame('h', $stub->doSomething('e', 'f', 'g'));
269269
}
270270
}
271271
?>
@@ -296,7 +296,7 @@ result of a callback function or method. See
296296
->will($this->returnCallback('str_rot13'));
297297
298298
// $stub->doSomething($argument) returns str_rot13($argument)
299-
$this->assertEquals('fbzrguvat', $stub->doSomething('something'));
299+
$this->assertSame('fbzrguvat', $stub->doSomething('something'));
300300
}
301301
}
302302
?>
@@ -326,9 +326,9 @@ an example.
326326
->will($this->onConsecutiveCalls(2, 3, 5, 7));
327327
328328
// $stub->doSomething() returns a different value each time
329-
$this->assertEquals(2, $stub->doSomething());
330-
$this->assertEquals(3, $stub->doSomething());
331-
$this->assertEquals(5, $stub->doSomething());
329+
$this->assertSame(2, $stub->doSomething());
330+
$this->assertSame(3, $stub->doSomething());
331+
$this->assertSame(5, $stub->doSomething());
332332
}
333333
}
334334
?>

src/textui.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ indicate progress:
5858

5959
PHPUnit distinguishes between *failures* and
6060
*errors*. A failure is a violated PHPUnit
61-
assertion such as a failing ``assertEquals()`` call.
61+
assertion such as a failing ``assertSame()`` call.
6262
An error is an unexpected exception or a PHP error. Sometimes
6363
this distinction proves useful since errors tend to be easier to fix
6464
than failures. If you have a big list of problems, it is best to

0 commit comments

Comments
 (0)