Skip to content

Ensure that assertSame generates diff for arrays #2976

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 1 commit into from
Jan 27, 2018

Conversation

mhujer
Copy link
Contributor

@mhujer mhujer commented Jan 27, 2018

Fixes #2169.

With this patch, the arrays are diffed for assertSame() similarly to assertEquals():

<?php declare(strict_types = 1);

use PHPUnit\Framework\TestCase;

class ArrayDiffTest extends TestCase
{
	public function testEquality()
	{
		$this->assertEquals(
			[1, 2, 3, 4, 5, 6],
			[1, 2, 33, 4, 5, 6]
		);
	}

	public function testSame()
	{
		$this->assertSame(
			[1, 2, 3, 4, 5, 6],
			[1, 2, 33, 4, 5, 6]
		);
	}
1) ArrayDiffTest::testEquality
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => 1
     1 => 2
-    2 => 3
+    2 => 33


2) ArrayDiffTest::testSame
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
 Array &0 (
     0 => 1
     1 => 2
-    2 => 3
+    2 => 33

I also tested it with PHPStorm and it fixes the diffing issue there as well:

image

Questions:

  1. is this a correct approach?
  2. Wouldn't is be better to merge it to 6.5 branch?

@mhujer
Copy link
Contributor Author

mhujer commented Jan 27, 2018

Appveyor failure seems unrelated. It is caused by http://windows.php.net/downloads/releases/php-7.2.0-Win32-VC15-x86.zip not being available (7.2.1 is available, so probably the version number should be incremented in AppVeyor config).

EDIT: See #2977

@sebastianbergmann sebastianbergmann merged commit 25b2df6 into sebastianbergmann:master Jan 27, 2018
@mhujer mhujer deleted the mh-fix-2169 branch January 27, 2018 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Method assertSame doesn't create ComparisonFailure for arrays
2 participants