Skip to content
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

Fix regression with self-referencing arrays handling #2638

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
2 changes: 1 addition & 1 deletion src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ private function registerMockObjectsFromTestArguments(array $testArguments, arra
}

$this->registerMockObject($testArgument);
} elseif (is_array($testArgument) && !in_array($testArgument, $visited)) {
} elseif (is_array($testArgument) && !in_array($testArgument, $visited, true)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice fix

@sebastianbergmann , would you consider applying strictness for is_array globally ?

$visited[] = $testArgument;

$this->registerMockObjectsFromTestArguments(
Expand Down
17 changes: 16 additions & 1 deletion tests/Framework/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public function testConfiguredMockCanBeCreated()
$this->assertNull($mock->bar());
}

public function testProvidingOfAuoreferencedArray()
public function testProvidingOfAutoreferencedArray()
{
$test = new \TestAutoreferenced('testJsonEncodeException', $this->getAutoreferencedArray());
$test->runBare();
Expand All @@ -671,4 +671,19 @@ private function getAutoreferencedArray()
]
];
}

public function testProvidingArrayThatMixesObjectsAndScalars()
{
$data = [
[123],
['foo'],
[$this->createMock(Mockable::class)],
];

$test = new \TestAutoreferenced('testJsonEncodeException', [$data]);
$test->runBare();

$this->assertInternalType('array', $test->myTestData);
$this->assertSame($data, $test->myTestData);
}
}