Skip to content

Commit

Permalink
Merge pull request #536 from driesvints/fix-matrix-build
Browse files Browse the repository at this point in the history
Fix matrix build and Laravel 7 support
  • Loading branch information
calebporzio committed Jan 22, 2020
2 parents 208051e + 91fb532 commit b501bd3
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 115 deletions.
39 changes: 35 additions & 4 deletions .github/workflows/test.yml
Expand Up @@ -14,9 +14,31 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.2, 7.3, 7.4]
laravel: [5.6.*, 5.7.*, 5.8.*, 6.*]
php: [7.1, 7.2, 7.3, 7.4]
laravel: [5.6.*, 5.7.*, 5.8.*, 6.*, 7.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 5.6.*
testbench: 3.6.*
- laravel: 5.7.*
testbench: 3.7.*
- laravel: 5.8.*
testbench: 3.8.*
- laravel: 6.*
testbench: 4.*
- laravel: 7.*
testbench: 5.*
exclude:
- php: 7.1
laravel: 6.*
- php: 7.1
laravel: 7.*
- php: 7.4
laravel: 5.6.*
- php: 7.4
laravel: 5.7.*
- php: 7.4
laravel: 5.8.*

name: PHP:${{ matrix.php }} / Laravel:${{ matrix.laravel }}(${{ matrix.dependency-version }})

Expand All @@ -30,8 +52,17 @@ jobs:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Install
run: composer install --no-interaction --no-suggest
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --dev
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Run Tests
run: vendor/bin/phpunit
43 changes: 25 additions & 18 deletions composer.json
Expand Up @@ -9,20 +9,18 @@
}
],
"require": {
"illuminate/database": "^5.6|^6.0",
"illuminate/support": "^5.6|^6.0",
"illuminate/validation": "^5.6|^6.0",
"php": "^7.1.3",
"illuminate/database": "~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0",
"illuminate/support": "~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0",
"illuminate/validation": "~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0",
"symfony/http-kernel": "^4.0|^5.0"
},
"extra": {
"laravel": {
"providers": [
"Livewire\\LivewireServiceProvider"
],
"aliases": {
"Livewire": "Livewire\\Livewire"
}
}
"require-dev": {
"laravel/framework": "~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0",
"mockery/mockery": "^1.3.1",
"orchestra/testbench": "~3.6.0|~3.7.0|~3.8.0|^4.0|^5.0",
"phpunit/phpunit": "^7.5.15|^8.4|^9.0",
"psy/psysh": "@stable"
},
"autoload": {
"psr-4": {
Expand All @@ -35,10 +33,19 @@
"App\\": "vendor/orchestra/testbench-core/laravel/app"
}
},
"require-dev": {
"phpunit/phpunit": "^8.3",
"laravel/framework": "^5.6|^6.0",
"orchestra/testbench": "~4.0",
"psy/psysh": "@stable"
}
"extra": {
"laravel": {
"providers": [
"Livewire\\LivewireServiceProvider"
],
"aliases": {
"Livewire": "Livewire\\Livewire"
}
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
3 changes: 0 additions & 3 deletions src/Commands/ComponentParser.php
Expand Up @@ -5,12 +5,9 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;
use Illuminate\Console\DetectsApplicationNamespace;

class ComponentParser
{
use DetectsApplicationNamespace;

protected $appPath;
protected $viewPath;
protected $component;
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/FileManipulationCommand.php
Expand Up @@ -5,12 +5,9 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Livewire\LivewireComponentsFinder;
use Illuminate\Console\DetectsApplicationNamespace;

class FileManipulationCommand extends Command
{
use DetectsApplicationNamespace;

protected $parser;

protected function ensureDirectoryExists($path)
Expand Down
68 changes: 68 additions & 0 deletions src/CompilerEngine.php
@@ -0,0 +1,68 @@
<?php

namespace Livewire;

use Exception;
use Illuminate\Foundation\Application;
use Illuminate\View\Engines\CompilerEngine as LaravelCompilerEngine;
use Illuminate\View\Engines\PhpEngine;
use Livewire\Exceptions\BypassViewHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;

if (Application::VERSION === '7.x-dev' || version_compare(Application::VERSION, '7.0', '>=')) {
class CompilerEngine extends LaravelCompilerEngine
{
// Errors thrown while a view is rendering are caught by the Blade
// compiler and wrapped in an "ErrorException". This makes Livewire errors
// harder to read, AND causes issues like `abort(404)` not actually working.
protected function handleViewException(Throwable $e, $obLevel)
{
$uses = array_flip(class_uses_recursive($e));

if (
// Don't wrap "abort(404)".
$e instanceof NotFoundHttpException
// Don't wrap "abort(500)".
|| $e instanceof HttpException
// Don't wrap most Livewire exceptions.
|| isset($uses[BypassViewHandler::class])
) {
// This is because there is no "parent::parent::".
PhpEngine::handleViewException($e, $obLevel);

return;
}

parent::handleViewException($e, $obLevel);
}
}
} else {
class CompilerEngine extends LaravelCompilerEngine
{
// Errors thrown while a view is rendering are caught by the Blade
// compiler and wrapped in an "ErrorException". This makes Livewire errors
// harder to read, AND causes issues like `abort(404)` not actually working.
protected function handleViewException(Exception $e, $obLevel)
{
$uses = array_flip(class_uses_recursive($e));

if (
// Don't wrap "abort(404)".
$e instanceof NotFoundHttpException
// Don't wrap "abort(500)".
|| $e instanceof HttpException
// Don't wrap most Livewire exceptions.
|| isset($uses[BypassViewHandler::class])
) {
// This is because there is no "parent::parent::".
PhpEngine::handleViewException($e, $obLevel);

return;
}

parent::handleViewException($e, $obLevel);
}
}
}
6 changes: 5 additions & 1 deletion src/DataCaster.php
Expand Up @@ -61,7 +61,11 @@ public function getCasters()
return \Carbon\Carbon::parse($value);
},
'uncast' => function ($value) {
return $value->toString();
if (method_exists($value, 'toString')) {
return $value->toString();
}

return $value->__toString();
},
],
'collection' => [
Expand Down
14 changes: 11 additions & 3 deletions src/LivewireServiceProvider.php
Expand Up @@ -2,6 +2,7 @@

namespace Livewire;

use Illuminate\Foundation\Application;
use Illuminate\Routing\Route;
use Illuminate\Routing\Router;
use Livewire\Macros\RouteMacros;
Expand All @@ -15,6 +16,7 @@
use Illuminate\Foundation\Http\Middleware\TrimStrings;
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
use Illuminate\Foundation\Testing\TestResponse;
use Illuminate\Testing\TestResponse as Laravel7TestResponse;
use Livewire\Commands\{
ComponentParser,
CopyCommand,
Expand Down Expand Up @@ -124,17 +126,23 @@ public function registerCommands()

public function registerTestMacros()
{
TestResponse::macro('assertSeeLivewire', function ($component) {
$macro = function ($component) {
$escapedComponentName = trim(htmlspecialchars(json_encode(['name' => $component])), '{}');

\Illuminate\Foundation\Testing\Assert::assertStringContainsString(
\PHPUnit\Framework\Assert::assertStringContainsString(
(string) $escapedComponentName,
$this->getContent(),
'Cannot find Livewire component ['.$component.'] rendered on page.'
);

return $this;
});
};

if (Application::VERSION === '7.x-dev' || version_compare(Application::VERSION, '7.0', '>=')) {
Laravel7TestResponse::macro('assertSeeLivewire', $macro);
} else {
TestResponse::macro('assertSeeLivewire', $macro);
}
}

public function registerRouteMacros()
Expand Down
29 changes: 0 additions & 29 deletions src/LivewireViewCompilerEngine.php
Expand Up @@ -4,12 +4,7 @@

use Exception;
use Throwable;
use Illuminate\View\Engines\PhpEngine;
use Livewire\Exceptions\BypassViewHandler;
use Illuminate\View\Engines\CompilerEngine;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class LivewireViewCompilerEngine extends CompilerEngine
{
Expand Down Expand Up @@ -82,28 +77,4 @@ public function removeLivewireDirectivesFromCompiler()
{
$this->exposedCompiler->setProperty('customDirectives', $this->tmpCustomDirectives);
}

// Errors thrown while a view is rendering are caught by the Blade
// compiler and wrapped in an "ErrorException". This makes Livewire errors
// harder to read, AND causes issues like `abort(404)` not actually working.
protected function handleViewException(Exception $e, $obLevel)
{
$uses = array_flip(class_uses_recursive($e));

if (
// Don't wrap "abort(404)".
$e instanceof NotFoundHttpException
// Don't wrap "abort(500)".
|| $e instanceof HttpException
// Don't wrap most Livewire exceptions.
|| isset($uses[BypassViewHandler::class])
) {
// This is because there is no "parent::parent::".
PhpEngine::handleViewException($e, $obLevel);

return;
}

parent::handleViewException($e, $obLevel);
}
}
2 changes: 1 addition & 1 deletion src/Testing/Concerns/MakesAssertions.php
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\MessageBag;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\Assert as PHPUnit;
use PHPUnit\Framework\Assert as PHPUnit;

trait MakesAssertions
{
Expand Down

0 comments on commit b501bd3

Please sign in to comment.