Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Keys shouldn't be mutually exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
halivert committed Apr 27, 2021
1 parent bfb276e commit 7b48199
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Console/CreateJSRoutesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ private function includeRoute($route, $routeName)
{
$include = $this->getOption('include');

if (!empty($include)) {
return Str::is($include, $routeName);
if (!empty($include) and Str::is($include, $routeName)) {
return true;
}

$exclude = $this->getOption('exclude');

if (!empty($exclude)) {
return !Str::is($exclude, $routeName);
};
if (!empty($exclude) and Str::is($exclude, $routeName)) {
return false;
}

$methods = $this->getOption('methods');

Expand Down
86 changes: 86 additions & 0 deletions tests/CreateOnlyGETMethodsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Halivert\JSRoutes\Tests;

use Halivert\JSRoutes\Console\CreateJSRoutesCommand;
use Illuminate\Routing\Router;
use Orchestra\Testbench\TestCase;

class CreateOnlyGETMethodsTest extends TestCase
{
protected function getPackageProviders($app)
{
return [
'Halivert\JSRoutes\Tests\Stubs\Providers\JSRoutesServiceProviderTest'
];
}

protected function getEnvironmentSetUp($app)
{
$app['router']->get('get', ['as' => 'get', 'uses' => function () {
return 'hello world';
}]);

$app['router']->get('get/{id}', ['as' => 'hi', 'uses' => function () {
return 'hello world';
}]);

$app['router']->post('post', function () {
return 'goodbye world';
})->name('bye');

$app['router']->group(['prefix' => 'boss'], function (Router $router) {
$router->put('put', ['as' => 'boss.hi', 'uses' => function () {
return 'hello boss';
}]);

$router->delete('delete', function () {
return 'goodbye boss';
})->name('boss.bye');
});


$app['router']->patch('patch', function () {
return 'goodbye world';
})->name('patch');

$app['router']->options('options', function () {
return 'goodbye world';
})->name('options');

$app['router']->get('bruh', function () {
return 'goodbye world';
})->name('telescope');

$app['router']->get('bruh/get', function () {
return 'Telescope get';
})->name('telescope.get');


$app['router']->get('multi/{id}/param/{id2}/url/{id}', function () {
return 'goodbye world';
})->name('multiparam');

$app['config']->set('app.jsroutes.path', './');
$app['config']->set('app.jsroutes.methods', ['GET']);
$app['config']->set('app.jsroutes.include', ['get']);
$app['config']->set('app.jsroutes.exclude', ['telescope*']);
}

/**
* @test
*/
public function it_creates_file()
{
if (file_exists(realpath('./routes.js'))) {
$this->artisan('route:tojs')->expectsQuestion(
"The [routes.js] file already exists. Do you want to replace it?",
"yes"
)->expectsOutput('routes.js created')->assertExitCode(0);
} else {
$this->artisan('route:tojs')
->expectsOutput('routes.js created')
->assertExitCode(0);
}
}
}

0 comments on commit 7b48199

Please sign in to comment.