|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Halivert\JSRoutes\Tests; |
| 4 | + |
| 5 | +use Halivert\JSRoutes\Console\CreateJSRoutesCommand; |
| 6 | +use Illuminate\Routing\Router; |
| 7 | +use Orchestra\Testbench\TestCase; |
| 8 | + |
| 9 | +class CreateOnlyGETMethodsTest extends TestCase |
| 10 | +{ |
| 11 | + protected function getPackageProviders($app) |
| 12 | + { |
| 13 | + return [ |
| 14 | + 'Halivert\JSRoutes\Tests\Stubs\Providers\JSRoutesServiceProviderTest' |
| 15 | + ]; |
| 16 | + } |
| 17 | + |
| 18 | + protected function getEnvironmentSetUp($app) |
| 19 | + { |
| 20 | + $app['router']->get('get', ['as' => 'get', 'uses' => function () { |
| 21 | + return 'hello world'; |
| 22 | + }]); |
| 23 | + |
| 24 | + $app['router']->get('get/{id}', ['as' => 'hi', 'uses' => function () { |
| 25 | + return 'hello world'; |
| 26 | + }]); |
| 27 | + |
| 28 | + $app['router']->post('post', function () { |
| 29 | + return 'goodbye world'; |
| 30 | + })->name('bye'); |
| 31 | + |
| 32 | + $app['router']->group(['prefix' => 'boss'], function (Router $router) { |
| 33 | + $router->put('put', ['as' => 'boss.hi', 'uses' => function () { |
| 34 | + return 'hello boss'; |
| 35 | + }]); |
| 36 | + |
| 37 | + $router->delete('delete', function () { |
| 38 | + return 'goodbye boss'; |
| 39 | + })->name('boss.bye'); |
| 40 | + }); |
| 41 | + |
| 42 | + |
| 43 | + $app['router']->patch('patch', function () { |
| 44 | + return 'goodbye world'; |
| 45 | + })->name('patch'); |
| 46 | + |
| 47 | + $app['router']->options('options', function () { |
| 48 | + return 'goodbye world'; |
| 49 | + })->name('options'); |
| 50 | + |
| 51 | + $app['router']->get('bruh', function () { |
| 52 | + return 'goodbye world'; |
| 53 | + })->name('telescope'); |
| 54 | + |
| 55 | + $app['router']->get('bruh/get', function () { |
| 56 | + return 'Telescope get'; |
| 57 | + })->name('telescope.get'); |
| 58 | + |
| 59 | + |
| 60 | + $app['router']->get('multi/{id}/param/{id2}/url/{id}', function () { |
| 61 | + return 'goodbye world'; |
| 62 | + })->name('multiparam'); |
| 63 | + |
| 64 | + $app['config']->set('app.jsroutes.path', './'); |
| 65 | + $app['config']->set('app.jsroutes.methods', ['GET']); |
| 66 | + $app['config']->set('app.jsroutes.include', ['get']); |
| 67 | + $app['config']->set('app.jsroutes.exclude', ['telescope*']); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @test |
| 72 | + */ |
| 73 | + public function it_creates_file() |
| 74 | + { |
| 75 | + if (file_exists(realpath('./routes.js'))) { |
| 76 | + $this->artisan('route:tojs')->expectsQuestion( |
| 77 | + "The [routes.js] file already exists. Do you want to replace it?", |
| 78 | + "yes" |
| 79 | + )->expectsOutput('routes.js created')->assertExitCode(0); |
| 80 | + } else { |
| 81 | + $this->artisan('route:tojs') |
| 82 | + ->expectsOutput('routes.js created') |
| 83 | + ->assertExitCode(0); |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments