Skip to content

Commit cd96d45

Browse files
committed
test(Support): update JsonFixer test
- Update JsonFixer test - Use chained assertions to improve readability - Fix deprecated usage of JSON_THROW_ON_ERROR
1 parent 83a969c commit cd96d45

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

tests/Support/HeplersTest.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
use Laravel\Lumen\Application;
1616

1717
it('can explode env', function (): void {
18-
expect(env_explode('ENV_EXPLODE_STRING'))->toBeArray()->toBeTruthy();
19-
expect(env_explode('ENV_EXPLODE_EMPTY'))->toBe(['']);
20-
expect(env_explode('ENV_EXPLODE_NOT_EXIST'))->toBeNull();
21-
// expect(env_explode('ENV_EXPLODE_TRUE'))->toBeTrue();
22-
// expect(env_explode('ENV_EXPLODE_FALSE'))->toBeFalse();
23-
// expect(env_explode('ENV_EXPLODE_NULL'))->toBeNull();
18+
expect(env_explode('ENV_EXPLODE_STRING'))->toBeArray()->toBeTruthy()
19+
->and(env_explode('ENV_EXPLODE_EMPTY'))->toBe([''])
20+
->and(env_explode('ENV_EXPLODE_NOT_EXIST'))->toBeNull()
21+
// ->and(env_explode('ENV_EXPLODE_TRUE'))->toBeTrue()
22+
// ->and(env_explode('ENV_EXPLODE_FALSE'))->toBeFalse()
23+
// ->and(env_explode('ENV_EXPLODE_NULL'))->toBeNull()
24+
;
2425
})->group(__DIR__, __FILE__);
2526

2627
it('can return Stringable', function (): void {
27-
expect(str())->toBeInstanceOf(Stringable::class);
28-
expect(str('foo'))->toBeInstanceOf(Illuminate\Support\Stringable::class);
28+
expect(str())->toBeInstanceOf(Stringable::class)
29+
->and(str('foo'))->toBeInstanceOf(Illuminate\Support\Stringable::class);
2930
})->group(__DIR__, __FILE__);
3031

3132
it('can is lumen', function (): void {
32-
expect(is_lumen())->toBeFalse();
33-
expect(is_lumen(app()))->toBeFalse();
34-
expect(is_lumen(app(Application::class)))->toBeTrue();
33+
expect(is_lumen())->toBeFalse()
34+
->and(is_lumen(app()))->toBeFalse()
35+
->and(is_lumen(app(Application::class)))->toBeTrue();
3536
})->group(__DIR__, __FILE__);

tests/Support/JsonFixerTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@
1919
})->group(__DIR__, __FILE__)->with('InvalidJsons');
2020

2121
it('can fix invalid json with missing value', function (): void {
22-
expect(new JsonFixer())
23-
->missingValue('')
24-
->fix(substr(json_encode([1, 2, 3]), 0, 5))->toBeJson();
25-
26-
expect(new JsonFixer())
27-
->silent()
28-
->fix($json = substr(json_encode([1, 2, 3]), 3))->toBe($json)
22+
expect(new JsonFixer())->missingValue('')
23+
->fix(substr(json_encode([1, 2, 3], JSON_THROW_ON_ERROR), 0, 5))->toBeJson()
24+
->and(new JsonFixer())
25+
->silent()->fix($json = substr(json_encode([1, 2, 3], JSON_THROW_ON_ERROR), 3))->toBe($json)
2926
->not->toBeJson();
3027
})->group(__DIR__, __FILE__);
3128

3229
it('will throw RuntimeException', function (): void {
3330
(new JsonFixer())
3431
->silent(false)
35-
->fix(substr(json_encode([1, 2, 3]), 3));
32+
->fix(substr(json_encode([1, 2, 3], JSON_THROW_ON_ERROR), 3));
3633
})->group(__DIR__, __FILE__)->throws(RuntimeException::class, 'Could not fix JSON (tried padding ``)');

tests/TestCase.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class TestCase extends \Orchestra\Testbench\TestCase
4949
use PHPMock;
5050
use VarDumperTestTrait;
5151

52-
protected function setUp(): void
53-
{
54-
parent::setUp();
55-
}
56-
5752
protected function tearDown(): void
5853
{
5954
parent::tearDown();
@@ -64,7 +59,7 @@ protected function tearDown(): void
6459
\Mockery::close();
6560
}
6661

67-
protected function getPackageProviders($app)
62+
protected function getPackageProviders($app): array
6863
{
6964
return [
7065
ExceptionNotifyServiceProvider::class,
@@ -107,12 +102,12 @@ protected function defineEnvironment($app): void
107102

108103
protected function defineRoutes($router): void
109104
{
110-
$router->any('report-exception', static fn () => tap(response('report-exception'), function (): void {
105+
$router->any('report-exception', static fn () => tap(response('report-exception'), static function (): void {
111106
ExceptionNotify::report(new \Exception('What happened?'), ['bark', 'dump', 'null']);
112107
}));
113108

114-
$router->any('exception', static fn () => tap(response('exception'), function (): void {
115-
throw new \Exception('What happened?');
109+
$router->any('exception', static fn () => tap(response('exception'), static function (): void {
110+
throw new \RuntimeException('What happened?');
116111
}));
117112
}
118113
}

0 commit comments

Comments
 (0)