Skip to content
Merged
54 changes: 36 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,44 @@ on:
branches:
- master

permissions:
contents: read

jobs:
test:
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
# Disable testing on windows for now...
# os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
php: [7.4, 8.0, 8.1]
laravel: [8.*, 9.*]
#stability: [prefer-lowest, prefer-stable]
php: ["8.1", "8.2", "8.3", "8.4"]
laravel: [10.*, 11.*, 12.*, 13.*]
stability: [prefer-stable]
include:
- laravel: 8.*
testbench: ^6.6
- laravel: 9.*
testbench: 7.*
# Laravel 7 has no support for PHP 8.1
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
- laravel: 12.*
testbench: 10.*
- laravel: 13.*
testbench: 11.*
exclude:
# Laravel 9 doesn't support < PHP 8
- laravel: 9.*
php: 7.4
# Laravel 10 supports PHP 8.1 - 8.3
- laravel: 10.*
php: "8.4"
# Laravel 11 & 12 require PHP >= 8.2
- laravel: 11.*
php: "8.1"
- laravel: 12.*
php: "8.1"
# Laravel 13 requires PHP >= 8.3
- laravel: 13.*
php: "8.1"
- laravel: 13.*
php: "8.2"

services:
redis:
Expand All @@ -43,13 +56,13 @@ jobs:

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, redis
coverage: none

- name: Setup problem matchers
Expand All @@ -58,7 +71,12 @@ jobs:
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
# We intentionally test older, still-constraint-compatible Laravel releases
# (e.g. L10 is EOL) that may carry open Packagist advisories. Composer 2.9+
# blocks advisory-flagged versions during resolution by default, so allow them
# here. This only affects the CI runner, not the published composer.json.
composer config audit.block-insecure false
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --dev --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
run: vendor/bin/phpunit
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ All notable changes to `swiftmade/playback` will be documented in this file
- Fix lock key
- Add a test case for the handling of race condition
- Minor refactor and documentation improvements
- Remove predis dependency
- Remove predis dependency

## Unreleased

- Add support for Laravel 10, 11, 12 and 13
- Drop support for Laravel 8 and 9 (and PHP < 8.1)
- Upgrade test suite to PHPUnit 10/11/12
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Playback gives you idempotent endpoints in Laravel, using Redis locks. [What's e

## Installation

> 💡 Supports Laravel 8.x, Laravel 9.x on PHP 7.4, 8.0 or 8.1
> 💡 Supports Laravel 10.x, 11.x, 12.x and 13.x on PHP 8.1 – 8.4

1. You can install the package via composer:

Expand Down Expand Up @@ -53,7 +53,7 @@ Open `config/cache.php` and add a new store.

Just apply the `Swiftmade\Playback\Playback` middleware to your endpoints. There are many ways of doing it, so here's a link to the docs:

- https://laravel.com/docs/9.x/middleware
- https://laravel.com/docs/middleware

## Use

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
}
],
"require": {
"php": "^7.3|^8.0",
"illuminate/support": "^8.0|^9.0"
"php": "^8.1",
"illuminate/support": "^10.0|^11.0|^12.0|^13.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.9",
"orchestra/testbench": "^6.0|^7.0",
"phpunit/phpunit": "^9.0",
"spatie/async": "^1.5"
"friendsofphp/php-cs-fixer": "^3.64",
"orchestra/testbench": "^8.0|^9.0|^10.0|^11.0",
"phpunit/phpunit": "^10.5|^11.0|^12.0",
"spatie/async": "^1.6"
},
"autoload": {
"psr-4": {
Expand All @@ -49,4 +49,4 @@
]
}
}
}
}
15 changes: 9 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
backupStaticProperties="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>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
47 changes: 14 additions & 33 deletions tests/PlaybackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Spatie\Async\Pool;
use Swiftmade\Playback\Recorder;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Swiftmade\Playback\PlaybackServiceProvider;
use Swiftmade\Playback\Tests\Support\TestServiceProvider;

Expand All @@ -24,9 +25,7 @@ protected function tearDown(): void
parent::tearDown();
}

/**
* @test
*/
#[Test]
public function it_plays_back_post_requests()
{
$headers = [
Expand Down Expand Up @@ -55,9 +54,7 @@ public function it_plays_back_post_requests()
);
}

/**
* @test
*/
#[Test]
public function it_plays_back_internal_server_errors()
{
$headers = [
Expand Down Expand Up @@ -85,9 +82,7 @@ public function it_plays_back_internal_server_errors()
);
}

/**
* @test
*/
#[Test]
public function different_key_returns_different_response()
{
$headers = [
Expand Down Expand Up @@ -116,9 +111,7 @@ public function different_key_returns_different_response()
);
}

/**
* @test
*/
#[Test]
public function it_returns_400_if_headers_change()
{
$headers = [
Expand All @@ -137,9 +130,7 @@ public function it_returns_400_if_headers_change()
$response2->assertStatus(400);
}

/**
* @test
*/
#[Test]
public function it_returns_400_if_body_changes()
{
$headers = [
Expand All @@ -158,9 +149,7 @@ public function it_returns_400_if_body_changes()
$response2->assertStatus(400);
}

/**
* @test
*/
#[Test]
public function it_returns_400_if_query_parameters_change()
{
$headers = [
Expand All @@ -176,9 +165,7 @@ public function it_returns_400_if_query_parameters_change()
$response2->assertStatus(400);
}

/**
* @test
*/
#[Test]
public function it_returns_400_if_path_changes()
{
$headers = [
Expand All @@ -194,9 +181,7 @@ public function it_returns_400_if_path_changes()
$response2->assertStatus(400);
}

/**
* @test
*/
#[Test]
public function it_does_not_play_back_if_validation_fails()
{
$headers = [
Expand Down Expand Up @@ -228,9 +213,7 @@ public function it_does_not_play_back_if_validation_fails()
$response4->assertHeader(config('playback.playback_header_name'), 'validation_test');
}

/**
* @test
*/
#[Test]
public function it_does_not_record_get_request()
{
$headers = [
Expand All @@ -253,9 +236,7 @@ public function it_does_not_record_get_request()
);
}

/**
* @test
*/
#[Test]
public function the_first_request_wins()
{
$headers = [
Expand All @@ -267,7 +248,7 @@ public function the_first_request_wins()
->timeout(6);

$pool[] = async(function () use ($headers) {
$app = new self();
$app = new self('the_first_request_wins');
$app->setUpBeforeClass();
$app->setUp();
$response = $app->post('slow', [], $headers);
Expand All @@ -285,7 +266,7 @@ public function the_first_request_wins()
$pool[] = async(function () use ($headers) {
usleep(150 * 1000);

$app = new self();
$app = new self('the_first_request_wins');
$app->setUpBeforeClass();
$app->setUp();
$response = $app->post('slow', [], $headers);
Expand All @@ -302,7 +283,7 @@ public function the_first_request_wins()
$pool[] = async(function () use ($headers) {
usleep(3000 * 1000);

$app = new self();
$app = new self('the_first_request_wins');
$app->setUpBeforeClass();
$app->setUp();
$response = $app->post('slow', [], $headers);
Expand Down
Loading