Skip to content

Commit

Permalink
ensure delta is initialized correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey179 committed Dec 26, 2022
1 parent 8ba45d6 commit 9765afc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 7.0.1 (2022-12-26)

* fixed bug with incorrectly initialized delta in `bovigo\assert\predicate\equals()`

## 7.0.0 (2022-12-25)

* Raised minimum required PHP version to 8.0.0
Expand Down
14 changes: 4 additions & 10 deletions src/main/php/predicate/Equals.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@
*/
class Equals extends Predicate implements Delta
{
/**
* @var double
*/
private $delta;
/**
* @var string
*/
private $lastFailureDiff;
private float $delta = 0.0;
private string $lastFailureDiff = '';

public function __construct(private mixed $expected) { }

Expand Down Expand Up @@ -96,7 +90,7 @@ public function __toString(): string
/**
* checks if a diff is available for the last failure
*
* @since 1.7.0
* @since 1.7.0
*/
public function hasDiffForLastFailure(): bool
{
Expand All @@ -106,7 +100,7 @@ public function hasDiffForLastFailure(): bool
/**
* returns diff for last failure
*
* @since 1.7.0
* @since 1.7.0
*/
public function diffForLastFailure(): string
{
Expand Down
15 changes: 15 additions & 0 deletions src/test/php/predicate/EqualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
namespace bovigo\assert\predicate;

use bovigo\assert\AssertionFailure;
use DateTime;
use PHPUnit\Framework\TestCase;
use TypeError;

use function bovigo\assert\assertFalse;
use function bovigo\assert\assertThat;
Expand Down Expand Up @@ -151,4 +153,17 @@ public function notEqualsWithFailingDelta(): void
{
assertFalse(isNotEqualTo(5)->withDelta(0.1)->test(4.9));
}

/**
* @test
* @since 7.0.1
* @group delta_initialized_incorrectly
*/
public function deltaMustNotBeNull(): void
{
$d1 = new DateTime('1980-05-28 06:30:00 Europe/Berlin');
$d2 = new DateTime('@328336200');
expect(fn() => assertThat($d1, equals($d2)))
->doesNotThrow(TypeError::class);
}
}

0 comments on commit 9765afc

Please # to comment.