From b7d765758cff597b5cf2d75b46633799a268b583 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 5 Jan 2022 11:57:57 +0000 Subject: [PATCH] Test valid return types --- tests/func_015.phpt | 43 +++++++++++++++++++++++++++++++++++-------- tests/func_016.phpt | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 16 deletions(-) diff --git a/tests/func_015.phpt b/tests/func_015.phpt index 4bd1e9d..067634d 100644 --- a/tests/func_015.phpt +++ b/tests/func_015.phpt @@ -12,16 +12,43 @@ timecop.func_override=0 getMessage(), "\n"; + $message = $e->getMessage(); + + // Workaround exception message not including type in PHP 7 so the same test can be used for both. + if (PHP_MAJOR_VERSION === 7) { + $message = str_replace('N/A given', var_type($input).' given', $message); + } + + echo $message, "\n"; } } ---EXPECTREGEX-- -timecop_travel\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|string) given -timecop_travel\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|stdClass) given -timecop_travel\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|string) given -timecop_travel\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|float) given -timecop_travel\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|bool) given +--EXPECT-- +timecop_travel(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, string given +timecop_travel(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, stdClass given +timecop_travel(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, string given +timecop_travel(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, float given +timecop_travel(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, bool given +bool(true) +bool(true) +bool(true) diff --git a/tests/func_016.phpt b/tests/func_016.phpt index 1de378f..6a024b7 100644 --- a/tests/func_016.phpt +++ b/tests/func_016.phpt @@ -12,16 +12,43 @@ timecop.func_override=0 getMessage(), "\n"; + $message = $e->getMessage(); + + // Workaround exception message not including type in PHP 7 so the same test can be used for both. + if (PHP_MAJOR_VERSION === 7) { + $message = str_replace('N/A given', var_type($input).' given', $message); + } + + echo $message, "\n"; } } ---EXPECTREGEX-- -timecop_freeze\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|string) given -timecop_freeze\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|stdClass) given -timecop_freeze\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|string) given -timecop_freeze\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|float) given -timecop_freeze\(\): Argument #1 \(\$timestamp\) must be of type DateTimeInterface|int, (N\/A|bool) given +--EXPECT-- +timecop_freeze(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, string given +timecop_freeze(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, stdClass given +timecop_freeze(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, string given +timecop_freeze(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, float given +timecop_freeze(): Argument #1 ($timestamp) must be of type DateTimeInterface|int, bool given +bool(true) +bool(true) +bool(true)