Skip to content

Commit

Permalink
Merge pull request #69 from fetzi/master
Browse files Browse the repository at this point in the history
Add compatibility with Laravel 10 and use Github Actions instead of Travis CI
  • Loading branch information
jenssegers authored Dec 4, 2023
2 parents 22a3700 + fe24e8c commit d965d7b
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 66 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor
composer.lock
.DS_Store
.phpunit.cache/
.phpunit.result.cache
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@
}
],
"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": {
"Jenssegers\\Blade\\": "src/"
}
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"scripts": {
"test": "vendor/bin/phpunit",
"lint": "vendor/bin/pint --test",
"fix": "vendor/bin/pint"
}
}
31 changes: 12 additions & 19 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Default">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="false">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<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.4/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage includeUncoveredFiles="false"/>
<testsuites>
<testsuite name="Default">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
6 changes: 6 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"preset": "laravel",
"exclude": [
"tests/cache"
]
}
26 changes: 9 additions & 17 deletions src/Blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
25 changes: 25 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Jenssegers\Blade;

use Closure;
use Illuminate\Container\Container as BaseContainer;

class Container extends BaseContainer
{
protected array $terminatingCallbacks = [];

public function terminating(Closure $callback)
{
$this->terminatingCallbacks[] = $callback;

return $this;
}

public function terminate()
{
foreach ($this->terminatingCallbacks as $terminatingCallback) {
$terminatingCallback();
}
}
}
10 changes: 5 additions & 5 deletions tests/BladeTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Factory;
use Illuminate\View\View;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\ViewFinderInterface;
use Jenssegers\Blade\Blade;
use PHPUnit\Framework\TestCase;
Expand All @@ -14,7 +14,7 @@ class BladeTest extends TestCase
*/
private $blade;

public function setUp()
protected function setUp(): void
{
$this->blade = new Blade('tests/views', 'tests/cache');

Expand Down Expand Up @@ -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']);
Expand All @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit d965d7b

Please sign in to comment.