Skip to content

Commit

Permalink
Merge pull request #7 from lbausch/develop
Browse files Browse the repository at this point in the history
Version 0.5.0
  • Loading branch information
lbausch authored Oct 22, 2023
2 parents f0be5fa + 577d50d commit ed3e2ba
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 56 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
pull_request:
schedule:
- cron: '0 0 * * *'
workflow_dispatch: {}

jobs:
tests:
Expand All @@ -22,17 +23,17 @@ jobs:
strategy:
fail-fast: true
matrix:
php: ['7.3', '7.4', '8.0', '8.1']
php: ['8.1', '8.2']
stability: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
Expand All @@ -48,13 +49,13 @@ jobs:
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit --verbose --coverage-clover coverage.xml
run: vendor/bin/phpunit --coverage-clover coverage.xml
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
DB_USERNAME: root

- name: Upload coverage to Codecov
if: ${{ github.ref == 'refs/heads/master' && matrix.php == '8.0' && matrix.stability == 'prefer-stable' }}
uses: codecov/codecov-action@v1
if: ${{ github.ref == 'refs/heads/master' && matrix.php == '8.1' && matrix.stability == 'prefer-stable' }}
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/composer.lock
/vendor/
/.phpunit.cache/
/.phpunit.result.cache
5 changes: 3 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('bootstrap')
->exclude('resources')
->exclude('vendor')
->in(__DIR__)
;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'global_namespace_import' => [
'import_classes' => true,
],
])
->setFinder($finder)
;
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ It accesses Flarum's session cookie and reads the session data from the session
Based on the user information in the Flarum user database an user in the Laravel application is created / updated and logged in.

## Requirements
+ PHP 7.3+
+ Laravel 8
+ PHP 8.1+
+ Laravel 10
+ Working installation of Flarum in the same filesystem as the Laravel application, so Flarum's session files can be read
+ Flarum and Laravel need to share the same domain / subdomain, so Flarum's session cookie can be accessed

Expand All @@ -38,13 +38,13 @@ composer require lbausch/flarum-laravel-session
Register the `\Bausch\FlarumLaravelSession\FlarumSessionMiddleware` middleware in `app/Http/Kernel.php`:
```php
/**
* The application's route middleware.
* The application's middleware aliases.
*
* These middleware may be assigned to groups or used individually.
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
*
* @var array
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
protected $middlewareAliases = [
// ...
'flarum' => \Bausch\FlarumLaravelSession\FlarumSessionMiddleware::class,
// ...
Expand Down Expand Up @@ -84,7 +84,7 @@ To avoid Laravel from trying to encrypt the Flarum session cookie, add the follo
/**
* The names of the cookies that should not be encrypted.
*
* @var array
* @var array<int, string>
*/
protected $except = [
'flarum_session',
Expand Down Expand Up @@ -121,10 +121,8 @@ class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
public function register(): void
{
//
}
Expand All @@ -134,7 +132,7 @@ class AppServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot()
public function boot(): void
{
FlarumLaravelSession::handleIdentifiedUser(YourCustomHandler::class);
}
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
}
],
"require": {
"php": "^7.3|^8.0",
"illuminate/auth": "^8.65|^9.0",
"illuminate/filesystem": "^8.65|^9.0",
"illuminate/http": "^8.65|^9.0",
"illuminate/session": "^8.65|^9.0",
"illuminate/support": "^8.65|^9.0"
"php": "^8.1",
"illuminate/auth": "^10.0",
"illuminate/filesystem": "^10.0",
"illuminate/http": "^10.0",
"illuminate/session": "^10.0",
"illuminate/support": "^10.0"
},
"require-dev": {
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "9.*"
"orchestra/testbench": "^8.13",
"phpunit/phpunit": "^10.4"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 7 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
testdox="true"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" testdox="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Flarum Laravel Session Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<coverage/>
<php>
<env name="DB_CONNECTION" value="testing"/>
</php>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
4 changes: 0 additions & 4 deletions src/Actions/HandleIdentifiedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public function __invoke(object $flarum_user, Request $request, Closure $next)

/**
* Create or update User.
*
* @param \Illuminate\Foundation\Auth\User $user
*/
protected function createOrUpdateUser(?User $user, object $flarum_user): User
{
Expand All @@ -52,8 +50,6 @@ protected function createOrUpdateUser(?User $user, object $flarum_user): User

/**
* Update attributes.
*
* @param \Illuminate\Foundation\Auth\User $user
*/
protected function updateAttributes(?User $user, object $flarum_user): User
{
Expand Down
2 changes: 0 additions & 2 deletions src/Contracts/FlarumUserIdentified.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ interface FlarumUserIdentified
{
/**
* Handle an authenticated Flarum user.
*
* @return mixed
*/
public function __invoke(object $flarum_user, Request $request, Closure $next);
}
2 changes: 0 additions & 2 deletions src/FlarumSessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class FlarumSessionMiddleware
{
/**
* Handle an incoming request.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/FlarumMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Illuminate\Support\Str;
use Symfony\Component\HttpKernel\Exception\HttpException;

final class MiddlewareTest extends TestCase
final class FlarumMiddlewareTest extends TestCase
{
public function testExceptionIsThrownIfSessionCouldNotBeFound()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('flarum_id');
$table->string('username');
$table->string('nickname')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
Expand All @@ -27,11 +25,9 @@ public function up()

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('users');
}
}
};

0 comments on commit ed3e2ba

Please sign in to comment.