Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/laravel-installation-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Laravel Installation Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
# Run tests weekly on Sunday at 0:00 UTC
- cron: '0 0 * * 0'

jobs:
laravel-installation-test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3', '8.4']
laravel-version: ['9.*', '10.*', '11.*', '12.*']
exclude:
# Laravel 9 requires PHP 8.0+, we start from 8.1
# Laravel 10 requires PHP 8.1+
# Laravel 11 requires PHP 8.2+
# Laravel 12 requires PHP 8.3+
- php-version: '8.1'
laravel-version: '11.*'
- php-version: '8.1'
laravel-version: '12.*'
- php-version: '8.2'
laravel-version: '12.*'

name: PHP ${{ matrix.php-version }} - Laravel ${{ matrix.laravel-version }}

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

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

- name: Make test script executable
run: chmod +x scripts/test-laravel-installation.sh

- name: Run Laravel installation tests
run: ./scripts/test-laravel-installation.sh ${{ matrix.laravel-version }} --keep-files

- name: Run PHPUnit tests in Laravel context
run: |
# Convert Laravel version to directory name (e.g., "10.*" -> "10.x")
LARAVEL_DIR=$(echo "${{ matrix.laravel-version }}" | sed 's/\*/x/g')
cd laravel-installation-tests/laravel-${LARAVEL_DIR}

# Copy the package tests to Laravel test directory
cp -r ../../tests/* tests/
cp ../../phpunit.xml ./phpunit-package.xml
# Run the package tests within Laravel context
./vendor/bin/phpunit --configuration=phpunit-package.xml --testdox
2 changes: 1 addition & 1 deletion .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
php-version: ['8.0', '8.1', '8.2', '8.3', '8.4']
php-version: ['8.1', '8.2', '8.3', '8.4']

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ coverage/
*.log
.DS_Store
composer.lock

laravel-installation-tests/
Empty file added FILLED_PR_TEMPLATE.md
Empty file.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Progressive JSON Streaming for PHP APIs

**TL;DR:** Stream JSON data incrementally to show users page structure instantly while slow API calls complete in the background.
**TL;DR:** Progressive JSON Streaming sends data incrementally to show users page structure instantly while slow API calls complete in the background.

[![PHP Version](https://img.shields.io/badge/PHP-8.0%2B-blue?style=flat-square&logo=php)](https://www.php.net/)[![Tests](https://img.shields.io/github/actions/workflow/status/egyjs/progressive-json-php/php-tests.yml?branch=master&style=flat-square&logo=github&label=Tests)](https://github.com/egyjs/progressive-json-php/actions)
[![PHP Version](https://img.shields.io/badge/PHP-8.1%2B-blue?style=flat-square&logo=php)](https://www.php.net/)[![Tests](https://img.shields.io/github/actions/workflow/status/egyjs/progressive-json-php/php-tests.yml?branch=master&style=flat-square&logo=github&label=Tests)](https://github.com/egyjs/progressive-json-php/actions)
[![Code Coverage](https://img.shields.io/codecov/c/github/egyjs/progressive-json-php?style=flat-square&logo=codecov)](https://codecov.io/gh/egyjs/progressive-json-php)
[![Latest Version](https://img.shields.io/packagist/v/egyjs/progressive-json-php?style=flat-square&logo=packagist)](https://packagist.org/packages/egyjs/progressive-json-php)
[![License](https://img.shields.io/github/license/egyjs/progressive-json-php?style=flat-square)](https://github.com/egyjs/progressive-json-php/blob/master/LICENSE)
Expand Down Expand Up @@ -584,15 +584,34 @@ The test suite includes:
- βœ… Stream generation and output
- βœ… Symfony integration tests
- βœ… Configuration and validation tests
- βœ… **Laravel installation tests** (v9.x - v12.x)

Coverage reports are generated in `build/coverage-html/` when running with coverage.

### Laravel Installation Tests

We provide comprehensive installation tests for Laravel versions 9.x through 12.x:

```bash
# Run Laravel installation tests locally
./scripts/test-laravel-installation.sh
```

These tests verify:
- Package installation via Composer
- Autoloading and integration with Laravel
- Performance and clean removal

See [`docs/LARAVEL_INSTALLATION_TESTS.md`](docs/LARAVEL_INSTALLATION_TESTS.md) for detailed information.

### Continuous Integration

GitHub Actions automatically runs tests on:
- PHP 8.0, 8.1, 8.2, 8.3, and 8.4
- PHP 8.1, 8.2, 8.3, and 8.4
- Laravel 9.x, 10.x, 11.x, and 12.x combinations
- Push and Pull Request events
- Multiple operating systems
- Weekly scheduled runs

---

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "egyjs/progressive-json-php",
"version": "1.0.1",
"version": "1.1.0",
"description": "Framework-agnostic Progressive JSON Streamer for PHP - breadth-first JSON streaming with placeholders, inspired by Dan Abramov's Progressive JSON.",
"keywords": ["php", "json", "stream", "streaming", "progressive json", "progressive-json", "react", "suspense", "laravel", "symfony", "vue", "breadth-first json"],
"type": "library",
"require": {
"symfony/http-foundation": "^5.4",
"php": ">=8.0"
"symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
"php": ">=8.1"
},
"license": "MIT",
"autoload": {
Expand Down
219 changes: 219 additions & 0 deletions docs/LARAVEL_INSTALLATION_TESTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# Laravel Installation Tests

This directory contains comprehensive tests to verify that the `egyjs/progressive-json-php` package installs and works correctly across multiple Laravel versions (9.x through 12.x).

## Overview

The installation tests verify:

- βœ… **Package Installation**: Composer can successfully install the package
- βœ… **Autoloading**: Classes are properly autoloaded in Laravel context
- βœ… **Basic Functionality**: Core package features work as expected
- βœ… **Laravel Integration**: Package integrates well with Laravel's ecosystem

## Test Matrix

| PHP Version | Laravel 9.x | Laravel 10.x | Laravel 11.x | Laravel 12.x |
|-------------|-------------|--------------|--------------|--------------|
| PHP 8.1 | βœ… | βœ… | ❌* | ❌* |
| PHP 8.2 | βœ… | βœ… | βœ… | ❌* |
| PHP 8.3 | βœ… | βœ… | βœ… | βœ… |
| PHP 8.4 | βœ… | βœ… | βœ… | βœ… |

_*Laravel version requirements exclude certain PHP versions_

## Automated Testing (GitHub Actions)

The GitHub Actions workflow (`.github/workflows/laravel-installation-test.yml`) automatically runs these tests:

- **Triggers**: Push to master, Pull requests, Weekly schedule
- **Matrix Strategy**: Tests all compatible PHP/Laravel version combinations
- **Unified Testing**: Uses the same `scripts/test-laravel-installation.sh` script for consistency
- **Comprehensive Testing**: Full integration testing in clean Laravel installations
- **Performance Monitoring**: Tracks performance across versions
- **Summary Reporting**: Provides detailed test results and summaries

### Workflow Architecture

The GitHub Actions workflow leverages the same local test script for consistency:

1. **Setup**: Configures PHP environment with required extensions
2. **Script Execution**: Runs `./scripts/test-laravel-installation.sh [VERSION] --keep-files`
3. **PHPUnit Integration**: Executes package tests within the Laravel context
4. **Summary Generation**: Provides comprehensive test results

This unified approach ensures that:
- Local and CI testing use identical logic
- Debugging is easier (run the same script locally)
- Maintenance is simplified (single source of truth)

### Viewing Test Results

1. Go to the "Actions" tab in your GitHub repository
2. Look for "Laravel Installation Tests" workflow runs
3. Click on any run to see detailed results for each PHP/Laravel combination
4. Check the summary for a quick overview of test results

## Local Testing

### Prerequisites

- PHP 8.1+ with Composer installed
- Git (for cloning Laravel projects)
- Sufficient disk space (each Laravel installation ~100MB)

### Running Tests

The test script accepts Laravel version parameters for flexible testing:

#### On Linux/macOS:

```bash
# Make the script executable
chmod +x scripts/test-laravel-installation.sh

# Run all tests (default: Laravel 9.*, 10.*, 11.*, 12.*)
./scripts/test-laravel-installation.sh

# Test specific Laravel version
./scripts/test-laravel-installation.sh 10.*

# Test multiple specific versions
./scripts/test-laravel-installation.sh 9.* 11.*

# Keep test files for inspection (don't auto-cleanup)
./scripts/test-laravel-installation.sh --keep-files

# Combine version selection with file preservation
./scripts/test-laravel-installation.sh 10.* 11.* --keep-files

# Show help information
./scripts/test-laravel-installation.sh --help
```

#### Script Parameters

- **Laravel Versions**: Specify one or more Laravel versions (e.g., `9.*`, `10.*`, `11.*`, `12.*`)
- **`--keep-files`**: Preserve test directories after completion for debugging
- **`--help`**: Display usage information and examples

If no Laravel versions are specified, the script tests all default versions (9.* through 12.*).

#### Examples

```bash
# Test only Laravel 10 and 11
./scripts/test-laravel-installation.sh 10.* 11.*

# Test Laravel 9 and keep files for inspection
./scripts/test-laravel-installation.sh 9.* --keep-files

# Quick test of latest Laravel version
./scripts/test-laravel-installation.sh 12.*
```

### Understanding Test Output

The scripts provide colored output to help you understand the test progress:

- πŸ”΅ **[INFO]**: General information about test progress
- 🟒 **[SUCCESS]**: Test step completed successfully
- 🟑 **[WARNING]**: Non-critical issues or warnings
- πŸ”΄ **[ERROR]**: Test failures that need attention

### Example Output

```
[INFO] Starting Laravel Installation Tests
[INFO] PHP Version: 8.3.0
[INFO] Package: egyjs/progressive-json-php

[INFO] Testing Laravel 10.*
[INFO] Creating Laravel 10.* application...
[INFO] Created: Laravel Framework 10.48.22
[INFO] Installing egyjs/progressive-json-php...
[SUCCESS] Autoloading: βœ“
[SUCCESS] Basic functionality: βœ“
[SUCCESS] Laravel 10.* tests completed successfully!

=== TEST SUMMARY ===
[SUCCESS] All Laravel installation tests passed! πŸŽ‰
[INFO] Your package is compatible with Laravel versions: 9.* 10.* 11.* 12.*
```

## Test Details

### Package Installation Test
- Creates fresh Laravel applications using `composer create-project`
- Configures local package repository to simulate Packagist installation
- Installs package via `composer require egyjs/progressive-json-php:@dev`
- Verifies package appears in `composer show` output

### Autoloading Test
- Requires vendor autoload file
- Attempts to instantiate `Egyjs\ProgressiveJson\ProgressiveJsonStreamer`
- Verifies class exists and can be loaded

### Basic Functionality Test
- Creates ProgressiveJsonStreamer instance within Laravel application context
- Processes sample data including Laravel version and PHP version information
- Uses Laravel's `app()->version()` helper to verify Laravel integration
- Verifies output is generated correctly and not empty
- Tests that the package works seamlessly within Laravel's environment


## Continuous Integration

### GitHub Actions Integration

The workflow is designed to:
- Run automatically on code changes
- Test against all supported Laravel/PHP combinations
- Provide detailed failure information
- Cache dependencies for faster execution
- Generate test summaries

### Test Scope

The current implementation focuses on essential compatibility testing:
- **Installation verification**: Ensures the package can be installed via Composer
- **Autoloading verification**: Confirms classes load correctly in Laravel
- **Basic functionality**: Tests core features work within Laravel context
- **Future enhancements**: Additional tests (service providers, routes, performance) may be added

### Adding New Laravel Versions

To test new Laravel versions:

1. Update the matrix in `.github/workflows/laravel-installation-test.yml`
2. Add version to `LARAVEL_VERSIONS` array in test scripts
3. Update compatibility matrix in this documentation
4. Test locally before committing

### Custom Test Scenarios

You can extend the tests by:
- Adding service provider integration tests
- Testing route context functionality
- Adding performance benchmarks
- Testing HTTP response generation
- Adding package removal verification
- Testing with different PHP extensions

## Contributing

When contributing to the package:

1. Run installation tests locally before submitting PRs
2. Update tests if adding Laravel-specific features
3. Ensure tests pass in CI before merging
4. Update this documentation for any test changes

## Support

If you encounter issues with the installation tests:

1. Check the troubleshooting section above
2. Review GitHub Actions logs for detailed error information
3. Run tests locally with `--keep-files` for debugging
4. Open an issue with test output and environment details
Loading