Skip to content

Commit

Permalink
Fix file assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerkretzmar committed May 17, 2024
1 parent 65107c3 commit 5d3699f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 6 additions & 2 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use PHPUnit\Framework\Assert;

/*
|--------------------------------------------------------------------------
| Test Case
Expand All @@ -24,8 +26,10 @@
|
*/

expect()->extend('toBeOne', function () {
return $this->toBe(1);
expect()->extend('toEqualFile', function (string $expected, string $message = '') {
Assert::assertFileEquals($expected, $this->value, $message);

return $this;
});

/*
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/CommandRouteGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

artisan('ziggy:generate');

expect(base_path('resources/js/ziggy.js'))->toBeFile('./tests/fixtures/ziggy.js');
expect(base_path('resources/js/ziggy.js'))->toEqualFile('./tests/fixtures/ziggy.js');
});

test('generate file with custom url', function () {
Expand All @@ -43,15 +43,15 @@

artisan('ziggy:generate --url http://example.org');

expect(base_path('resources/js/ziggy.js'))->toBeFile('./tests/fixtures/custom-url.js');
expect(base_path('resources/js/ziggy.js'))->toEqualFile('./tests/fixtures/custom-url.js');
});

test('generate file with custom pathname', function () {
Route::get('posts/{post}/comments', fn () => '')->name('postComments.index');

artisan('ziggy:generate --url /foo/bar');

expect(base_path('resources/js/ziggy.js'))->toBeFile('./tests/fixtures/custom-pathname.js');
expect(base_path('resources/js/ziggy.js'))->toEqualFile('./tests/fixtures/custom-pathname.js');
});

test('generate file respecting config', function () {
Expand All @@ -63,7 +63,7 @@

artisan('ziggy:generate');

expect(base_path('resources/js/ziggy.js'))->toBeFile('./tests/fixtures/ziggy.js');
expect(base_path('resources/js/ziggy.js'))->toEqualFile('./tests/fixtures/ziggy.js');
});

test('generate file with custom output formatter', function () {
Expand All @@ -81,7 +81,7 @@

artisan('ziggy:generate');

expect(base_path('resources/js/ziggy.js'))->toBeFile('./tests/fixtures/ziggy-custom.js');
expect(base_path('resources/js/ziggy.js'))->toEqualFile('./tests/fixtures/ziggy-custom.js');
});

test('generate file for groups', function () {
Expand All @@ -97,7 +97,7 @@

artisan('ziggy:generate resources/js/admin.js --group admin');

expect(base_path('resources/js/admin.js'))->toBeFile('./tests/fixtures/admin.js');
expect(base_path('resources/js/admin.js'))->toEqualFile('./tests/fixtures/admin.js');
});

test('generate file at path set in config', function () {
Expand All @@ -124,7 +124,7 @@
);
}

expect(base_path('resources/js/ziggy.d.ts'))->toBeFile('./tests/fixtures/ziggy.d.ts');
expect(base_path('resources/js/ziggy.d.ts'))->toEqualFile('./tests/fixtures/ziggy.d.ts');
});

test('generate dts file without generating routes file', function () {
Expand Down
8 changes: 6 additions & 2 deletions tests/fixtures/ziggy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare module 'ziggy-js' {
"name": "post",
"required": true
}
]
],
"comments.show": [
{
"name": "post",
Expand All @@ -20,11 +20,15 @@ declare module 'ziggy-js' {
}
],
"reactions.store": [
{
"name": "post",
"required": true
},
{
"name": "reaction",
"required": false
}
],
]
}
}
export {};

0 comments on commit 5d3699f

Please sign in to comment.