diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9635d1b..dc17090 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -5,20 +5,25 @@ on: [push] jobs: test: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: [8.3, 8.4] + name: PHP ${{ matrix.php }} steps: - name: Checkout code - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Cache dependencies - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ~/.composer/cache/files - key: dependencies-composer-${{ hashFiles('composer.json') }} + key: dependencies-composer-${{ matrix.php }}-${{ hashFiles('composer.json') }} - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick coverage: none env: diff --git a/.gitignore b/.gitignore index 8f4861d..b70e2c4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ composer.lock vendor coverage .phpunit.result.cache + +#nix dev env +.envrc +.devenv +.direnv \ No newline at end of file diff --git a/composer.json b/composer.json index 7a6856f..5b74b6b 100644 --- a/composer.json +++ b/composer.json @@ -1,92 +1,101 @@ { - "name": "spatie/laravel-blade-x", - "description": "Supercharged Blade components", - "keywords": [ - "spatie", - "blade", - "components", - "html", - "laravel-blade-x" - ], - "homepage": "https://github.com/spatie/laravel-blade-x", - "license": "MIT", - "authors": [ - { - "name": "Sebastian De Deyne", - "email": "sebastian@spatie.be", - "homepage": "https://spatie.be", - "role": "Developer" - }, - { - "name": "Brent Roose", - "email": "brent@spatie.be", - "homepage": "https://spatie.be", - "role": "Developer" - }, - { - "name": "Ruben Van Assche", - "email": "ruben@spatie.be", - "homepage": "https://spatie.be", - "role": "Developer" - }, - { - "name": "Freek Van der Herten", - "email": "freek@spatie.be", - "homepage": "https://spatie.be", - "role": "Developer" - }, - { - "name": "Alex Vanderbist", - "email": "alex@spatie.be", - "homepage": "https://spatie.be", - "role": "Developer" - } - ], - "require": { - "php": "^7.2|^8.1", - "laravel/framework": ">=4.1,<4.3", - "symfony/filesystem": "^6.4" + "name": "spatie/laravel-blade-x", + "description": "Supercharged Blade components", + "keywords": [ + "spatie", + "blade", + "components", + "html", + "laravel-blade-x" + ], + "homepage": "https://github.com/spatie/laravel-blade-x", + "license": "MIT", + "authors": [ + { + "name": "Sebastian De Deyne", + "email": "sebastian@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" }, - "require-dev": { - "anlutro/l4-testing": "dev-master", - "laravel/laravel": "dev-master", - "phpunit/phpunit": "^9.5" + { + "name": "Brent Roose", + "email": "brent@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" }, - "autoload": { - "files": [ - "src/Laravel/helpers.php" - ], - "psr-4": { - "Spatie\\BladeX\\": "src" - } + { + "name": "Ruben Van Assche", + "email": "ruben@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" }, - "autoload-dev": { - "psr-4": { - "Spatie\\BladeX\\Tests\\": "tests" - } + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" }, - "scripts": { - "test": "vendor/bin/phpunit", - "test-coverage": "vendor/bin/phpunit --coverage-html coverage" + { + "name": "Alex Vanderbist", + "email": "alex@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "require": { + "php": "^7.2|^8.1", + "laravel/framework": ">=4.1,<4.3", + "symfony/filesystem": "^6.4" + }, + "require-dev": { + "laravel/laravel": "dev-master", + "phpunit/phpunit": "^9.5", + "rector/rector": "^2.5" + }, + "autoload": { + "files": [ + "src/Laravel/helpers.php" + ], + "psr-4": { + "Spatie\\BladeX\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Spatie\\BladeX\\Tests\\": "tests" + } + }, + "scripts": { + "test": "vendor/bin/phpunit", + "test-coverage": "vendor/bin/phpunit --coverage-html coverage" + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "kylekatarnls/update-helper": true }, - "config": { - "sort-packages": true, - "allow-plugins": { - "kylekatarnls/update-helper": true - } + "audit": { + "ignore": { + "PKSA-8qx3-n5y5-vvnd": "nested array validation with wildcard is not supported in laravel 4.2", + "PKSA-w7xr-vk7n-rstm": "affected only when register_argc_argv is 'on' in php.ini", + "PKSA-3qhw-gzjt-j63j": "affected only laravel 5.5.40 and 5.6.x through 5.6.29", + "PKSA-17kp-jm2n-vxzz": "there is no link() function in Laravel 4.2 Filesystem/Filesystem.php", + "PKSA-7ywf-hktb-jkn9": "JSON nested attribute handling not implemented in 4.2, JSON columns is treated as string in 4.2", + "PKSA-njrm-6dtg-m2pc": "this is only affected newer blade engine such as laravel >5.x because it use hashed parent placeholder and inserted into raw HTML", + "PKSA-nrj3-r2wg-yt8b": "this is only affected when we use 'cookie' driver in session ", + "PKSA-m5cs-t1y6-qpcs": "update or not update still vulnerable, because affected to < 12.61.1", + "PKSA-3r5d-mb8f-1qw9": "update or not update still vulnerable, because affected to < 12.60.0" + } + } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/dicoding-dev/L42x" }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/dicoding-dev/L42x" - }, - { - "type": "vcs", - "url": "https://github.com/dicoding-dev/L42x-app" - }, - { - "type": "vcs", - "url": "https://github.com/dicoding-dev/laravel-testing" - } - ] + { + "type": "vcs", + "url": "https://github.com/dicoding-dev/L42x-app" + } + ] } diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..8340db8 --- /dev/null +++ b/rector.php @@ -0,0 +1,32 @@ +withPhpVersion(80400) + ->withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withRules([ + DynamicClassConstFetchRector::class, + CombineHostPortLdapUriRector::class, + RemoveGetClassGetParentClassNoArgsRector::class, + JsonValidateRector::class, + AddTypeToConstRector::class, + ReadOnlyAnonymousClassRector::class, + AddOverrideAttributeToOverriddenMethodsRector::class, + ExplicitNullableParamTypeRector::class, + AddEscapeArgumentRector::class, + ]); diff --git a/src/BladeXServiceProvider.php b/src/BladeXServiceProvider.php index 7f2f78d..cda476d 100644 --- a/src/BladeXServiceProvider.php +++ b/src/BladeXServiceProvider.php @@ -7,6 +7,7 @@ class BladeXServiceProvider extends ViewServiceProvider { + #[\Override] public function register() { parent::register(); @@ -19,6 +20,7 @@ public function register() $this->registerBladeXCompiler(); } + #[\Override] public function registerFactory() { $this->app->bindShared('view', function($app) { @@ -35,6 +37,7 @@ public function registerFactory() }); } + #[\Override] public function registerBladeEngine($resolver) { $this->app->bindShared('blade.compiler', function($app) diff --git a/src/ComponentDirectory/NamespacedDirectory.php b/src/ComponentDirectory/NamespacedDirectory.php index bdb09a0..0e0e082 100644 --- a/src/ComponentDirectory/NamespacedDirectory.php +++ b/src/ComponentDirectory/NamespacedDirectory.php @@ -32,6 +32,7 @@ public function getAbsoluteDirectory(): string return $viewPath ? "{$absoluteDirectory}/{$viewPath}" : $absoluteDirectory; } + #[\Override] public function getViewName(SplFileInfo $viewFile): string { return "{$this->namespace}::".parent::getViewName($viewFile); diff --git a/src/Laravel/Collection.php b/src/Laravel/Collection.php index bd59620..1bbb981 100644 --- a/src/Laravel/Collection.php +++ b/src/Laravel/Collection.php @@ -7,7 +7,8 @@ class Collection extends L4Collection { - public function filter(Closure $callback = null) + #[\Override] + public function filter(?Closure $callback = null) { if ($callback) { // return new static(Arr::where($this->items, $callback)); @@ -17,6 +18,7 @@ public function filter(Closure $callback = null) return new static(array_filter($this->items)); } + #[\Override] public function implode($value, $glue = null) { $first = $this->first(); @@ -28,6 +30,7 @@ public function implode($value, $glue = null) return implode($value, $this->items); } + #[\Override] public function mapWithKeys(callable $callback) { $result = []; @@ -48,6 +51,7 @@ public function pluck($value, $key = null) return new static(array_pluck($this->items, $value, $key)); } + #[\Override] public function unique($key = null, $strict = false) { $callback = $this->valueRetriever($key); @@ -63,6 +67,7 @@ public function unique($key = null, $strict = false) }); } + #[\Override] public function reject($callback) { $useAsCallable = $this->useAsCallable($callback); @@ -74,11 +79,13 @@ public function reject($callback) }); } + #[\Override] protected function useAsCallable($value) { return ! is_string($value) && is_callable($value); } + #[\Override] protected function valueRetriever($value) { if ($this->useAsCallable($value)) { diff --git a/tests/Features/Registration/TestClasses/SelectViewModel.php b/tests/Features/Registration/TestClasses/SelectViewModel.php index ecc0f41..7edfb89 100644 --- a/tests/Features/Registration/TestClasses/SelectViewModel.php +++ b/tests/Features/Registration/TestClasses/SelectViewModel.php @@ -15,7 +15,7 @@ class SelectViewModel extends ViewModel /** @var string */ private $selected; - public function __construct(string $name, array $options, string $selected = null) + public function __construct(string $name, array $options, ?string $selected = null) { $this->name = $name; diff --git a/tests/Features/ViewModel/TestClasses/SelectFieldViewModel.php b/tests/Features/ViewModel/TestClasses/SelectFieldViewModel.php index 03309e5..0ea7a44 100644 --- a/tests/Features/ViewModel/TestClasses/SelectFieldViewModel.php +++ b/tests/Features/ViewModel/TestClasses/SelectFieldViewModel.php @@ -19,7 +19,7 @@ class SelectFieldViewModel extends ViewModel * @todo $name and $options should not have default value * need to revert back after solving the test problem */ - public function __construct(string $name = '', array $options = [], string $selected = null) + public function __construct(string $name = '', array $options = [], ?string $selected = null) { $this->name = $name; diff --git a/tests/TestCase.php b/tests/TestCase.php index 571332b..01224b6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,10 +11,23 @@ use Spatie\BladeX\Facades\BladeX; use Spatie\BladeX\Tests\SnapshotAssertions\MatchesSnapshots; -abstract class TestCase extends \anlutro\LaravelTesting\PkgAppTestCase +abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase { use MatchesSnapshots; + // ponytail: inlined from anlutro/l4-testing PkgAppTestCase (only the <5.0 branch we use) + public function createApplication(): Application + { + $unitTesting = true; + $testEnvironment = 'testing'; + + $app = new Application(); + $app->bindInstallPaths(require $this->getVendorPath() . '/laravel/laravel/bootstrap/paths.php'); + require Application::getBootstrapFile(); + + return $app; + } + protected function setUp(): void { parent::setUp();