Skip to content

Replace assertEquals() with assertSame() #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ specify which method(s) a test method wants to test:
*/
public function testBalanceIsInitiallyZero()
{
$this->assertEquals(0, $this->ba->getBalance());
$this->assertSame(0, $this->ba->getBalance());
}

If provided, only the code coverage information for the specified
Expand Down Expand Up @@ -728,7 +728,7 @@ annotation in a method's DocBlock to mark it as a test method.
*/
public function initialBalanceShouldBe0()
{
$this->assertEquals(0, $this->ba->getBalance());
$this->assertSame(0, $this->ba->getBalance());
}

.. _appendixes.annotations.testdox:
Expand All @@ -752,7 +752,7 @@ The ``@testdox`` annotation can be applied to both test classes and test methods
*/
public function balanceIsInitiallyZero()
{
$this->assertEquals(0, $this->ba->getBalance());
$this->assertSame(0, $this->ba->getBalance());
}
}

Expand Down Expand Up @@ -783,7 +783,7 @@ you can define a data set using the ``@testWith`` annotation.
*/
public function testStringLength(string $input, int $expectedLength)
{
$this->assertEquals($expectedLength, strlen($input));
$this->assertSame($expectedLength, strlen($input));
}

.. _appendixes.annotations.ticket:
Expand Down
12 changes: 6 additions & 6 deletions src/code-coverage-analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ shows an example.
*/
public function testBalanceIsInitiallyZero()
{
$this->assertEquals(0, $this->ba->getBalance());
$this->assertSame(0, $this->ba->getBalance());
}

/**
Expand All @@ -229,7 +229,7 @@ shows an example.
}

catch (BankAccountException $e) {
$this->assertEquals(0, $this->ba->getBalance());
$this->assertSame(0, $this->ba->getBalance());

return;
}
Expand All @@ -247,7 +247,7 @@ shows an example.
}

catch (BankAccountException $e) {
$this->assertEquals(0, $this->ba->getBalance());
$this->assertSame(0, $this->ba->getBalance());

return;
}
Expand All @@ -262,11 +262,11 @@ shows an example.
*/
public function testDepositWithdrawMoney()
{
$this->assertEquals(0, $this->ba->getBalance());
$this->assertSame(0, $this->ba->getBalance());
$this->ba->depositMoney(1);
$this->assertEquals(1, $this->ba->getBalance());
$this->assertSame(1, $this->ba->getBalance());
$this->ba->withdrawMoney(1);
$this->assertEquals(0, $this->ba->getBalance());
$this->assertSame(0, $this->ba->getBalance());
}
}
?>
Expand Down
8 changes: 4 additions & 4 deletions src/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ following way:
{
public function testCalculate()
{
$this->assertEquals(2, 1 + 1);
$this->assertSame(2, 1 + 1);
}
}
?>
Expand Down Expand Up @@ -1340,7 +1340,7 @@ which has to be returned from the

public function testGetRowCount()
{
$this->assertEquals(2, $this->getConnection()->getRowCount('guestbook'));
$this->assertSame(2, $this->getConnection()->getRowCount('guestbook'));
}
}
?>
Expand Down Expand Up @@ -1379,12 +1379,12 @@ examples, but a third one:

public function testAddEntry()
{
$this->assertEquals(2, $this->getConnection()->getRowCount('guestbook'), "Pre-Condition");
$this->assertSame(2, $this->getConnection()->getRowCount('guestbook'), "Pre-Condition");

$guestbook = new Guestbook();
$guestbook->addEntry("suzy", "Hello world!");

$this->assertEquals(3, $this->getConnection()->getRowCount('guestbook'), "Inserting failed");
$this->assertSame(3, $this->getConnection()->getRowCount('guestbook'), "Inserting failed");
}
}
?>
Expand Down
6 changes: 3 additions & 3 deletions src/fixtures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ creation of the ``array`` fixture into the
``setUp()`` method. Finally, we remove the redundant code
from the test methods and use the newly introduced instance variable,
``$this->stack``, instead of the method-local variable
``$stack`` with the ``assertEquals()``
``$stack`` with the ``assertSame()``
assertion method.

.. code-block:: php
Expand All @@ -67,14 +67,14 @@ assertion method.
public function testPush()
{
array_push($this->stack, 'foo');
$this->assertEquals('foo', $this->stack[count($this->stack)-1]);
$this->assertSame('foo', $this->stack[count($this->stack)-1]);
$this->assertFalse(empty($this->stack));
}

public function testPop()
{
array_push($this->stack, 'foo');
$this->assertEquals('foo', array_pop($this->stack));
$this->assertSame('foo', array_pop($this->stack));
$this->assertTrue(empty($this->stack));
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/test-doubles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ the example. This leads to more readable and "fluent" code.

// Calling $stub->doSomething() will now return
// 'foo'.
$this->assertEquals('foo', $stub->doSomething());
$this->assertSame('foo', $stub->doSomething());
}
}
?>
Expand Down Expand Up @@ -146,7 +146,7 @@ the same best practice defaults used by ``createMock()``.
public function testStub()
{
// Create a stub for the SomeClass class.
$stub = $this->getMockBuilder($originalClassName)
$stub = $this->getMockBuilder(SomeClass::class)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
Expand All @@ -159,7 +159,7 @@ the same best practice defaults used by ``createMock()``.

// Calling $stub->doSomething() will now return
// 'foo'.
$this->assertEquals('foo', $stub->doSomething());
$this->assertSame('foo', $stub->doSomething());
}
}
?>
Expand Down Expand Up @@ -194,10 +194,10 @@ can achieve this using ``returnArgument()`` instead of
->will($this->returnArgument(0));

// $stub->doSomething('foo') returns 'foo'
$this->assertEquals('foo', $stub->doSomething('foo'));
$this->assertSame('foo', $stub->doSomething('foo'));

// $stub->doSomething('bar') returns 'bar'
$this->assertEquals('bar', $stub->doSomething('bar'));
$this->assertSame('bar', $stub->doSomething('bar'));
}
}
?>
Expand Down Expand Up @@ -264,8 +264,8 @@ an example.

// $stub->doSomething() returns different values depending on
// the provided arguments.
$this->assertEquals('d', $stub->doSomething('a', 'b', 'c'));
$this->assertEquals('h', $stub->doSomething('e', 'f', 'g'));
$this->assertSame('d', $stub->doSomething('a', 'b', 'c'));
$this->assertSame('h', $stub->doSomething('e', 'f', 'g'));
}
}
?>
Expand Down Expand Up @@ -296,7 +296,7 @@ result of a callback function or method. See
->will($this->returnCallback('str_rot13'));

// $stub->doSomething($argument) returns str_rot13($argument)
$this->assertEquals('fbzrguvat', $stub->doSomething('something'));
$this->assertSame('fbzrguvat', $stub->doSomething('something'));
}
}
?>
Expand Down Expand Up @@ -326,9 +326,9 @@ an example.
->will($this->onConsecutiveCalls(2, 3, 5, 7));

// $stub->doSomething() returns a different value each time
$this->assertEquals(2, $stub->doSomething());
$this->assertEquals(3, $stub->doSomething());
$this->assertEquals(5, $stub->doSomething());
$this->assertSame(2, $stub->doSomething());
$this->assertSame(3, $stub->doSomething());
$this->assertSame(5, $stub->doSomething());
}
}
?>
Expand Down
2 changes: 1 addition & 1 deletion src/textui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ indicate progress:

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