diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..fdb3fcb --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,33 @@ +name: Tests + +on: ['push', 'pull_request'] + +jobs: + ci: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + php: ['8.1', '8.2', '8.3'] + + name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none + + - name: Install PHP dependencies + run: composer update --prefer-stable --no-interaction --no-progress + + - name: Unit Tests + run: composer test + + - name: Source Linter + run: composer lint \ No newline at end of file diff --git a/.gitignore b/.gitignore index fc7ea17..790abfd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /vendor composer.lock .DS_Store +.phpunit.cache/ +.phpunit.result.cache \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 799e576..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: php - -php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 - -sudo: false - -before_script: - - travis_retry composer self-update - - travis_retry composer install --dev --no-interaction - -script: - - mkdir -p build/logs - - ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml - -after_success: - - php vendor/bin/coveralls -v diff --git a/composer.json b/composer.json index 2e5175c..dd6437c 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,13 @@ } ], "require": { - "php": ">=7.0", - "illuminate/view": "^5.5|^6.0|^7.0|^8.0" + "php": ">=8.1", + "illuminate/view": "^9.0|^10.0", + "illuminate/config": "^9.0|^10.0" }, "require-dev": { - "phpunit/phpunit": "^6.0|^7.0", - "satooshi/php-coveralls": "^1.0" + "phpunit/phpunit": "^10.0", + "laravel/pint": "^1.13" }, "autoload": { "psr-4": { @@ -23,5 +24,10 @@ } }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "scripts": { + "test": "vendor/bin/phpunit", + "lint": "vendor/bin/pint --test", + "fix": "vendor/bin/pint" + } } diff --git a/phpunit.xml b/phpunit.xml index f062023..fcc2c8b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,21 +1,14 @@ - - - - ./tests/ - - - - - src/ - - + + + + + ./tests/ + + + + + src/ + + diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..362cf29 --- /dev/null +++ b/pint.json @@ -0,0 +1,6 @@ +{ + "preset": "laravel", + "exclude": [ + "tests/cache" + ] +} \ No newline at end of file diff --git a/src/Blade.php b/src/Blade.php index 00f87e9..be0c996 100644 --- a/src/Blade.php +++ b/src/Blade.php @@ -2,7 +2,7 @@ namespace Jenssegers\Blade; -use Illuminate\Container\Container; +use Illuminate\Config\Repository; use Illuminate\Contracts\Container\Container as ContainerInterface; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory as FactoryContract; @@ -61,7 +61,7 @@ public function directive(string $name, callable $handler) { $this->compiler->directive($name, $handler); } - + public function if($name, callable $callback) { $this->compiler->if($name, $callback); @@ -113,21 +113,13 @@ public function __call(string $method, array $params) protected function setupContainer(array $viewPaths, string $cachePath) { - $this->container->bindIf('files', function () { - return new Filesystem; - }, true); - - $this->container->bindIf('events', function () { - return new Dispatcher; - }, true); - - $this->container->bindIf('config', function () use ($viewPaths, $cachePath) { - return [ - 'view.paths' => $viewPaths, - 'view.compiled' => $cachePath, - ]; - }, true); - + $this->container->bindIf('files', fn () => new Filesystem); + $this->container->bindIf('events', fn () => new Dispatcher); + $this->container->bindIf('config', fn () => new Repository([ + 'view.paths' => $viewPaths, + 'view.compiled' => $cachePath, + ])); + Facade::setFacadeApplication($this->container); } } diff --git a/src/Container.php b/src/Container.php new file mode 100644 index 0000000..453a8f7 --- /dev/null +++ b/src/Container.php @@ -0,0 +1,25 @@ +terminatingCallbacks[] = $callback; + + return $this; + } + + public function terminate() + { + foreach ($this->terminatingCallbacks as $terminatingCallback) { + $terminatingCallback(); + } + } +} diff --git a/tests/BladeTest.php b/tests/BladeTest.php index a8f7e27..6748720 100644 --- a/tests/BladeTest.php +++ b/tests/BladeTest.php @@ -1,8 +1,8 @@ blade = new Blade('tests/views', 'tests/cache'); @@ -72,7 +72,7 @@ public function testShare() public function testComposer() { $this->blade->composer('variables', function (View $view) { - $view->with('name', 'John Doe and ' . $view->offsetGet('name')); + $view->with('name', 'John Doe and '.$view->offsetGet('name')); }); $output = $this->blade->make('variables', ['name' => 'Jane Doe']); @@ -85,7 +85,7 @@ public function testCreator() $view->with('name', 'John Doe'); }); $this->blade->composer('variables', function (View $view) { - $view->with('name', 'Jane Doe and ' . $view->offsetGet('name')); + $view->with('name', 'Jane Doe and '.$view->offsetGet('name')); }); $output = $this->blade->make('variables'); @@ -166,7 +166,7 @@ public function testOther() private function expected(string $file): string { - $file_path = __DIR__ . '/expected/' . $file . '.html'; + $file_path = __DIR__.'/expected/'.$file.'.html'; return file_get_contents($file_path); }