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

Commit 7b48199

Browse files
committed
Keys shouldn't be mutually exclusive
1 parent bfb276e commit 7b48199

File tree

2 files changed

+91
-5
lines changed

2 files changed

+91
-5
lines changed

src/Console/CreateJSRoutesCommand.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ private function includeRoute($route, $routeName)
9999
{
100100
$include = $this->getOption('include');
101101

102-
if (!empty($include)) {
103-
return Str::is($include, $routeName);
102+
if (!empty($include) and Str::is($include, $routeName)) {
103+
return true;
104104
}
105105

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

108-
if (!empty($exclude)) {
109-
return !Str::is($exclude, $routeName);
110-
};
108+
if (!empty($exclude) and Str::is($exclude, $routeName)) {
109+
return false;
110+
}
111111

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

tests/CreateOnlyGETMethodsTest.php

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

Comments
 (0)