Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge inertia-laravel-testing into inertia-laravel #220

Merged
merged 10 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at https://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
/.php_cs.dist export-ignore
/.styleci.yml export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/CHANGELOG.md export-ignore
/CONTRIBUTING.md export-ignore
/README.md export-ignore
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: tests

on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
tests:
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
php:
- 7.2
- 7.3
- 7.4
- 8.0
composerFlags:
- '--prefer-lowest'
- ''

name: PHP ${{ matrix.php }} w/ Composer ${{ matrix.composerFlags }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer update --prefer-dist --no-interaction --no-progress ${{ matrix.composerFlags }}

- name: Execute tests
run: vendor/bin/phpunit --verbose
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
.DS_Store
.env
.phpunit.result.cache
composer.lock
phpunit.xml
/vendor
31 changes: 31 additions & 0 deletions _ide_helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/** @noinspection PhpUndefinedClassInspection */
/** @noinspection PhpFullyQualifiedNameUsageInspection */
/** @noinspection PhpUnusedAliasInspection */

namespace Illuminate\Testing {

/**
* @see \Inertia\Testing\TestResponseMacros
*
* @method self assertInertia(\Closure $assert = null)
*/
class TestResponse
{
//
}
}

namespace Illuminate\Foundation\Testing {

/**
* @see \Inertia\Testing\TestResponseMacros
*
* @method self assertInertia(\Closure $assert = null)
*/
class TestResponse
{
//
}
}
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
}
},
"require": {
"php": "^7.2|^8.0",
"ext-json": "*",
"laravel/framework": "^5.4|^6.0|^7.0|^8.0"
},
"require-dev": {
"orchestra/testbench": "~3.0"
"roave/security-advisories": "dev-master",
"orchestra/testbench": "^4.0|^5.0|^6.0",
"phpunit/phpunit": "^8.0|^9.0"
},
"extra": {
"laravel": {
Expand Down
38 changes: 38 additions & 0 deletions config/inertia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Testing
|--------------------------------------------------------------------------
|
| The values described here are used to locate Inertia components on the
| filesystem. For instance, when using `assertInertia`, the assertion
| attempts to locate the component as a file relative to any of the
| paths AND with any of the extensions specified here.
|
*/

'testing' => [

'ensure_pages_exist' => true,

'page_paths' => [

resource_path('js/Pages'),

],

'page_extensions' => [

'js',
'svelte',
'ts',
'vue',

],

],

];
20 changes: 0 additions & 20 deletions phpunit.xml

This file was deleted.

23 changes: 23 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>

15 changes: 15 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Inertia.js Laravel Adapter

<p align="left">
<a href="https://github.com/inertiajs/inertia-laravel/releases">
<img src="https://img.shields.io/github/release/inertiajs/inertia-laravel.svg?style=flat-square" alt="Latest Version">
</a>
<a href="https://github.com/inertiajs/inertia-laravel/actions?query=workflow%3Atests+branch%3Amaster">
<img src="https://img.shields.io/github/workflow/status/inertiajs/inertia-laravel/tests/master.svg?style=flat-square" alt="Build Status">
</a>
<a href="https://styleci.io/repos/174395905"><img src="https://styleci.io/repos/174395905/shield" alt="StyleCI"></a>
<a href="https://packagist.org/packages/inertiajs/inertia-laravel">
<img src="https://img.shields.io/packagist/dt/inertiajs/inertia-laravel.svg?style=flat-square" alt="Total Downloads">
</a>
</p>

---

Visit [inertiajs.com](https://inertiajs.com/) to learn more.
4 changes: 2 additions & 2 deletions src/Inertia.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* @method static array getShared($key = null)
* @method static void version($version)
* @method static int|string getVersion()
* @method static \Inertia\Response render($component, $props = [])
* @method static Response render($component, $props = [])
* @method static \Illuminate\Http\Response location($url)
* @method static \Inertia\LazyProp lazy(callable $callback)
* @method static LazyProp lazy(callable $callback)
*
* @see \Inertia\ResponseFactory
*/
Expand Down
41 changes: 41 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,34 @@

namespace Inertia;

use Illuminate\Foundation\Testing\TestResponse as LegacyTestResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Illuminate\Testing\TestResponse;
use Illuminate\View\FileViewFinder;
use Inertia\Testing\TestResponseMacros;
use LogicException;

class ServiceProvider extends BaseServiceProvider
{
public function register()
{
$this->app->singleton(ResponseFactory::class);

$this->mergeConfigFrom(
__DIR__.'/../config/inertia.php',
'inertia'
);

$this->app->bind('inertia.testing.view-finder', function ($app) {
return new FileViewFinder(
$app['files'],
$app['config']->get('inertia.testing.page_paths'),
$app['config']->get('inertia.testing.page_extensions')
);
});
}

public function boot()
Expand All @@ -20,6 +38,11 @@ public function boot()
$this->registerConsoleCommands();
$this->registerRequestMacro();
$this->registerRouterMacro();
$this->registerTestingMacros();

$this->publishes([
__DIR__.'/../config/inertia.php' => config_path('inertia.php'),
]);
}

protected function registerBladeDirective()
Expand Down Expand Up @@ -55,4 +78,22 @@ protected function registerRouterMacro()
->defaults('props', $props);
});
}

protected function registerTestingMacros()
{
if (class_exists(TestResponse::class)) {
TestResponse::mixin(new TestResponseMacros());

return;
}

// Laravel <= 6.0
if (class_exists(LegacyTestResponse::class)) {
LegacyTestResponse::mixin(new TestResponseMacros());

return;
}

throw new LogicException('Could not detect TestResponse class.');
}
}
Loading