Skip to content

Commit 9765afc

Browse files
author
Frank Kleine
committed
ensure delta is initialized correctly
1 parent 8ba45d6 commit 9765afc

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 7.0.1 (2022-12-26)
4+
5+
* fixed bug with incorrectly initialized delta in `bovigo\assert\predicate\equals()`
6+
37
## 7.0.0 (2022-12-25)
48

59
* Raised minimum required PHP version to 8.0.0

src/main/php/predicate/Equals.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@
1717
*/
1818
class Equals extends Predicate implements Delta
1919
{
20-
/**
21-
* @var double
22-
*/
23-
private $delta;
24-
/**
25-
* @var string
26-
*/
27-
private $lastFailureDiff;
20+
private float $delta = 0.0;
21+
private string $lastFailureDiff = '';
2822

2923
public function __construct(private mixed $expected) { }
3024

@@ -96,7 +90,7 @@ public function __toString(): string
9690
/**
9791
* checks if a diff is available for the last failure
9892
*
99-
* @since 1.7.0
93+
* @since 1.7.0
10094
*/
10195
public function hasDiffForLastFailure(): bool
10296
{
@@ -106,7 +100,7 @@ public function hasDiffForLastFailure(): bool
106100
/**
107101
* returns diff for last failure
108102
*
109-
* @since 1.7.0
103+
* @since 1.7.0
110104
*/
111105
public function diffForLastFailure(): string
112106
{

src/test/php/predicate/EqualsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
namespace bovigo\assert\predicate;
1010

1111
use bovigo\assert\AssertionFailure;
12+
use DateTime;
1213
use PHPUnit\Framework\TestCase;
14+
use TypeError;
1315

1416
use function bovigo\assert\assertFalse;
1517
use function bovigo\assert\assertThat;
@@ -151,4 +153,17 @@ public function notEqualsWithFailingDelta(): void
151153
{
152154
assertFalse(isNotEqualTo(5)->withDelta(0.1)->test(4.9));
153155
}
156+
157+
/**
158+
* @test
159+
* @since 7.0.1
160+
* @group delta_initialized_incorrectly
161+
*/
162+
public function deltaMustNotBeNull(): void
163+
{
164+
$d1 = new DateTime('1980-05-28 06:30:00 Europe/Berlin');
165+
$d2 = new DateTime('@328336200');
166+
expect(fn() => assertThat($d1, equals($d2)))
167+
->doesNotThrow(TypeError::class);
168+
}
154169
}

0 commit comments

Comments
 (0)