Permalink
Browse files

Merge branch '8.0'

  • Loading branch information...
sebastianbergmann committed Feb 5, 2019
2 parents 093fc2c + 6205f33 commit ae06eafd42900b5119f444fcb94a94d2db9d784a
Showing with 55 additions and 2 deletions.
  1. +1 −0 ChangeLog-8.0.md
  2. +16 −2 src/Framework/Assert.php
  3. +38 −0 tests/unit/Framework/AssertTest.php
@@ -7,6 +7,7 @@ All notable changes of the PHPUnit 8.0 release series are documented in this fil
### Fixed

* Fixed [#3508](https://github.com/sebastianbergmann/phpunit/pull/3508): `TypeError` in `Fileloader` when trying to load nonexistent file
* Fixed [#3511](https://github.com/sebastianbergmann/phpunit/issues/3511): Asserting that an object is contained in an `iterable` while using `==` instead of `===` is no longer possible

## [8.0.1] - 2019-02-03

@@ -188,7 +188,7 @@ public static function assertContains($needle, $haystack, string $message = '',
}
if ($checkForObjectIdentity !== true) {
self::createWarning('The optional $checkForObjectIdentity parameter of assertContains() is deprecated and will be removed in PHPUnit 9.');
self::createWarning('The optional $checkForObjectIdentity parameter of assertContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertContainsEquals() instead.');
}
if ($checkForNonObjectIdentity !== false) {
@@ -229,6 +229,13 @@ public static function assertContains($needle, $haystack, string $message = '',
static::assertThat($haystack, $constraint, $message);
}
public static function assertContainsEquals($needle, iterable $haystack, string $message = ''): void
{
$constraint = new TraversableContains($needle, false, false);
static::assertThat($haystack, $constraint, $message);
}
/**
* Asserts that a haystack that is stored in a static attribute of a class
* or an attribute of an object contains a needle.
@@ -272,7 +279,7 @@ public static function assertNotContains($needle, $haystack, string $message = '
}
if ($checkForObjectIdentity !== true) {
self::createWarning('The optional $checkForObjectIdentity parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.');
self::createWarning('The optional $checkForObjectIdentity parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotContainsEquals() instead.');
}
if ($checkForNonObjectIdentity !== false) {
@@ -317,6 +324,13 @@ public static function assertNotContains($needle, $haystack, string $message = '
static::assertThat($haystack, $constraint, $message);
}
public static function assertNotContainsEquals($needle, iterable $haystack, string $message = ''): void
{
$constraint = new LogicalNot(new TraversableContains($needle, false, false));
static::assertThat($haystack, $constraint, $message);
}
/**
* Asserts that a haystack that is stored in a static attribute of a class
* or an attribute of an object does not contain a needle.
@@ -2192,6 +2192,44 @@ public function testIterableNotContainsSameObjectCanBeAsserted(): void
$this->fail();
}
public function testIterableContainsEqualObjectCanBeAsserted(): void
{
$a = new \stdClass;
$a->foo = 'bar';
$b = new \stdClass;
$b->foo = 'baz';
$this->assertContainsEquals($a, [$a]);
try {
$this->assertContainsEquals($b, [$a]);
} catch (AssertionFailedError $e) {
return;
}
$this->fail();
}
public function testIterableNotContainsEqualObjectCanBeAsserted(): void
{
$a = new \stdClass;
$a->foo = 'bar';
$b = new \stdClass;
$b->foo = 'baz';
$this->assertNotContainsEquals($b, [$a]);
try {
$this->assertNotContainsEquals($a, [$a]);
} catch (AssertionFailedError $e) {
return;
}
$this->fail();
}
protected function sameValues(): array
{
$object = new \SampleClass(4, 8, 15);

0 comments on commit ae06eaf

Please sign in to comment.