Skip to content

Commit

Permalink
test: improve implementation using Github Actions
Browse files Browse the repository at this point in the history
* tests: add PSR-4 autoloading for test namespace

- Introduced PSR-4 autoloading for the test namespace.
- Updated test files to include the new namespace.

* test: simplify test case structure

- Updated LocalizerTests to extend a new base TestCase.
- Moved package provider and alias methods to the new TestCase class.
- Cleaned up unnecessary setup code in LocalizerTests.

* test: add GitHub Actions workflow for running tests

- Introduced a new workflow to automate testing on push and pull requests.
- Configured matrix strategy for different PHP and Laravel versions.

* chore: remove Travis and CircleCI config files

- Deleted `.travis.yml` and `circle.yml` as CI configurations.
- Updated README to reflect the switch to GitHub Actions for CI.

* test: make PHPUnit config compatible with v10

* test: use testbench package defined in composer.json
  • Loading branch information
jordyvanderhaegen authored Nov 26, 2024
1 parent 42ea38f commit a9a81ab
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 60 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: run-tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.4, 8.3, 8.2]
laravel: [11.*, 10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*

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

steps:
- name: Checkout code
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
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:^2.64" "orchestra/testbench-browser-kit:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ composer.lock
composer.phar
Thumbs.db
phpunit.xml
.phpunit.cache
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

[![Join the chat at https://gitter.im/mcamara/laravel-localization](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mcamara/laravel-localization?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Latest Stable Version](https://poser.pugx.org/mcamara/laravel-localization/version.png)](https://packagist.org/packages/mcamara/laravel-localization) [![Total Downloads](https://poser.pugx.org/mcamara/laravel-localization/d/total.png)](https://packagist.org/packages/mcamara/laravel-localization) [![Build Status](https://travis-ci.org/mcamara/laravel-localization.png)](https://travis-ci.org/mcamara/laravel-localization)
[![Latest Stable Version](https://poser.pugx.org/mcamara/laravel-localization/version.png)](https://packagist.org/packages/mcamara/laravel-localization)
[![Total Downloads](https://poser.pugx.org/mcamara/laravel-localization/d/total.png)](https://packagist.org/packages/mcamara/laravel-localization)
![GitHub Actions](https://github.com/mcamara/laravel-localization/actions/workflows/run-tests.yml/badge.svg)
[![Open Source Helpers](https://www.codetriage.com/mcamara/laravel-localization/badges/users.svg)](https://www.codetriage.com/mcamara/laravel-localization)
[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)

Expand Down
3 changes: 0 additions & 3 deletions circle.yml

This file was deleted.

7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"laravel/framework": "~5.2.0||~5.3.0||~5.4.0||~5.5.0||~5.6.0||~5.7.0||~5.8.0||^6.0||^7.0||^8.0||^9.0|^10.0||^11.0"
},
"require-dev": {
"orchestra/testbench-browser-kit": "~3.4|~3.8|~4.0|^7.12|^8.5",
"orchestra/testbench-browser-kit": "~3.4|~3.8|~4.0|^7.12|^8.5|^9.0",
"phpunit/phpunit": "6.0.*|^8.0|^9.5.10|^10.0"
},
"suggest": {
Expand All @@ -35,6 +35,11 @@
"Mcamara\\LaravelLocalization": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Mcamara\\LaravelLocalization\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
Expand Down
30 changes: 15 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<source>
<include>
<directory suffix=".php">./src/Mcamara</directory>
</whitelist>
</filter>
</include>
</source>
</phpunit>
Empty file removed tests/.gitkeep
Empty file.
24 changes: 4 additions & 20 deletions tests/LocalizerTests.php → tests/LaravelLocalizationTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Mcamara\LaravelLocalization\Tests;

use Illuminate\Support\Facades\Request;
use Mcamara\LaravelLocalization\LaravelLocalization;

class LocalizerTests extends \Orchestra\Testbench\BrowserKit\TestCase
class LaravelLocalizationTest extends TestCase
{
protected $test_url = 'http://localhost/';
protected $test_url2 = 'http://localhost';
Expand All @@ -11,25 +14,6 @@ class LocalizerTests extends \Orchestra\Testbench\BrowserKit\TestCase

protected $defaultLocale = 'en';

protected function getPackageProviders($app)
{
return [
'Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider',
];
}

protected function getPackageAliases($app)
{
return [
'LaravelLocalization' => 'Mcamara\LaravelLocalization\Facades\LaravelLocalization',
];
}

public function setUp(): void
{
parent::setUp();
}

/**
* Set routes for testing.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/ModelWithTranslatableRoutes.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Mcamara\LaravelLocalization\Tests;

use Illuminate\Database\Eloquent\Model;
use Mcamara\LaravelLocalization\Interfaces\LocalizedUrlRoutable;

Expand Down
22 changes: 22 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Mcamara\LaravelLocalization\Tests;

use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider;
use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
protected function getPackageProviders($app)
{
return [LaravelLocalizationServiceProvider::class];
}

protected function getPackageAliases($app)
{
return [
'LaravelLocalization' => LaravelLocalization::class,
];
}
}

0 comments on commit a9a81ab

Please sign in to comment.