Skip to content

Commit

Permalink
update and several fix
Browse files Browse the repository at this point in the history
  • Loading branch information
muhajirinlpu committed Oct 4, 2023
1 parent 3dc7a20 commit 859f6cf
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 23 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/cs-fix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Coding Standard
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
php-cs-fixer:
runs-on: ubuntu-20.04
Expand Down
10 changes: 6 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Feature">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="build/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
[![Total Downloads](https://poser.pugx.org/dentro/yalr/downloads)](https://packagist.org/packages/dentro/yalr)
[![Laravel Octane Compatible](https://img.shields.io/badge/Laravel%20Octane-Compatible-success?style=flat&logo=laravel)](https://github.com/laravel/octane)

Laravel classes custom route wrapper. Support PHP 8 Attributes and classes route.

Define Laravel routes in different ways using [Class Wrapper Route](#class-wrapper-route) or [Route Attribute](#route-attribute)

Previously known as [jalameta/router](https://github.com/jalameta/jps-router).<br><br>

### TABLE OF CONTENT
Expand Down Expand Up @@ -316,7 +318,6 @@ class DashboardController extends Controller
}
}
```
pretty cool right!. This feature is inspired by [spatie/laravel-route-attribute](https://github.com/spatie/laravel-route-attributes).

#### Available Class Target
```php
Expand Down
4 changes: 2 additions & 2 deletions src/RouteAttributeRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function registerClass(string $className): void
$attributes = $class->getAttributes(RouteAttribute::class, ReflectionAttribute::IS_INSTANCEOF);

$options = collect($attributes)
->map(fn(ReflectionAttribute $attribute) => $attribute->newInstance())
->reduce(function ($carry, RouteAttribute $attribute) {
->map(static fn(ReflectionAttribute $attribute) => $attribute->newInstance())
->reduce(static function ($carry, RouteAttribute $attribute) {
switch (true) {
case $attribute instanceof Name:
$carry['as'] = $attribute->name;
Expand Down
4 changes: 2 additions & 2 deletions src/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function register(): void
__DIR__.'/../config/routes.php', 'routes'
);

$this->app->singleton(RouterFactory::SERVICE_NAME, function () {
return new RouterFactory(fn () => [
$this->app->singleton(RouterFactory::SERVICE_NAME, static function () {
return new RouterFactory(static fn () => [
Container::getInstance()['config'],
Container::getInstance()['router'],
]);
Expand Down
8 changes: 4 additions & 4 deletions tests/PreloadsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function test_preloads_called_when_route_cached(): void
$this->cacheRoute();

$this->assertRegisteredRoutesCount(5);
static::assertTrue($this->app->routesAreCached());
self::assertTrue($this->app->routesAreCached());

static::assertNotNull($this->getRouter()->getBindingCallback('user'));
self::assertNotNull($this->getRouter()->getBindingCallback('user'));
}

public function test_preloads_called_when_route_not_cached(): void
Expand All @@ -36,8 +36,8 @@ public function test_preloads_called_when_route_not_cached(): void
->register();

$this->assertRegisteredRoutesCount(5);
static::assertNotTrue($this->app->routesAreCached());
self::assertNotTrue($this->app->routesAreCached());

static::assertNotNull($this->getRouter()->getBindingCallback('user'));
self::assertNotNull($this->getRouter()->getBindingCallback('user'));
}
}
2 changes: 1 addition & 1 deletion tests/Routes/BinderRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(protected Router $router)

public function bind(): void
{
$this->router->bind('user', function ($value) {
$this->router->bind('user', static function ($value) {
return 'User: ' . $value;
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Routes/SimpleRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function register(): void
{
$this->router->get($this->prefix('foo'), [
'as' => 'foo',
'uses' => fn() => 'bar',
'uses' => static fn() => 'bar',
]);
}
}
10 changes: 5 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function assertRegisteredRoutesCount(int $expectedNumber): self
{
$actualNumber = $this->getRouteCollection()->count();

static::assertSame($expectedNumber, $actualNumber);
self::assertSame($expectedNumber, $actualNumber);

return $this;
}
Expand All @@ -58,7 +58,7 @@ public function assertRouteRegistered(
}

$routeRegistered = collect($this->getRouteCollection()->getRoutes())
->contains(function (Route $route) use ($name, $middleware, $controllerMethod, $controller, $uri, $httpMethod, $domain) {
->contains(static function (Route $route) use ($name, $middleware, $controllerMethod, $controller, $uri, $httpMethod, $domain) {
if (!\in_array(strtoupper($httpMethod), $route->methods, true)) {
return false;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public function assertRouteRegistered(
return true;
});

static::assertTrue($routeRegistered, 'The expected route was not registered');
self::assertTrue($routeRegistered, 'The expected route was not registered');

return $this;
}
Expand All @@ -120,7 +120,7 @@ protected function cacheRoute(): void
$this->app->getCachedRoutesPath(), $content,
);

static::assertTrue(
self::assertTrue(
$files->exists(base_path('bootstrap/cache/routes-v7.php'))
);

Expand All @@ -129,7 +129,7 @@ protected function cacheRoute(): void
}


$this->beforeApplicationDestroyed(function () use ($files) {
$this->beforeApplicationDestroyed(static function () use ($files) {
$files->delete(
base_path('bootstrap/cache/routes-v7.php'),
...$files->glob(base_path('routes/testbench-*.php'))
Expand Down

0 comments on commit 859f6cf

Please sign in to comment.