Skip to content

Commit

Permalink
Merge pull request #14 from grantholle/laravel-11
Browse files Browse the repository at this point in the history
Add Laravel 11 support
  • Loading branch information
grantholle authored Mar 20, 2024
2 parents fad7a6d + 4bbc51b commit 5df0023
Show file tree
Hide file tree
Showing 24 changed files with 143 additions and 122 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/phpstan.yml

This file was deleted.

9 changes: 6 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.2, 8.1]
laravel: [9.*, 10.*]
php: [8.2, 8.3]
laravel: [9.*, 10.*, 11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
carbon: ^2.63
- laravel: 10.*
- laravel: ^10.15
testbench: 8.*
carbon: ^2.63
- laravel: 11.*
testbench: 9.*
carbon: ^2.63

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
28 changes: 0 additions & 28 deletions .github/workflows/update-changelog.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ phpstan.neon
testbench.yaml
vendor
node_modules
.phpunit.cache/test-results
phpunit.xml.dist.bak
49 changes: 32 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,62 @@
"require": {
"php": "^8.1",
"ext-intl": "*",
"illuminate/contracts": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"illuminate/contracts": "^9.0|^10.0|^11.0",
"illuminate/support": "^9.0|^10.0|^11.0",
"spatie/laravel-package-tools": "^1.14.0",
"stevebauman/location": "^7.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.0",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^7.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"nunomaduro/collision": "^6.0|^7.0|^8.0",
"orchestra/testbench": "^9.0",
"pestphp/pest": "^1.0|^2.0",
"pestphp/pest-plugin-laravel": "^1.0|^2.0",
"spatie/laravel-ray": "^1.26"
},
"autoload": {
"psr-4": {
"GrantHolle\\Timezone\\": "src"
},
"files": ["src/helpers.php"]
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"GrantHolle\\Timezone\\Tests\\": "tests"
"GrantHolle\\Timezone\\Tests\\": "tests",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"post-autoload-dump": [
"@clear",
"@prepare",
"@php ./vendor/bin/testbench package:discover --ansi"
],
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
"format": "vendor/bin/pint",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve"
],
"lint": [
"@php vendor/bin/pint",
"@php vendor/bin/phpstan analyse"
]
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
"pestphp/pest-plugin": true
}
},
"extra": {
Expand Down
58 changes: 21 additions & 37 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="GrantHolle Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="GrantHolle Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function timezones(?string $timezone = null): Collection|string
return $zones->get($timezone);
}

public function toLocal(null|Carbon|CarbonImmutable $date, string $format = null): string|CarbonImmutable
public function toLocal(null|Carbon|CarbonImmutable $date, ?string $format = null): string|CarbonImmutable
{
$date = $date ?? now();

Expand All @@ -56,7 +56,7 @@ public function toLocal(null|Carbon|CarbonImmutable $date, string $format = null
return $converted->format($format);
}

public function toLocalFormatted(null|Carbon|CarbonImmutable $date, string $format = null): string
public function toLocalFormatted(null|Carbon|CarbonImmutable $date, ?string $format = null): string
{
$date = $date ?? now();

Expand Down
4 changes: 2 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ function timezone(): string
* Gets a list of all timezones
* or the formatted name of the given timezone
*/
function timezones(string $timezone = null): Collection|string
function timezones(?string $timezone = null): Collection|string
{
return Timezone::timezones($timezone);
}
}

if (!function_exists('to_local_timezone')) {
function to_local_timezone(null|Carbon\Carbon|CarbonImmutable $date, string $format = null): string
function to_local_timezone(null|Carbon\Carbon|CarbonImmutable $date, ?string $format = null): string
{
return Timezone::toLocalFormatted($date, $format);
}
Expand Down
1 change: 0 additions & 1 deletion tests/Drivers/LocalTestDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class LocalTestDriver extends Driver
{

protected function process(Request $request): Fluent|false
{
return new Fluent([
Expand Down
2 changes: 0 additions & 2 deletions tests/LocalConversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use GrantHolle\Timezone\Facades\Timezone;
use Illuminate\Support\Facades\Config;

uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);

it('can detect user timezone', function (string $timezone) {
expect(timezone())->toEqual($timezone);
})->with([
Expand Down
2 changes: 0 additions & 2 deletions tests/SetTimezoneTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);

beforeEach(function () {
test()->user = seedUser(['timezone' => null]);
});
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
use GrantHolle\Timezone\TimezoneServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Orchestra\Testbench\Attributes\WithMigration;
use Orchestra\Testbench\TestCase as Orchestra;
use Stevebauman\Location\LocationServiceProvider;

#[WithMigration]
class TestCase extends Orchestra
{
public User $user;
Expand All @@ -32,8 +34,8 @@ protected function defineDatabaseMigrations(): void

public function getEnvironmentSetUp($app): void
{
config()->set('database.default', 'testing');
config()->set('location.driver', LocalTestDriver::class);
$app['config']->set('database.default', 'testing');
$app['config']->set('location.driver', LocalTestDriver::class);
}

public function defineRoutes($router)
Expand Down
Empty file added workbench/app/Models/.gitkeep
Empty file.
24 changes: 24 additions & 0 deletions workbench/app/Providers/WorkbenchServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Workbench\App\Providers;

use Illuminate\Support\ServiceProvider;

class WorkbenchServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}

/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}
Empty file added workbench/bootstrap/.gitkeep
Empty file.
19 changes: 19 additions & 0 deletions workbench/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

use function Orchestra\Testbench\default_skeleton_path;

return Application::configure(basePath: $APP_BASE_PATH ?? default_skeleton_path())
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
Empty file.
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions workbench/database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Workbench\Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
}
}
Empty file.
Empty file added workbench/routes/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions workbench/routes/console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;

Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote')->hourly();
7 changes: 7 additions & 0 deletions workbench/routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('welcome');
});

0 comments on commit 5df0023

Please sign in to comment.