Skip to content

Commit

Permalink
Merge pull request #2494 from lucasmichot/feat/stricter-exception-tests
Browse files Browse the repository at this point in the history
Make exceptions tests stricter
  • Loading branch information
kylekatarnls authored Nov 8, 2021
2 parents 19102bb + e0dc715 commit f8d6d8a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/Carbon/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Carbon\Carbon;
use Carbon\CarbonInterface;
use Carbon\CarbonInterval;
use Carbon\Exceptions\InvalidFormatException;
use Closure;
use DateTime;
use Exception;
use InvalidArgumentException;
use Tests\AbstractTestCase;

Expand Down Expand Up @@ -1577,7 +1577,7 @@ public function testDiffWithInvalidObject()

public function testDiffForHumansWithIncorrectDateTimeStringWhichIsNotACarbonInstance()
{
$this->expectExceptionObject(new Exception(
$this->expectExceptionObject(new InvalidFormatException(
'Failed to parse time string (2018-04-13-08:00:00) at position 16'
));

Expand Down
7 changes: 3 additions & 4 deletions tests/CarbonImmutable/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Carbon\CarbonImmutable as Carbon;
use Carbon\CarbonInterface;
use Carbon\CarbonInterval;
use Carbon\Exceptions\InvalidFormatException;
use Closure;
use DateTime;
use Exception;
use InvalidArgumentException;
use Tests\AbstractTestCase;

Expand Down Expand Up @@ -1532,10 +1532,9 @@ public function testDiffWithInvalidObject()

public function testDiffForHumansWithIncorrectDateTimeStringWhichIsNotACarbonInstance()
{
$this->expectException(Exception::class);
$this->expectExceptionMessage(
$this->expectExceptionObject(new InvalidFormatException(
'Failed to parse time string (2018-04-13-08:00:00) at position 16'
);
));

$mar13 = Carbon::parse('2018-03-13');
$mar13->diffForHumans('2018-04-13-08:00:00');
Expand Down
1 change: 1 addition & 0 deletions tests/CarbonInterval/CreateFromFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function testInvalidSubstitute()
"Allowed substitutes for interval formats are y, Y, o, m, n, W, d, j, z, h, g, H, G, i, s, u, v\n".
'See https://php.net/manual/en/function.date.php for their meaning'
);
$this->expectExceptionCode(0);

CarbonInterval::createFromFormat('N', '4');
}
Expand Down

0 comments on commit f8d6d8a

Please sign in to comment.