Skip to content

Commit

Permalink
Merge pull request #61 from laravel-frontend-presets/livewire-v2
Browse files Browse the repository at this point in the history
chore(add support for Livewire v2)
  • Loading branch information
ryangjchandler authored Sep 10, 2020
2 parents 47d8c00 + fa1af0d commit 124f9d5
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 69 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/phpunit.xml.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</include>
</coverage>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
16 changes: 11 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.2, 7.3, 7.4]
laravel: [^7.0]
php: [7.3, 7.4]
laravel: [^8.0]
name: P${{ matrix.php }} - L${{ matrix.laravel }}
steps:
- name: Checkout code
Expand All @@ -27,20 +27,26 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite
coverage: none
- name: Create Laravel app
run: composer create-project laravel/laravel=${{ matrix.laravel }} ../app --prefer-dist
- name: Install dependencies
run: |
cd ../app
composer require livewire/livewire
composer require livewire/livewire:^2.0
composer config repositories.local '{"type": "path", "url": "../tall"}' --file composer.json
composer require laravel-frontend-presets/tall dev-master
composer require laravel-frontend-presets/tall:@dev
- name: Install preset
run: |
cd ../app
php artisan ui tall --auth
- name: Overwrite configuration
run: |
cd ../app
rm phpunit.xml
cp ../tall/.github/workflows/phpunit.xml.stub ./phpunit.xml
- name: Execute tests
run: |
cd ../app
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ Some notable features of this package include:
- Tailwind-powered pagination views
- The [Tailwind UI](https://tailwindui.com) and Tailwind's [Custom Forms](https://github.com/tailwindcss/custom-forms) extensions available out-of-the-box

> **Note**: If you're looking for an application boilerplate that supports the TALL stack, you should check out [Laravel Jetstream](https://github.com/laravel/jetstream). It comes with authentication scaffolding, account management, teams support.
## Installation

This preset is intended to be installed into a fresh Laravel application. Follow [Laravel's installation instructions](https://laravel.com/docs/7.x/installation) to ensure you have a working environment before continuing.
This preset is intended to be installed into a fresh Laravel application. Follow [Laravel's installation instructions](https://laravel.com/docs/8.x/installation) to ensure you have a working environment before continuing.

### Installation (without auth)

Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
},
{
"name": "Ryan Chandler",
"email": "[email protected]"
"email": "[email protected]"
}
],
"require": {
"php": "^7.2.5",
"laravel/ui": "^2.0"
"laravel/ui": "^2.0",
"illuminate/support": "^8.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/TallPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TallPreset extends Preset
const NPM_PACKAGES_TO_ADD = [
'@tailwindcss/ui' => '^0.4',
'@tailwindcss/typography' => '^0.2',
'alpinejs' => '^2.0',
'alpinejs' => '^2.6',
'laravel-mix-tailwind' => '^0.1.0',
'tailwindcss' => '^1.5',
];
Expand Down
4 changes: 2 additions & 2 deletions stubs/auth/app/Http/Livewire/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function authenticate()
return;
}

redirect()->intended(route('home'));
return redirect()->intended(route('home'));
}

public function render()
{
return view('livewire.auth.login');
return view('livewire.auth.login')->extends('layouts.auth');
}
}
4 changes: 2 additions & 2 deletions stubs/auth/app/Http/Livewire/Auth/Passwords/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public function confirm()

session()->put('auth.password_confirmed_at', time());

redirect()->intended(route('home'));
return redirect()->intended(route('home'));
}

public function render()
{
return view('livewire.auth.passwords.confirm');
return view('livewire.auth.passwords.confirm')->extends('layouts.auth');
}
}
2 changes: 1 addition & 1 deletion stubs/auth/app/Http/Livewire/Auth/Passwords/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public function broker()

public function render()
{
return view('livewire.auth.passwords.email');
return view('livewire.auth.passwords.email')->extends('layouts.auth');
}
}
2 changes: 1 addition & 1 deletion stubs/auth/app/Http/Livewire/Auth/Passwords/Reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ protected function guard()

public function render()
{
return view('livewire.auth.passwords.reset');
return view('livewire.auth.passwords.reset')->extends('layouts.auth');
}
}
6 changes: 3 additions & 3 deletions stubs/auth/app/Http/Livewire/Auth/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Livewire\Auth;

use App\Providers\RouteServiceProvider;
use App\User;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Auth\Events\Registered;
Expand Down Expand Up @@ -41,11 +41,11 @@ public function register()

Auth::login($user, true);

redirect()->intended(route('home'));
return redirect()->intended(route('home'));
}

public function render()
{
return view('livewire.auth.register');
return view('livewire.auth.register')->extends('layouts.auth');
}
}
2 changes: 1 addition & 1 deletion stubs/auth/app/Http/Livewire/Auth/Verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public function resend()

public function render()
{
return view('livewire.auth.verify');
return view('livewire.auth.verify')->extends('layouts.auth');
}
}
4 changes: 4 additions & 0 deletions stubs/auth/resources/views/layouts/auth.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
@section('body')
<div class="flex flex-col justify-center min-h-screen py-12 bg-gray-50 sm:px-6 lg:px-8">
@yield('content')

@isset($slot)
{{ $slot }}
@endisset
</div>
@endsection
46 changes: 26 additions & 20 deletions stubs/auth/routes/web.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?php

use App\Http\Controllers\Auth\EmailVerificationController;
use App\Http\Controllers\Auth\LogoutController;
use App\Http\Livewire\Auth\Login;
use App\Http\Livewire\Auth\Passwords\Confirm;
use App\Http\Livewire\Auth\Passwords\Email;
use App\Http\Livewire\Auth\Passwords\Reset;
use App\Http\Livewire\Auth\Register;
use App\Http\Livewire\Auth\Verify;
use Illuminate\Support\Facades\Route;

/*
Expand All @@ -15,36 +23,34 @@

Route::view('/', 'welcome')->name('home');

Route::layout('layouts.auth')->group(function () {
Route::middleware('guest')->group(function () {
Route::livewire('login', 'auth.login')
->name('login');
Route::middleware('guest')->group(function () {
Route::get('login', Login::class)
->name('login');

Route::livewire('register', 'auth.register')
->name('register');
});
Route::get('register', Register::class)
->name('register');
});

Route::livewire('password/reset', 'auth.passwords.email')
->name('password.request');
Route::get('password/reset', Email::class)
->name('password.request');

Route::livewire('password/reset/{token}', 'auth.passwords.reset')
->name('password.reset');
Route::get('password/reset/{token}', Reset::class)
->name('password.reset');

Route::middleware('auth')->group(function () {
Route::livewire('email/verify', 'auth.verify')
->middleware('throttle:6,1')
->name('verification.notice');
Route::middleware('auth')->group(function () {
Route::get('email/verify', Verify::class)
->middleware('throttle:6,1')
->name('verification.notice');

Route::livewire('password/confirm', 'auth.passwords.confirm')
->name('password.confirm');
});
Route::get('password/confirm', Confirm::class)
->name('password.confirm');
});

Route::middleware('auth')->group(function () {
Route::get('email/verify/{id}/{hash}', 'Auth\EmailVerificationController')
Route::get('email/verify/{id}/{hash}', EmailVerificationController::class)
->middleware('signed')
->name('verification.verify');

Route::post('logout', 'Auth\LogoutController')
Route::post('logout', LogoutController::class)
->name('logout');
});
16 changes: 8 additions & 8 deletions stubs/auth/tests/Feature/Auth/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Feature\Auth;

use App\User;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
Expand All @@ -24,7 +24,7 @@ public function can_view_login_page()
/** @test */
public function is_redirected_if_already_logged_in()
{
$user = factory(User::class)->create();
$user = User::factory()->create();

$this->be($user);

Expand All @@ -35,7 +35,7 @@ public function is_redirected_if_already_logged_in()
/** @test */
public function a_user_can_login()
{
$user = factory(User::class)->create(['password' => Hash::make('password')]);
$user = User::factory()->create(['password' => Hash::make('password')]);

Livewire::test('auth.login')
->set('email', $user->email)
Expand All @@ -48,7 +48,7 @@ public function a_user_can_login()
/** @test */
public function is_redirected_to_the_home_page_after_login()
{
$user = factory(User::class)->create(['password' => Hash::make('password')]);
$user = User::factory()->create(['password' => Hash::make('password')]);

Livewire::test('auth.login')
->set('email', $user->email)
Expand All @@ -60,7 +60,7 @@ public function is_redirected_to_the_home_page_after_login()
/** @test */
public function email_is_required()
{
$user = factory(User::class)->create(['password' => Hash::make('password')]);
$user = User::factory()->create(['password' => Hash::make('password')]);

Livewire::test('auth.login')
->set('password', 'password')
Expand All @@ -71,7 +71,7 @@ public function email_is_required()
/** @test */
public function email_must_be_valid_email()
{
$user = factory(User::class)->create(['password' => Hash::make('password')]);
$user = User::factory()->create(['password' => Hash::make('password')]);

Livewire::test('auth.login')
->set('email', 'invalid-email')
Expand All @@ -83,7 +83,7 @@ public function email_must_be_valid_email()
/** @test */
public function password_is_required()
{
$user = factory(User::class)->create(['password' => Hash::make('password')]);
$user = User::factory()->create(['password' => Hash::make('password')]);

Livewire::test('auth.login')
->set('email', $user->email)
Expand All @@ -94,7 +94,7 @@ public function password_is_required()
/** @test */
public function bad_login_attempt_shows_message()
{
$user = factory(User::class)->create();
$user = User::factory()->create();

Livewire::test('auth.login')
->set('email', $user->email)
Expand Down
4 changes: 2 additions & 2 deletions stubs/auth/tests/Feature/Auth/LogoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Feature\Auth;

use App\User;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Tests\TestCase;
Expand All @@ -14,7 +14,7 @@ class LogoutTest extends TestCase
/** @test */
public function an_authenticated_user_can_log_out()
{
$user = factory(User::class)->create();
$user = User::factory()->create();
$this->be($user);

$this->post(route('logout'))
Expand Down
8 changes: 4 additions & 4 deletions stubs/auth/tests/Feature/Auth/Passwords/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Feature\Auth\Passwords;

use App\User;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Route;
Expand All @@ -25,7 +25,7 @@ protected function setUp(): void
/** @test */
public function a_user_must_confirm_their_password_before_visiting_a_protected_page()
{
$user = factory(User::class)->create();
$user = User::factory()->create();
$this->be($user);

$this->get('/must-be-confirmed')
Expand All @@ -47,7 +47,7 @@ public function a_user_must_enter_a_password_to_confirm_it()
/** @test */
public function a_user_must_enter_their_own_password_to_confirm_it()
{
$user = factory(User::class)->create([
$user = User::factory()->create([
'password' => Hash::make('password'),
]);

Expand All @@ -60,7 +60,7 @@ public function a_user_must_enter_their_own_password_to_confirm_it()
/** @test */
public function a_user_who_confirms_their_password_will_get_redirected()
{
$user = factory(User::class)->create([
$user = User::factory()->create([
'password' => Hash::make('password'),
]);

Expand Down
Loading

0 comments on commit 124f9d5

Please sign in to comment.