Skip to content

Commit

Permalink
Add GitHub tests workflow (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev authored Feb 24, 2023
1 parent 61c73d0 commit 0bfbff8
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 41 deletions.
40 changes: 40 additions & 0 deletions .docker/nginx/app.laravel-optimus.80.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
server {
listen 80;
listen [::]:80;
server_name app.laravel-optimus.localhost;

root /app/public;
index index.php index.html;
access_log /dev/stdout;
error_log /dev/stderr info;

charset utf-8;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;

add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;

server_tokens off;
client_max_body_size 100M;

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}

location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
19 changes: 19 additions & 0 deletions .docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ----------------------
# The FPM base container
# ----------------------
FROM php:8.1-fpm-alpine AS dev

# Cleanup apk cache and temp files
RUN rm -rf /var/cache/apk/* /tmp/*

# ----------------------
# Composer install step
# ----------------------

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# ----------------------
# The FPM production container
# ----------------------
FROM dev
85 changes: 85 additions & 0 deletions .docker/php/www.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www]

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = www-data
group = www-data

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 9000

; Choose how the process manager will control the number of child processes.
; Possible Values:
; static - a fixed number (pm.max_children) of child processes;
; dynamic - the number of child processes are set dynamically based on the
; following directives. With this process management, there will be
; always at least 1 children.
; pm.max_children - the maximum number of children that can
; be alive at the same time.
; pm.start_servers - the number of children created on startup.
; pm.min_spare_servers - the minimum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is less than this
; number then some children will be created.
; pm.max_spare_servers - the maximum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is greater than this
; number then some children will be killed.
; ondemand - no children are created at startup. Children will be forked when
; new requests will connect. The following parameter are used:
; pm.max_children - the maximum number of children that
; can be alive at the same time.
; pm.process_idle_timeout - The number of seconds after which
; an idle process will be killed.
; Note: This value is mandatory.
pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 5

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 2

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 3

; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
;pm.max_requests = 500
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* text=auto

/.docker export-ignore
/.github export-ignore
/tests export-ignore
/.gitattributes export-ignore
Expand All @@ -8,4 +9,5 @@
/.travis.yml export-ignore
/CODE_OF_CONDUCT.md export-ignore
/CONTRIBUTING.md export-ignore
/docker-compose.yaml export-ignore
/phpunit.xml.dist export-ignore
48 changes: 48 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: tests

on: [ push, pull_request ]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.0, 8.1, 8.2 ]
laravel: [ 9.* ]
dependency-version: [ prefer-lowest, prefer-stable ]
exclude:
- laravel: 9.*
php: 8.2
include:
- laravel: 9.*
testbench: 7.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

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

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit --testdox
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ This project follows [PSR-12 coding style guide](https://www.php-fig.org/psr/psr

The phpunit script can be used to invoke the PHPUnit test runner:

```shell script
$ vendor/bin/phpunit
```shell
vendor/bin/phpunit
```

## Reporting issues
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p align="center">
<a href="https://discord.gg/R2sbjAt"><img src="https://img.shields.io/static/v1?logo=discord&label=&message=Discord&color=36393f&style=flat-square" alt="Discord"></a>
<a href="https://github.com/cybercog/laravel-optimus/releases"><img src="https://img.shields.io/github/release/cybercog/laravel-optimus.svg?style=flat-square" alt="Releases"></a>
<a href="https://travis-ci.org/cybercog/laravel-optimus"><img src="https://img.shields.io/travis/cybercog/laravel-optimus/master.svg?style=flat-square" alt="Build Status"></a>
<a href="https://github.com/cybercog/laravel-optimus/actions/workflows/tests.yml"><img src="https://img.shields.io/github/actions/workflow/status/cybercog/laravel-optimus/tests.yml?style=flat-square" alt="Build"></a>
<a href="https://styleci.io/repos/77817858"><img src="https://styleci.io/repos/77817858/shield" alt="StyleCI"></a>
<a href="https://scrutinizer-ci.com/g/cybercog/laravel-optimus/?branch=master"><img src="https://img.shields.io/scrutinizer/g/cybercog/laravel-optimus.svg?style=flat-square" alt="Code Quality"></a>
<a href="https://github.com/cybercog/laravel-optimus/blob/master/LICENSE"><img src="https://img.shields.io/github/license/cybercog/laravel-optimus.svg?style=flat-square" alt="License"></a>
Expand Down Expand Up @@ -48,8 +48,8 @@ Laravel wrapper for the [Optimus Library](https://github.com/jenssegers/optimus)

First, pull in the package through Composer.

```shell script
$ composer require cybercog/laravel-optimus
```shell
composer require cybercog/laravel-optimus
```

#### Register Package Manually (optional)
Expand All @@ -76,8 +76,8 @@ If you want you can use the [facade](http://laravel.com/docs/facades). Add the r

Laravel Optimus requires connection configuration. To get started, you'll need to publish config file:

```shell script
$ php artisan vendor:publish --provider="Cog\Laravel\Optimus\Providers\OptimusServiceProvider" --tag="config"
```shell
php artisan vendor:publish --provider="Cog\Laravel\Optimus\Providers\OptimusServiceProvider" --tag="config"
```

This will create a `config/optimus.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.
Expand All @@ -100,8 +100,8 @@ To get started you will need 3 keys in main connection;

Luckily for you, there is console command that can do all of this for you, just run the following command:

```shell script
$ php vendor/bin/optimus spark
```shell
php vendor/bin/optimus spark
```

Copy-paste generated integers to your connection config.
Expand Down Expand Up @@ -241,8 +241,8 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Run the tests with:

```shell script
$ vendor/bin/phpunit
```shell
vendor/bin/phpunit
```

## Security
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"require-dev": {
"graham-campbell/testbench": "^5.0",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^6.5|^7.0|^8.0|^9.0"
"phpunit/phpunit": "^9.6"
},
"autoload": {
"psr-4": {
Expand Down
35 changes: 35 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "3.9"
services:
app:
container_name: laravel-optimus-app
image: laravel-optimus-app
build:
context: ./
dockerfile: ./.docker/php/Dockerfile
restart: unless-stopped
working_dir: /app
volumes:
- ./:/app
- ./.docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro
networks:
- laravel-optimus

nginx:
container_name: laravel-optimus-nginx
image: nginx:1.21-alpine
restart: unless-stopped
depends_on:
- app
ports:
- "80:80"
environment:
VIRTUAL_HOST: app.laravel-optimus.localhost
volumes:
- ./.docker/nginx/app.laravel-optimus.80.conf:/etc/nginx/conf.d/app.laravel-optimus.80.conf:ro
- ./public:/app/public:ro
networks:
- laravel-optimus

networks:
laravel-optimus:
driver: bridge
2 changes: 1 addition & 1 deletion tests/Facades/OptimusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Cog\Tests\Laravel\Optimus\AbstractTestCase;
use GrahamCampbell\TestBenchCore\FacadeTrait;

class OptimusTest extends AbstractTestCase
final class OptimusTest extends AbstractTestCase
{
use FacadeTrait;

Expand Down
2 changes: 1 addition & 1 deletion tests/OptimusFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Cog\Laravel\Optimus\OptimusFactory;
use Jenssegers\Optimus\Optimus;

class OptimusFactoryTest extends AbstractTestCase
final class OptimusFactoryTest extends AbstractTestCase
{
public function testMakeStandard(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/OptimusManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Jenssegers\Optimus\Optimus;
use Mockery;

class OptimusManagerTest extends AbstractTestBenchTestCase
final class OptimusManagerTest extends AbstractTestBenchTestCase
{
public function testCreateConnection(): void
{
Expand Down
5 changes: 3 additions & 2 deletions tests/Providers/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

declare(strict_types=1);

namespace Cog\Tests\Laravel\Optimus;
namespace Cog\Tests\Laravel\Optimus\Providers;

use Cog\Laravel\Optimus\OptimusFactory;
use Cog\Laravel\Optimus\OptimusManager;
use Cog\Tests\Laravel\Optimus\AbstractTestCase;
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
use Jenssegers\Optimus\Optimus;

class ServiceProviderTest extends AbstractTestCase
final class ServiceProviderTest extends AbstractTestCase
{
use ServiceProviderTrait;

Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/Models/UserWithCustomOptimusConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Cog\Laravel\Optimus\Traits\OptimusEncodedRouteKey;
use Illuminate\Database\Eloquent\Model;

class UserWithCustomOptimusConnection extends Model
final class UserWithCustomOptimusConnection extends Model
{
use OptimusEncodedRouteKey;

Expand Down
Loading

0 comments on commit 0bfbff8

Please sign in to comment.