diff --git a/.docker/nginx/app.laravel-optimus.80.conf b/.docker/nginx/app.laravel-optimus.80.conf new file mode 100644 index 0000000..cc9f581 --- /dev/null +++ b/.docker/nginx/app.laravel-optimus.80.conf @@ -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; + } +} diff --git a/.docker/php/Dockerfile b/.docker/php/Dockerfile new file mode 100644 index 0000000..fa9f794 --- /dev/null +++ b/.docker/php/Dockerfile @@ -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 diff --git a/.docker/php/www.conf b/.docker/php/www.conf new file mode 100644 index 0000000..39bef0c --- /dev/null +++ b/.docker/php/www.conf @@ -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 diff --git a/.gitattributes b/.gitattributes index 57add99..7d5e79d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ * text=auto +/.docker export-ignore /.github export-ignore /tests export-ignore /.gitattributes export-ignore @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..8b17604 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 17966df..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: php - -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - 8.0 - -env: - global: - - setup=basic - -before_script: - - composer config discard-changes true - - if [[ $setup = 'basic' ]]; then travis_retry composer install --prefer-dist --no-interaction; fi - - if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable; fi - - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi - -script: - - ./vendor/bin/phpunit -c phpunit.xml.dist --verbose diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e37461..617846c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/README.md b/README.md index 6979632..6c26ec3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@

Discord Releases -Build Status +Build StyleCI Code Quality License @@ -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) @@ -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. @@ -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. @@ -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 diff --git a/composer.json b/composer.json index c693aad..a62d488 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..03ea3d4 --- /dev/null +++ b/docker-compose.yaml @@ -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 diff --git a/tests/Facades/OptimusTest.php b/tests/Facades/OptimusTest.php index 4b9282d..d2fbb5a 100644 --- a/tests/Facades/OptimusTest.php +++ b/tests/Facades/OptimusTest.php @@ -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; diff --git a/tests/OptimusFactoryTest.php b/tests/OptimusFactoryTest.php index 043b271..9b33ad3 100644 --- a/tests/OptimusFactoryTest.php +++ b/tests/OptimusFactoryTest.php @@ -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 { diff --git a/tests/OptimusManagerTest.php b/tests/OptimusManagerTest.php index 5c9e861..ae4eacd 100644 --- a/tests/OptimusManagerTest.php +++ b/tests/OptimusManagerTest.php @@ -20,7 +20,7 @@ use Jenssegers\Optimus\Optimus; use Mockery; -class OptimusManagerTest extends AbstractTestBenchTestCase +final class OptimusManagerTest extends AbstractTestBenchTestCase { public function testCreateConnection(): void { diff --git a/tests/Providers/ServiceProviderTest.php b/tests/Providers/ServiceProviderTest.php index 2554280..7597b45 100644 --- a/tests/Providers/ServiceProviderTest.php +++ b/tests/Providers/ServiceProviderTest.php @@ -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; diff --git a/tests/Stubs/Models/UserWithCustomOptimusConnection.php b/tests/Stubs/Models/UserWithCustomOptimusConnection.php index 57ea32f..6d45cbf 100644 --- a/tests/Stubs/Models/UserWithCustomOptimusConnection.php +++ b/tests/Stubs/Models/UserWithCustomOptimusConnection.php @@ -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; diff --git a/tests/Stubs/Models/UserWithDefaultOptimusConnection.php b/tests/Stubs/Models/UserWithDefaultOptimusConnection.php index fd85d34..080c487 100644 --- a/tests/Stubs/Models/UserWithDefaultOptimusConnection.php +++ b/tests/Stubs/Models/UserWithDefaultOptimusConnection.php @@ -5,7 +5,7 @@ use Cog\Laravel\Optimus\Traits\OptimusEncodedRouteKey; use Illuminate\Database\Eloquent\Model; -class UserWithDefaultOptimusConnection extends Model +final class UserWithDefaultOptimusConnection extends Model { use OptimusEncodedRouteKey; diff --git a/tests/Traits/OptimusEncodedRouteKeyTest.php b/tests/Traits/OptimusEncodedRouteKeyTest.php index 957dca2..ce566b7 100644 --- a/tests/Traits/OptimusEncodedRouteKeyTest.php +++ b/tests/Traits/OptimusEncodedRouteKeyTest.php @@ -21,7 +21,7 @@ use Illuminate\Support\Facades\Route; use Jenssegers\Optimus\Optimus as JenssegersOptimus; -class OptimusEncodedRouteKeyTest extends AbstractTestCase +final class OptimusEncodedRouteKeyTest extends AbstractTestCase { protected function setUp(): void {