Skip to content

Commit

Permalink
Test overflow with more iterations and debug infos
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Oct 5, 2024
1 parent 50c0e29 commit 8ae1b0c
Showing 1 changed file with 52 additions and 10 deletions.
62 changes: 52 additions & 10 deletions tests/Carbon/SettersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class SettersTest extends AbstractTestCase
{
public const SET_UNIT_NO_OVERFLOW_SAMPLE = 200;
public const SET_UNIT_NO_OVERFLOW_SAMPLE = 20_000;

public function testMonthEnum()
{
Expand Down Expand Up @@ -635,7 +635,7 @@ public function testSetUnitNoOverflow()
'current' => 0,
'start' => 0,
'end' => 0,
'failure' => 0,
'failure' => [],
];

for ($i = 0; $i < static::SET_UNIT_NO_OVERFLOW_SAMPLE; $i++) {
Expand Down Expand Up @@ -669,7 +669,21 @@ public function testSetUnitNoOverflow()
$end = $original->copy()->endOf($overflowUnit);

if ($date < $start || $date > $end) {
$results['failure']++;
$results['failure'][] = [
'year' => $year,
'month' => $month,
'day' => $day,
'hour' => $hour,
'minute' => $minute,
'second' => $second,
'microsecond' => $microsecond,
'valueUnit' => $valueUnit,
'value' => $value,
'overflowUnit' => $overflowUnit,
'date' => $date->format('Y-m-d H:i:s'),
'start' => $start->format('Y-m-d H:i:s'),
'end' => $end->format('Y-m-d H:i:s'),
];

continue;
}
Expand Down Expand Up @@ -722,7 +736,7 @@ public function testSetUnitNoOverflow()
}

$minimum = static::SET_UNIT_NO_OVERFLOW_SAMPLE / 100;
$this->assertSame(0, $results['failure']);
$this->assertSame([], $results['failure']);
$this->assertGreaterThan($minimum, $results['start']);
$this->assertGreaterThan($minimum, $results['end']);
$this->assertGreaterThan($minimum, $results['current']);
Expand Down Expand Up @@ -766,7 +780,7 @@ public function testAddUnitNoOverflow()
'current' => 0,
'start' => 0,
'end' => 0,
'failure' => 0,
'failure' => [],
];

for ($i = 0; $i < static::SET_UNIT_NO_OVERFLOW_SAMPLE; $i++) {
Expand Down Expand Up @@ -800,7 +814,21 @@ public function testAddUnitNoOverflow()
$end = $original->copy()->endOf($overflowUnit);

if ($date < $start || $date > $end) {
$results['failure']++;
$results['failure'][] = [
'year' => $year,
'month' => $month,
'day' => $day,
'hour' => $hour,
'minute' => $minute,
'second' => $second,
'microsecond' => $microsecond,
'valueUnit' => $valueUnit,
'value' => $value,
'overflowUnit' => $overflowUnit,
'date' => $date->format('Y-m-d H:i:s'),
'start' => $start->format('Y-m-d H:i:s'),
'end' => $end->format('Y-m-d H:i:s'),
];

continue;
}
Expand Down Expand Up @@ -848,7 +876,7 @@ public function testAddUnitNoOverflow()
}

$minimum = static::SET_UNIT_NO_OVERFLOW_SAMPLE / 100;
$this->assertSame(0, $results['failure']);
$this->assertSame([], $results['failure']);
$this->assertGreaterThan($minimum, $results['start']);
$this->assertGreaterThan($minimum, $results['end']);
$this->assertGreaterThan($minimum, $results['current']);
Expand All @@ -861,7 +889,7 @@ public function testSubUnitNoOverflow()
'current' => 0,
'start' => 0,
'end' => 0,
'failure' => 0,
'failure' => [],
];

for ($i = 0; $i < static::SET_UNIT_NO_OVERFLOW_SAMPLE; $i++) {
Expand Down Expand Up @@ -895,7 +923,21 @@ public function testSubUnitNoOverflow()
$end = $original->copy()->endOf($overflowUnit);

if ($date < $start || $date > $end) {
$results['failure']++;
$results['failure'][] = [
'year' => $year,
'month' => $month,
'day' => $day,
'hour' => $hour,
'minute' => $minute,
'second' => $second,
'microsecond' => $microsecond,
'valueUnit' => $valueUnit,
'value' => $value,
'overflowUnit' => $overflowUnit,
'date' => $date->format('Y-m-d H:i:s'),
'start' => $start->format('Y-m-d H:i:s'),
'end' => $end->format('Y-m-d H:i:s'),
];

continue;
}
Expand Down Expand Up @@ -960,7 +1002,7 @@ public function testSubUnitNoOverflow()
}

$minimum = static::SET_UNIT_NO_OVERFLOW_SAMPLE / 100;
$this->assertSame(0, $results['failure']);
$this->assertSame([], $results['failure']);
$this->assertGreaterThan($minimum, $results['start']);
$this->assertGreaterThan($minimum, $results['end']);
$this->assertGreaterThan($minimum, $results['current']);
Expand Down

0 comments on commit 8ae1b0c

Please sign in to comment.