Skip to content

Commit

Permalink
Merge pull request #9 from enricodelazzari/laravel-11
Browse files Browse the repository at this point in the history
  • Loading branch information
enricodelazzari authored Apr 19, 2024
2 parents 7396e55 + 9e8c330 commit 7456d5a
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
coverage: none

- name: Install composer dependencies
Expand Down
18 changes: 8 additions & 10 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.3, 8.2, 8.1, 8.0]
laravel: [10.*, 9.*]
stability: [prefer-lowest, prefer-stable]
php: [8.3, 8.2, 8.1]
laravel: [11.*, 10.*,]
stability: [prefer-stable] #prefer-lowest,
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
carbon: ^2.63
- laravel: 9.*
testbench: 7.*
carbon: ^2.63
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1

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

Expand All @@ -47,7 +45,7 @@ jobs:
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ testbench.yaml
vendor
node_modules
.php-cs-fixer.cache
.phpunit.cache
.phpunit.cache/test-results
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 MAIZE SRL <[email protected]>
Copyright (c) 2024 MAIZE SRL <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
27 changes: 13 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,24 @@
}
],
"require": {
"php": "^8.0",
"illuminate/database": "^9.0|^10.0",
"illuminate/http": "^9.0|^10.0",
"illuminate/routing": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"illuminate/validation": "^9.0|^10.0",
"php": "^8.1",
"illuminate/database": "^10.0|^11.0",
"illuminate/http": "^10.0|^11.0",
"illuminate/routing": "^10.0|^11.0",
"illuminate/support": "^10.0|^11.0",
"illuminate/validation": "^10.0|^11.0",
"spatie/laravel-package-tools": "^1.14.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"nunomaduro/collision": "^6.0",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^7.0|^8.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"phpstan/extension-installer": "^1.1",
"nunomaduro/collision": "^7.10.0|^8.1.1",
"larastan/larastan": "^2.0.1",
"orchestra/testbench": "^8.0|^9.0",
"pestphp/pest": "^2.34",
"pestphp/pest-plugin-laravel": "^2.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
"phpstan/phpstan-phpunit": "^1.0"
},
"autoload": {
"psr-4": {
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="Maize 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="Maize 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>
13 changes: 7 additions & 6 deletions src/Http/Controllers/NpsAnswerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ class NpsAnswerController extends Controller
{
public function __invoke(NpsAnswerRequest $request, $id)
{
$request
->user()
->answerNps(
Nps::findOrFail($id),
$request->validated()
);
$user = $request->user();

/** @phpstan-ignore-next-line */
$user->answerNps(
Nps::findOrFail($id),
$request->validated()
);

return response()->noContent();
}
Expand Down
11 changes: 6 additions & 5 deletions src/Http/Controllers/NpsAnswerDelayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ class NpsAnswerDelayController extends Controller
{
public function __invoke(Request $request, $id)
{
$request
->user()
->delayNps(
Nps::findOrFail($id),
);
$user = $request->user();

/** @phpstan-ignore-next-line */
$user->delayNps(
Nps::findOrFail($id),
);

return response()->noContent();
}
Expand Down
9 changes: 5 additions & 4 deletions src/Http/Controllers/NpsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class NpsController extends Controller
{
public function __invoke(Request $request)
{
$nps = $request
->user()
->findCurrentNps(true);
$user = $request->user();

return new NpsResource($nps);
/** @phpstan-ignore-next-line */
$nps = $user->findCurrentNps(true);

return NpsResource::make($nps);
}
}
1 change: 1 addition & 0 deletions src/NpsFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function find(bool $fail = false): ?Nps
$model = $this->getNpsModel();
$builder = $model::query();

/** @var ?Nps $nps */
$nps = Cache::remember(
$model::npsCacheKey(),
config('nps.cache.nps_ttl'),
Expand Down
31 changes: 21 additions & 10 deletions tests/NpsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use Maize\Nps\Models\Nps;
use Maize\Nps\Tests\Models\User;

test('can get a nps', function (User $user) {
test('can get a nps', function () {
$user = User::factory()->create();

$nps = Nps::factory()->create([
'starts_at' => now()->subDays(2),
'ends_at' => now()->addDays(2),
Expand All @@ -19,9 +21,12 @@
'question' => $nps->question,
],
]);
})->with('user');
});

test('cannot get a ended nps', function () {

$user = User::factory()->create();

test('cannot get a ended nps', function (User $user) {
Nps::factory()->create([
'starts_at' => now()->subDays(4),
'ends_at' => now()->subDays(2),
Expand All @@ -30,9 +35,11 @@
actingAs($user, 'api')
->getJson(routeByPartialName('nps.show'))
->assertStatus(404);
})->with('user');
});

test('cannot get a not started nps', function () {
$user = User::factory()->create();

test('cannot get a not started nps', function (User $user) {
Nps::factory()->create([
'starts_at' => now()->addDays(4),
'ends_at' => now()->addDays(2),
Expand All @@ -41,9 +48,11 @@
actingAs($user, 'api')
->getJson(routeByPartialName('nps.show'))
->assertStatus(404);
})->with('user');
});

test('can get current nps', function (Nps $nps) {
$user = User::factory()->create();

test('can get current nps', function (User $user, Nps $nps) {
Nps::factory()->create([
'starts_at' => null,
'ends_at' => null,
Expand Down Expand Up @@ -82,9 +91,11 @@
'id' => $nps->getKey(),
],
]);
})->with('user', 'current_nps');
})->with('current_nps');

test('nps should be cached', function (Nps $nps) {
$user = User::factory()->create();

test('nps should be cached', function (User $user, Nps $nps) {
actingAs($user, 'api')
->getJson(routeByPartialName('nps.show'))
->assertStatus(200);
Expand All @@ -96,4 +107,4 @@
expect(
Cache::get(Nps::npsCacheKey())->toArray()
)->toMatchArray($nps->toArray());
})->with('user', 'current_nps');
})->with('current_nps');

0 comments on commit 7456d5a

Please sign in to comment.