Skip to content
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## [Unreleased]

### Changed

- Requires `innmind/black-box:~7.0`
7 changes: 3 additions & 4 deletions blackbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
__DIR__.'/src/',
__DIR__.'/proofs/',
)
->dumpTo('coverage.clover')
->enableWhen(true),
->dumpTo('coverage.clover'),
),
)
->tryToProve(static function() {
yield from Load::everythingIn(__DIR__.'/proofs/')();
->tryToProve(static function($prove) {
yield from Load::everythingIn(__DIR__.'/proofs/')($prove);
yield from PHPUnit\Load::testsAt(__DIR__.'/tests/');
})
->exit();
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
},
"require-dev": {
"innmind/static-analysis": "~1.3",
"innmind/black-box": "~6.5",
"innmind/black-box": "~7.0",
"innmind/coding-standard": "~2.0"
},
"conflict": {
"innmind/black-box": "<6.0|~7.0"
"innmind/black-box": "<7.0|~8.0"
},
"suggest": {
"innmind/black-box": "For property based testing"
},
"provide": {
"innmind/black-box-sets": "6.0"
"innmind/black-box-sets": "7.0"
}
}
4 changes: 2 additions & 2 deletions fixtures/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function any(): Set
Set::integers()->between(0, 59),
Set::integers()->between(0, 999),
Set::integers()->between(0, 999),
)->toSet();
);
}

/**
Expand Down Expand Up @@ -60,6 +60,6 @@ static function($day, $hour, $minute, $second, $millisecond, $microsecond): Mode
Set::integers()->between(0, 59),
Set::integers()->between(0, 999),
Set::integers()->between(0, 999),
)->toSet();
);
}
}
2 changes: 1 addition & 1 deletion fixtures/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ static function(
Set::of('-', '+'),
Set::integers()->between(0, 12),
Set::of('00', '15', '30', '45'),
)->toSet();
);
}
}
4 changes: 2 additions & 2 deletions fixtures/Zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
final class Zone
{
/**
* @return Set\Provider<callable(Zones): Model>
* @return Set<callable(Zones): Model>
*/
public static function any(): Set\Provider
public static function any(): Set
{
return Set::compose(
static fn($offset, $daylight) => static fn(Zones $timezones) => Model::of(
Expand Down
84 changes: 39 additions & 45 deletions proofs/clock.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
};
use Innmind\BlackBox\Set;

return static function() {
yield proof(
'All models are always within bounds',
given(Set::either(
return static function($prove) {
yield $prove
->proof('All models are always within bounds')
->given(Set::either(
PointInTime::any(),
Set::call(static fn() => Clock::live()->now()),
)),
static function($assert, $point) {
Set::of(Clock::live()->now()),
))
->test(static function($assert, $point) {
$assert
->number($point->day()->ofYear())
->int()
Expand Down Expand Up @@ -66,13 +66,12 @@ static function($assert, $point) {
->int()
->greaterThanOrEqual(365)
->lessThanOrEqual(366);
},
);
});

yield proof(
'Point in times precision is down to the microsecond',
given(PointInTime::any()),
static function($assert, $point) {
yield $prove
->proof('Point in times precision is down to the microsecond')
->given(PointInTime::any())
->test(static function($assert, $point) {
$assert->false(
$point->equals(
$point->goBack(Period::microsecond(1)),
Expand All @@ -94,12 +93,11 @@ static function($assert, $point) {
$point->goBack(Period::microsecond(1)),
),
);
},
);
});

yield proof(
'Clock::at() returns nothing for invalid strings',
given(
yield $prove
->proof('Clock::at() returns nothing for invalid strings')
->given(
Set::strings()->unicode(),
Set::of(
Format::cookie(),
Expand All @@ -112,18 +110,17 @@ static function($assert, $point) {
Format::rss(),
Format::w3c(),
),
),
static fn($assert, $string, $format) => $assert->null(
)
->test(static fn($assert, $string, $format) => $assert->null(
Clock::live()->at($string, $format)->match(
static fn($point) => $point,
static fn() => null,
),
),
);
));

yield proof(
'Clock::ofFormat()->at()',
given(
yield $prove
->proof('Clock::ofFormat()->at()')
->given(
PointInTime::any(),
Set::of(
Format::iso8601(),
Expand All @@ -134,8 +131,8 @@ public function normalize(): Format
}
},
),
),
static function($assert, $point, $format) {
)
->test(static function($assert, $point, $format) {
$parsed = Clock::live()
->ofFormat($format)
->at($point->format($format))
Expand All @@ -154,12 +151,11 @@ static function($assert, $point, $format) {
),
$parsed,
);
},
);
});

yield proof(
'Each call to Clock::now() is ahead of the previous',
given(
yield $prove
->proof('Each call to Clock::now() is ahead of the previous')
->given(
Set::of(
Clock::live(),
Clock::via( // to make sure the now is not memoized
Expand All @@ -169,8 +165,8 @@ static function($assert, $point, $format) {
Set::integers()
->between(1, 2_000_000) // up to 2 seconds
->nullable(),
),
static function($assert, $clock, $microsecond) {
)
->test(static function($assert, $clock, $microsecond) {
$start = $clock->now();

if (\is_int($microsecond)) {
Expand All @@ -182,10 +178,9 @@ static function($assert, $clock, $microsecond) {
$start,
),
);
},
);
});

yield test(
yield $prove->test(
'Clock::now() is equal to iteself',
static function($assert) {
$clock = Clock::live();
Expand All @@ -195,7 +190,7 @@ static function($assert) {
},
);

yield test(
yield $prove->test(
'Clock::via()->switch()->now() applies the offset at the provided now date',
static function($assert) {
$clock = Clock::via(
Expand All @@ -222,7 +217,7 @@ static function($assert) {
},
);

yield test(
yield $prove->test(
'Clock::frozen()->switch()->now() applies the offset at the provided now date',
static function($assert) {
$clock = Clock::frozen(
Expand All @@ -249,13 +244,12 @@ static function($assert) {
},
);

yield proof(
'Timezone fixtures',
given(Zone::any()),
static function($assert, $timezone) {
yield $prove
->proof('Timezone fixtures')
->given(Zone::any())
->test(static function($assert, $timezone) {
$clock = Clock::live()->switch($timezone);

$assert->string($clock->now()->toString());
},
);
});
};
72 changes: 35 additions & 37 deletions proofs/elapsedPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
use Fixtures\Innmind\Time as Fixtures;
use Innmind\BlackBox\Set;

return static function() {
yield proof(
'High resolution elapsed period',
given(
return static function($prove) {
yield $prove
->proof('High resolution elapsed period')
->given(
Set::integers()->above(0),
Set::integers()->above(0),
Set::integers()->between(0, 999_999_999),
Set::integers()->between(0, 999_999_999),
)->filter(static fn($start, $end) => $end > $start),
static function(
)
->filter(static fn($start, $end) => $end > $start)
->test(static function(
$assert,
$startSeconds,
$endSeconds,
Expand All @@ -42,16 +43,16 @@ static function(
Period::microsecond(1)->asElapsedPeriod(),
),
);
},
);
});

yield proof(
'High resolution elapsed period within same second',
given(
yield $prove
->proof('High resolution elapsed period within same second')
->given(
Set::integers()->between(0, 999_999_999),
Set::integers()->between(0, 999_999_999),
)->filter(static fn($start, $end) => $end > $start && ($end - $start) > 1_000),
static function(
)
->filter(static fn($start, $end) => $end > $start && ($end - $start) > 1_000)
->test(static function(
$assert,
$startNanoseconds,
$endNanoseconds,
Expand All @@ -73,16 +74,15 @@ static function(
Period::microsecond(1)->asElapsedPeriod(),
),
);
},
);
});

yield proof(
'Elapsed period',
given(
yield $prove
->proof('Elapsed period')
->given(
Fixtures\Point::any(),
Set::integers()->above(1),
),
static function($assert, $start, $microsecond) {
)
->test(static function($assert, $start, $microsecond) {
$assert->true(
$start
->elapsedSince($start)
Expand All @@ -106,33 +106,32 @@ static function($assert, $start, $microsecond) {
Period::microsecond(0)->asElapsedPeriod(),
),
);
},
);
});

yield proof(
'Negative elapsed periods throws',
given(
yield $prove
->proof('Negative elapsed periods throws')
->given(
Fixtures\Point::any(),
Set::integers()->above(1),
),
static function($assert, $start, $microsecond) {
)
->test(static function($assert, $start, $microsecond) {
$assert->throws(
static fn() => $start
->goBack(Period::microsecond($microsecond))
->elapsedSince($start),
);
},
);
});

yield proof(
'Negative high resolution elapsed periods throws',
given(
yield $prove
->proof('Negative high resolution elapsed periods throws')
->given(
Set::integers()->above(0),
Set::integers()->above(0),
Set::integers()->between(0, 999_999_999),
Set::integers()->between(0, 999_999_999),
)->filter(static fn($start, $end) => $end > $start),
static function(
)
->filter(static fn($start, $end) => $end > $start)
->test(static function(
$assert,
$startSeconds,
$endSeconds,
Expand All @@ -145,10 +144,9 @@ static function(
$assert->throws(
static fn() => $start->elapsedSince($end),
);
},
);
});

yield test(
yield $prove->test(
'Regression elapsed period',
static function($assert) {
$before = ElapsedPeriod::of(1, 987, 564);
Expand Down
Loading
Loading