|
| 1 | +# Laravel MinIO Testing Tools |
| 2 | + |
| 3 | +[](https://packagist.org/packages/protonemedia/laravel-minio-testing-tools) |
| 4 | +[](LICENSE.md) |
| 5 | +[](https://github.com/protonemedia/laravel-minio-testing-tools/actions?query=workflow%3Arun-tests+branch%3Amain) |
| 6 | +[](https://packagist.org/packages/protonemedia/laravel-minio-testing-tools) |
| 7 | +[](https://plant.treeware.earth/protonemedia/laravel-minio-testing-tools) |
| 8 | + |
| 9 | +This package provides a trait to run your tests against a MinIO S3 server. |
| 10 | + |
| 11 | +## Support |
| 12 | + |
| 13 | +We proudly support the community by developing Laravel packages and giving them away for free. Keeping track of issues and pull requests takes time, but we're happy to help! If this package saves you time or if you're relying on it professionally, please consider [supporting the maintenance and development](https://github.com/sponsors/pascalbaljet). |
| 14 | + |
| 15 | +## Features |
| 16 | +* Starts and configures a MinIO server for your tests. |
| 17 | +* Updates the `filesystems` disk configuration. |
| 18 | +* Updates and restores the `.env` file. |
| 19 | +* Works with [Laravel Dusk](https://laravel.com/docs/9.x/dusk). |
| 20 | +* Works on [GitHub Actions](#github-actions) |
| 21 | +* Compatible with Laravel 9.0. |
| 22 | +* PHP 8.0 or higher is required. |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +Make sure you've downloaded the [MinIO Server and Client](https://min.io/download#/linux) for your OS. |
| 27 | + |
| 28 | +You can install the package via composer: |
| 29 | + |
| 30 | +```bash |
| 31 | +composer require protonemedia/laravel-minio-testing-tools --dev |
| 32 | +``` |
| 33 | + |
| 34 | +Add the trait to your test, and add the `bootUsesMinIOServer` method: |
| 35 | + |
| 36 | +```php |
| 37 | +<?php |
| 38 | + |
| 39 | +namespace Tests\Browser\Backend; |
| 40 | + |
| 41 | +use Illuminate\Foundation\Testing\DatabaseMigrations; |
| 42 | +use ProtoneMedia\LaravelMinioTestingTools\UsesMinioServer; |
| 43 | +use Tests\DuskTestCase; |
| 44 | + |
| 45 | +class UploadVideoTest extends DuskTestCase |
| 46 | +{ |
| 47 | + use DatabaseMigrations; |
| 48 | + use UsesMinioServer; |
| 49 | + |
| 50 | + protected function setUp(): void |
| 51 | + { |
| 52 | + parent::setUp(); |
| 53 | + |
| 54 | + $this->bootUsesMinIOServer(); |
| 55 | + } |
| 56 | + |
| 57 | + /** @test */ |
| 58 | + public function it_can_upload_a_video_using_multipart_upload() |
| 59 | + { |
| 60 | + } |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +That's it! |
| 65 | + |
| 66 | +## GitHub Actions |
| 67 | + |
| 68 | +The easiest way is to download the MinIO Server and Client before the tests are run: |
| 69 | + |
| 70 | +```yaml |
| 71 | +jobs: |
| 72 | + test: |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v2 |
| 75 | + |
| 76 | + - name: Download MinIO S3 server and client |
| 77 | + run: | |
| 78 | + wget https://dl.minio.io/server/minio/release/linux-amd64/minio -q -P /usr/local/bin/ |
| 79 | + wget https://dl.minio.io/client/mc/release/linux-amd64/mc -q -P /usr/local/bin/ |
| 80 | + chmod +x /usr/local/bin/minio |
| 81 | + chmod +x /usr/local/bin/mc |
| 82 | + minio --version |
| 83 | + mc --version |
| 84 | +``` |
| 85 | +
|
| 86 | +If you're using `php artisan serve`, make sure you don't use the `--no-reload` flag, as the `.env` file will be changed on-the-fly. |
| 87 | + |
| 88 | +Optionally, if you want persistent storage across the test suite, you may start the server manually before the tests are run. |
| 89 | + |
| 90 | +```yaml |
| 91 | +jobs: |
| 92 | + test: |
| 93 | + steps: |
| 94 | + - uses: actions/checkout@v2 |
| 95 | +
|
| 96 | + - name: Download MinIO S3 server and client |
| 97 | + run: | |
| 98 | + wget https://dl.minio.io/server/minio/release/linux-amd64/minio -q -P /usr/local/bin/ |
| 99 | + wget https://dl.minio.io/client/mc/release/linux-amd64/mc -q -P /usr/local/bin/ |
| 100 | + chmod +x /usr/local/bin/minio |
| 101 | + chmod +x /usr/local/bin/mc |
| 102 | + minio --version |
| 103 | + mc --version |
| 104 | +
|
| 105 | + - name: Run MinIO S3 server |
| 106 | + run: | |
| 107 | + mkdir ~/s3 |
| 108 | + sudo minio server ~/s3 --json > minio-log.json & |
| 109 | +
|
| 110 | + - name: Configure MinIO S3 |
| 111 | + run: | |
| 112 | + mc config host add local http://127.0.0.1:9000 minioadmin minioadmin |
| 113 | + mc admin user add local user password |
| 114 | + mc admin policy set local readwrite user=user |
| 115 | + mc mb local/bucket-name --region=eu-west-1 |
| 116 | +
|
| 117 | + - name: Upload Minio Logs (optional) |
| 118 | + if: failure() |
| 119 | + uses: actions/upload-artifact@v2 |
| 120 | + with: |
| 121 | + name: minio |
| 122 | + path: minio-log.json |
| 123 | +``` |
| 124 | + |
| 125 | +In this case, you also need to supply an environment file with the MinIO configuration. This makes the configuration also accessible by the browser session when you're running Laravel Dusk. |
| 126 | + |
| 127 | +```env |
| 128 | +AWS_ACCESS_KEY_ID=user |
| 129 | +AWS_SECRET_ACCESS_KEY=password |
| 130 | +AWS_DEFAULT_REGION=eu-west-1 |
| 131 | +AWS_BUCKET=bucket-name |
| 132 | +AWS_URL=http://127.0.0.1:9000 |
| 133 | +AWS_ENDPOINT=http://127.0.0.1:9000 |
| 134 | +AWS_USE_PATH_STYLE_ENDPOINT=true |
| 135 | +``` |
| 136 | + |
| 137 | +## Testing |
| 138 | + |
| 139 | +```bash |
| 140 | +composer test |
| 141 | +``` |
| 142 | + |
| 143 | +## Changelog |
| 144 | + |
| 145 | +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
| 146 | + |
| 147 | +## Contributing |
| 148 | + |
| 149 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 150 | + |
| 151 | +## Other Laravel packages |
| 152 | + |
| 153 | +* [`Laravel Analytics Event Tracking`](https://github.com/protonemedia/laravel-analytics-event-tracking): Laravel package to easily send events to Google Analytics. |
| 154 | +* [`Laravel Blade On Demand`](https://github.com/protonemedia/laravel-blade-on-demand): Laravel package to compile Blade templates in memory. |
| 155 | +* [`Laravel Cross Eloquent Search`](https://github.com/protonemedia/laravel-cross-eloquent-search): Laravel package to search through multiple Eloquent models. |
| 156 | +* [`Laravel Eloquent Scope as Select`](https://github.com/protonemedia/laravel-eloquent-scope-as-select): Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery. |
| 157 | +* [`Laravel Eloquent Where Not`](https://github.com/protonemedia/laravel-eloquent-where-not): This Laravel package allows you to flip/invert an Eloquent scope, or really any query constraint. |
| 158 | +* [`Laravel FFMpeg`](https://github.com/protonemedia/laravel-ffmpeg): This package provides an integration with FFmpeg for Laravel. The storage of the files is handled by Laravel's Filesystem. |
| 159 | +* [`Laravel Form Components`](https://github.com/protonemedia/laravel-form-components): Blade components to rapidly build forms with Tailwind CSS Custom Forms and Bootstrap 4. Supports validation, model binding, default values, translations, includes default vendor styling and fully customizable! |
| 160 | +* [`Laravel Mixins`](https://github.com/protonemedia/laravel-mixins): A collection of Laravel goodies. |
| 161 | +* [`Laravel Paddle`](https://github.com/protonemedia/laravel-paddle): Paddle.com API integration for Laravel with support for webhooks/events. |
| 162 | +* [`Laravel Verify New Email`](https://github.com/protonemedia/laravel-verify-new-email): This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified. |
| 163 | +* [`Laravel WebDAV`](https://github.com/protonemedia/laravel-webdav): WebDAV driver for Laravel's Filesystem. |
| 164 | + |
| 165 | +## Security |
| 166 | + |
| 167 | +If you discover any security-related issues, please email code@protone.media instead of using the issue tracker. Please do not email any questions, open an issue if you have a question. |
| 168 | + |
| 169 | +## Credits |
| 170 | + |
| 171 | +- [Pascal Baljet](https://github.com/pascalbaljet) |
| 172 | +- [All Contributors](../../contributors) |
| 173 | + |
| 174 | +## License |
| 175 | + |
| 176 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments