├── .github └── workflows │ └── run-tests.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── composer.json ├── config └── mailviewer.php ├── phpunit.xml.dist ├── routes └── web.php ├── src ├── Controllers │ └── MailViewerController.php ├── MailViewer.php └── MailViewerServiceProvider.php ├── tests ├── BaseTestCase.php ├── Database │ ├── Factories │ │ └── TestFactory.php │ └── Migrations │ │ └── 2018_10_10_131000_add_test_table.php ├── MailViewerTest.php └── Stubs │ ├── Mail │ ├── NamespaceOne │ │ └── TestEmail.php │ ├── NamespaceTwo │ │ └── TestEmail.php │ ├── TestEmailForMailViewer.php │ ├── TestEmailWithDependencies.php │ ├── TestEmailWithNoConstructor.php │ └── TestEmailWithState.php │ └── Models │ └── Test.php └── views ├── index.blade.php └── stubs ├── emailtestview.blade.php ├── emailtestview_for_namespace_one.blade.php ├── emailtestview_for_namespace_two.blade.php └── emailtestview_withstate.blade.php /.github/workflows/run-tests.yml: -------------------------------------------------------------------------------- 1 | name: "Run Tests" 2 | 3 | on: [push] 4 | 5 | jobs: 6 | test: 7 | 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: true 11 | matrix: 12 | php: [7.3, 7.4] 13 | laravel: [6.*, 7.*] 14 | dependency-version: [prefer-lowest, prefer-stable] 15 | 16 | name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} 17 | 18 | steps: 19 | - name: Checkout code 20 | uses: actions/checkout@v1 21 | 22 | - name: Cache dependencies 23 | uses: actions/cache@v1 24 | with: 25 | path: ~/.composer/cache/files 26 | key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} 27 | 28 | - name: Setup PHP 29 | uses: shivammathur/setup-php@v1 30 | with: 31 | php-version: ${{ matrix.php }} 32 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick 33 | coverage: none 34 | 35 | - name: Install dependencies 36 | run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest 37 | 38 | - name: Execute tests 39 | run: vendor/bin/phpunit -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | .DS_Store 4 | Thumbs.db 5 | phpunit.xml 6 | .phpunit.result.cache 7 | /.idea -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | All notable changes to the Laravel Mail Viewer be documented in this file 2 | 3 | ## v7.0.0 (10-09-2020) 4 | - Added Laravel v8.x support. 5 | - Dropped Laravel v6 & PHPUnit v8 support. 6 | 7 | ## v6.0.0 (03-03-2020) 8 | - Added Laravel v7.x support. 9 | - Dropped PHP v7.2 support, now PHP v7.3 is the minimum requirement. 10 | 11 | ## v5.0.1 (14-01-2020) 12 | - Added Github Action Workflow for tests 13 | 14 | ## v5.0.0 (04-09-2019) 15 | - Now supports Laravel v6.0 16 | - Laravel v5.6.* & Laravel v5.7.* are no longer supported, min requirement is now v5.8.* 17 | - Support for Laravel v5.8.* will be dropped in v5.1.* 18 | 19 | ## v4.0.4 (06-03-2019) 20 | - The package now renders the correct mailable having similar class name as another mailable in different namespace. 21 | - Big thanks to [Thomas Kane](https://github.com/thomasjohnkane) for pointing out [this issue](https://github.com/JoggApp/laravel-mail-viewer/issues/18). 22 | 23 | ## v4.0.3 (27-02-2019) 24 | - Update travis config 25 | 26 | ## v4.0.2 (27-02-2019) 27 | - drop php v7.1 support 28 | 29 | ## v4.0.1 (27-02-2019) 30 | - phpunit update 31 | 32 | ## v4.0.0 (27-02-2019) 33 | - Now supports Laravel v5.8 34 | 35 | ## v3.1.0 (05-12-2018) 36 | - Fixed the behaviour of in_array by enabling strict checking. 37 | 38 | ## v3.0.0 (13-11-2018) 39 | - If the constructor dependency is not type hinted it will trust the user input in the config file as a replacement. [PR for this feature](https://github.com/JoggApp/laravel-mail-viewer/pull/15) 40 | - Big thanks & credits to [Junhai](https://github.com/starvsion) for making this possible :) 41 | 42 | ## v2.2.0 (11-10-2018) 43 | - The package now uses DB transactions. [PR for this feature](https://github.com/JoggApp/laravel-mail-viewer/pull/12) 44 | - Big thanks & credits to [Wouter Peschier](https://github.com/kielabokkie) for making this possible :) 45 | 46 | ## v2.1.1 (05-10-2018) 47 | - [Bug fix](https://github.com/JoggApp/laravel-mail-viewer/pull/11) 48 | 49 | ## v2.1.0 (05-10-2018) 50 | - We can now define the [factory states](https://laravel.com/docs/5.7/database-testing#factory-states) to be used for any dependency of a mailable, if the dependency is an eloquent model. [PR for this feature](https://github.com/JoggApp/laravel-mail-viewer/pull/10) 51 | - Big thanks & credits to [Wouter Peschier](https://github.com/kielabokkie) for making this possible :) 52 | 53 | ## v2.0.2 (29-09-2018) 54 | - Fix class check and cover all data types. 55 | 56 | ## v2.0.1 (28-09-2018) 57 | - The package now attempts to instantiate non eloquent objects using the container if no factory exists. 58 | 59 | ## v2.0.0 (27-09-2018) 60 | - Major changes in how the mailables are registered in the config file. 61 | - Please read the comments in the config file for the 'mailable' key and update yours accordingly. 62 | - The config file is now cacheable as well as serializable. 63 | - Directory structure changed. 64 | 65 | ## v1.0.1 (20-09-2018) 66 | - Updated readme 67 | 68 | ## v1.0.0 (19-09-2018) 69 | - Added Tests 70 | - First major stable release 71 | 72 | ## v0.2.0 (07-09-2018) 73 | - Minor improvements 74 | 75 | ## v0.1.0 (07-09-2018) 76 | - Initial release -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Jogg Inc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This package has been archived and will no longer be maintained/updated. The reason being Laravel now itself provides a really convenient way to [preview mailables in the browser](https://laravel.com/docs/8.x/mail#rendering-mailables). 2 | 3 | # View all your mailables at a single place 4 | 5 | [![Latest Version](https://img.shields.io/github/release/JoggApp/laravel-mail-viewer.svg?style=flat-rounded)](https://github.com/JoggApp/laravel-mail-viewer/releases) 6 | ![](https://github.com/JoggApp/laravel-mail-viewer/workflows/Run%20Tests/badge.svg?branch=master) 7 | [![Total Downloads](https://img.shields.io/packagist/dt/JoggApp/laravel-mail-viewer.svg?style=flat-rounded&colorB=brightgreen)](https://packagist.org/packages/JoggApp/laravel-mail-viewer) 8 | 9 | The Design and content team members often need access to the emails your app will be sending out to the users. This is a fairly simple package that makes it possible and tries to minimize developer dependency. By using this package, you can have a dedicated route to view all your mailables at a single place. Having shareable URLs to view the mails makes the team co-ordination more smooth. 10 | 11 | ## Installation 12 | 13 | You can install this package via composer using this command: 14 | 15 | ```bash 16 | composer require joggapp/laravel-mail-viewer 17 | ``` 18 | 19 | The package will automatically register itself. 20 | 21 | You will have to add the mailables and configure the other settings using the package's config file in order to to use this package. Please read the comments/description for each config key thoroughly and set their values. You can publish the config file with: 22 | 23 | ```bash 24 | php artisan vendor:publish --provider="JoggApp\MailViewer\MailViewerServiceProvider" 25 | ``` 26 | 27 | This will create the package's config file called `mailviewer.php` in the `config` directory. These are the contents of the published config file: 28 | 29 | ```php 30 | return [ 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Only the mailables registered here can be accessed using this package 34 | |-------------------------------------------------------------------------- 35 | | 36 | | You have to add the mailables including their dependencies 37 | | in the following array. When asked for a mailable, the 38 | | package will search it here for its definition. 39 | | 40 | | Add the mailable definition as shown below in the example. 41 | | The mailable class will be the key and the dependencies 42 | | of the mailable class will be defined in an array as well. 43 | | 44 | | The package will look for the equivalent factory if the 45 | | dependency is an eloquent model. So don't forget to 46 | | create those factories. If you want a specific state to 47 | | be used for your dependency you will have to pass an array 48 | | with 'class' and 'states' keys. The class key will have the 49 | | name of the dependency and states should contain an array of 50 | | factory states you want to apply to the factory, see the 51 | | MailWithDependencyStates example below. 52 | | 53 | | Please note that the factory times/count feature isn't 54 | | supported for the factories. 55 | | Eg: 56 | | What the package supports: factory(Order::class)->create(); 57 | | What the package doesn't support: factory(Order::class, 5)->create(); 58 | | 59 | | The package will try to resolve all other non-eloquent objects 60 | | using the Laravel's service container. 61 | | 62 | | Also, don't forget to import these classes at the top :) 63 | | 64 | | eg: 65 | | 'mailables' => [ 66 | | OrderShipped::class => [ 67 | | Order::class, 68 | | 'Personal thank you message', 69 | | ], 70 | | MailWithDependencyStates::class => [ 71 | | [ 72 | | 'class' => Order::class, 73 | | 'states' => ['state1', 'state2'] 74 | | ] 75 | | ], 76 | | MailWithNoDependency::class => [] 77 | | ] 78 | | 79 | */ 80 | 81 | 'mailables' => [], 82 | 83 | /* 84 | |-------------------------------------------------------------------------- 85 | | URL where you want to view the mails 86 | |-------------------------------------------------------------------------- 87 | | 88 | | This is the URL where you can view all the 89 | | mailables registered above. 90 | | 91 | */ 92 | 93 | 'url' => 'mails', 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | The environments in which the url should be accessible 98 | |-------------------------------------------------------------------------- 99 | | 100 | | If you don't want to use this package in production env 101 | | at all, you can restrict that using this option 102 | | rather than by using a middleware. 103 | | 104 | */ 105 | 106 | 'allowed_environments' => ['local', 'staging', 'testing'], 107 | 108 | /* 109 | |-------------------------------------------------------------------------- 110 | | Middlewares that should be applied to the URL 111 | |-------------------------------------------------------------------------- 112 | | 113 | | The value should be an array of fully qualified 114 | | class names of the middleware classes. 115 | | 116 | | Eg: [Authenticate::class, CheckForMaintenanceMode::class] 117 | | Don't forget to import the classes at the top! 118 | | 119 | */ 120 | 121 | 'middlewares' => [], 122 | ]; 123 | ``` 124 | 125 | ## How to use 126 | 127 | - After setting up the config values as described above, you can see the list of all mailables by visiting the `/mails` route (considering the default url is 'mails' in the config file). You can modify it to whatever you want as per your needs. 128 | 129 | - You can also restrict the environments the package should list the mailables in. By default, the `allowed_environments` config is set to allow 3 environments: `local`, `staging` & `testing`. You can further secure it using the `middlewares` config. 130 | 131 | - Default view: 132 | 133 | List of all mails | A particular mail rendered 134 | :-------------------------:|:-------------------------: 135 | ![](https://user-images.githubusercontent.com/11228182/45781093-bb59ef00-bc7c-11e8-9d03-64cf245fd82c.png) | ![](https://user-images.githubusercontent.com/11228182/45780701-c3fdf580-bc7b-11e8-9f48-0d883a640010.png) 136 | 137 | - This package supports the option of overriding the package views that Laravel provides. You can modify the view using [these instructions from the Laravel docs](https://laravel.com/docs/packages#views), as per your needs. 138 | 139 | ## Testing 140 | 141 | You can run the tests with: 142 | 143 | ```bash 144 | vendor/bin/phpunit 145 | ``` 146 | 147 | ## Changelog 148 | 149 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 150 | 151 | ## Security 152 | 153 | If you discover any security related issues, please email [harish@jogg.co](mailto:harish@jogg.co) instead of using the issue tracker. 154 | 155 | ## Credits 156 | 157 | - [Harish Toshniwal](https://github.com/introwit) 158 | - [All Contributors](../../contributors) 159 | 160 | ## License 161 | 162 | The MIT License (MIT). Please see [License File](LICENSE.txt) for more information. 163 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "joggapp/laravel-mail-viewer", 3 | "description": "View all your mailables at a single place", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Harish Toshniwal", 8 | "email": "harish@jogg.co" 9 | } 10 | ], 11 | "autoload": { 12 | "psr-4": { 13 | "JoggApp\\MailViewer\\": "src" 14 | } 15 | }, 16 | "autoload-dev": { 17 | "psr-4": { 18 | "JoggApp\\MailViewer\\Tests\\": "tests" 19 | } 20 | }, 21 | "require": { 22 | "php": "^7.3", 23 | "illuminate/routing": "7.*|8.*", 24 | "illuminate/support": "7.*|8.*", 25 | "illuminate/database": "7.*|8.*" 26 | }, 27 | "require-dev": { 28 | "laravel/legacy-factories": "^1.0.4", 29 | "mockery/mockery": "^1.1", 30 | "orchestra/testbench": "5.*|6.*", 31 | "phpunit/phpunit": "^9.0" 32 | }, 33 | "extra": { 34 | "laravel": { 35 | "providers": [ 36 | "JoggApp\\MailViewer\\MailViewerServiceProvider" 37 | ] 38 | } 39 | }, 40 | "config": { 41 | "sort-packages": true 42 | }, 43 | "minimum-stability": "dev", 44 | "prefer-stable": true 45 | } 46 | -------------------------------------------------------------------------------- /config/mailviewer.php: -------------------------------------------------------------------------------- 1 | create(); 30 | | What the package doesn't support: factory(Order::class, 5)->create(); 31 | | 32 | | The package will try to resolve all other non-eloquent objects 33 | | using the Laravel's service container. 34 | | 35 | | Also, don't forget to import these classes at the top :) 36 | | 37 | | eg: 38 | | 'mailables' => [ 39 | | OrderShipped::class => [ 40 | | Order::class, 41 | | 'Personal thank you message', 42 | | ], 43 | | MailWithDependencyStates::class => [ 44 | | [ 45 | | 'class' => Order::class, 46 | | 'states' => ['state1', 'state2'] 47 | | ] 48 | | ], 49 | | MailWithNoDependency::class => [] 50 | | ] 51 | | 52 | */ 53 | 54 | 'mailables' => [], 55 | 56 | /* 57 | |-------------------------------------------------------------------------- 58 | | URL where you want to view the mails 59 | |-------------------------------------------------------------------------- 60 | | 61 | | This is the URL where you can view all the 62 | | mailables registered above. 63 | | 64 | */ 65 | 66 | 'url' => 'mails', 67 | 68 | /* 69 | |-------------------------------------------------------------------------- 70 | | The environments in which the url should be accessible 71 | |-------------------------------------------------------------------------- 72 | | 73 | | If you don't want to use this package in production env 74 | | at all, you can restrict that using this option 75 | | rather than by using a middleware. 76 | | 77 | */ 78 | 79 | 'allowed_environments' => ['local', 'staging', 'testing'], 80 | 81 | /* 82 | |-------------------------------------------------------------------------- 83 | | Middlewares that should be applied to the URL 84 | |-------------------------------------------------------------------------- 85 | | 86 | | The value should be an array of fully qualified 87 | | class names of the middleware classes. 88 | | 89 | | Eg: [Authenticate::class, CheckForMaintenanceMode::class] 90 | | Don't forget to import the classes at the top! 91 | | 92 | */ 93 | 94 | 'middlewares' => [], 95 | ]; 96 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ./src 6 | 7 | 8 | 9 | 10 | ./tests 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | middleware(MailViewer::middlewares()); 8 | 9 | Route::get(MailViewer::url() . '/{mail}', 'JoggApp\MailViewer\Controllers\MailViewerController@show') 10 | ->middleware(MailViewer::middlewares()) 11 | ->name('mv-mailviewer'); 12 | -------------------------------------------------------------------------------- /src/Controllers/MailViewerController.php: -------------------------------------------------------------------------------- 1 | $dependencies) { 42 | $reflection = new ReflectionClass($mailable); 43 | 44 | if ($reflection->getName() === $mail) { 45 | $args = []; 46 | 47 | foreach ($dependencies as $dependency) { 48 | $factoryStates = []; 49 | 50 | if (is_array($dependency)) { 51 | if (in_array('states', array_keys($dependency), true)) { 52 | $factoryStates = $dependency['states']; 53 | $dependency = $dependency['class']; 54 | } 55 | } 56 | 57 | if (is_string($dependency) && class_exists($dependency)) { 58 | if (isset($eloquentFactory[$dependency])) { 59 | $args[] = factory($dependency)->states($factoryStates)->create(); 60 | } else { 61 | $args[] = app($dependency); 62 | } 63 | } else { 64 | $args[] = $dependency; 65 | } 66 | } 67 | 68 | return new $mailable(...$args); 69 | } 70 | 71 | DB::rollBack(); 72 | } 73 | 74 | throw new Exception("No mailable called {$mail} is registered in config/mailviewer.php file"); 75 | } 76 | 77 | public static function prepareMails(array $mailables): array 78 | { 79 | $mails = []; 80 | 81 | foreach ($mailables as $mailable => $dependencies) { 82 | $reflection = new ReflectionClass($mailable); 83 | 84 | $givenParameters = []; 85 | 86 | foreach ($dependencies as $dependency) { 87 | if (is_array($dependency)) { 88 | if (in_array('states', array_keys($dependency), true)) { 89 | $dependency = $dependency['class']; 90 | } 91 | } 92 | 93 | $givenParameters[] = is_string($dependency) && class_exists($dependency) 94 | ? (new ReflectionClass($dependency))->getName() 95 | : getType($dependency); 96 | } 97 | 98 | $constructorParameters = []; 99 | 100 | if ($reflection->getConstructor()) { 101 | for ($i = 0; $i < count($reflection->getConstructor()->getParameters()); $i++) { 102 | $parameter = $reflection->getConstructor()->getParameters()[$i]; 103 | 104 | if (empty($parameter->getType())) { 105 | $constructorParameters[$i] = $givenParameters[$i]; 106 | continue; 107 | } 108 | 109 | $constructorParameters[] = $parameter->getType()->getName() == 'int' ? 'integer' : $parameter->getType()->getName(); 110 | } 111 | } 112 | 113 | if ($constructorParameters !== $givenParameters) { 114 | throw new Exception( 115 | "The arguments passed for {$mailable} in the config/mailviewer.php file do not match with the constructor 116 | params of the {$mailable} class or the constructor params of the {$mailable} class aren't typehinted" 117 | ); 118 | } 119 | 120 | $mails[] = $reflection->getName(); 121 | } 122 | 123 | return $mails; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/MailViewerServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 12 | __DIR__ . '/../config/mailviewer.php' => config_path('mailviewer.php'), 13 | ]); 14 | 15 | $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); 16 | 17 | $this->loadViewsFrom(__DIR__ . '/../views', 'mailviewer'); 18 | } 19 | 20 | public function register() 21 | { 22 | // 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/BaseTestCase.php: -------------------------------------------------------------------------------- 1 | withFactories(__DIR__ . '/Database/Factories'); 22 | 23 | $this->loadMigrationsFrom(__DIR__ . '/Database/Migrations'); 24 | 25 | $this->artisan('migrate', ['--database' => 'testing']); 26 | } 27 | 28 | protected function getPackageProviders($app) 29 | { 30 | return [MailViewerServiceProvider::class]; 31 | } 32 | 33 | protected function getEnvironmentSetUp($app) 34 | { 35 | $app['config']->set('app.env', 'local'); 36 | 37 | $app['config']->set( 38 | 'mailviewer.mailables', 39 | [ 40 | TestEmailForMailViewer::class => [], 41 | TestEmailWithNoConstructor::class => [], 42 | TestEmailWithDependencies::class => [ 43 | [], 44 | \stdClass::class, 45 | 'Some name', 46 | 7, 47 | null 48 | ], 49 | TestEmailWithState::class => [ 50 | [ 51 | 'class' => Test::class, 52 | 'states' => ['is-awesome'] 53 | ] 54 | ], 55 | TestEmailInNamespaceOne::class => [], 56 | TestEmailInNamespaceTwo::class => [] 57 | ] 58 | ); 59 | 60 | $app['config']->set('mailviewer.url', 'mails'); 61 | $app['config']->set('mailviewer.allowed_environments', ['local', 'staging', 'testing']); 62 | $app['config']->set('mailviewer.middlewares', []); 63 | 64 | $app['config']->set('database.default', 'testbench'); 65 | $app['config']->set('database.connections.testbench', [ 66 | 'driver' => 'sqlite', 67 | 'database' => ':memory:', 68 | 'prefix' => '', 69 | ]); 70 | 71 | $app['config']->set('app.debug', env('APP_DEBUG', true)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tests/Database/Factories/TestFactory.php: -------------------------------------------------------------------------------- 1 | define(Test::class, function () { 8 | return [ 9 | 'is_awesome' => 'no' 10 | ]; 11 | }); 12 | 13 | $factory->state(Test::class, 'is-awesome', [ 14 | 'is_awesome' => 'yes' 15 | ]); 16 | -------------------------------------------------------------------------------- /tests/Database/Migrations/2018_10_10_131000_add_test_table.php: -------------------------------------------------------------------------------- 1 | boolean('is_awesome'); 18 | }); 19 | } 20 | 21 | /** 22 | * Reverse the migrations. 23 | * 24 | * @return void 25 | */ 26 | public function down() 27 | { 28 | Schema::dropIfExists('tests'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/MailViewerTest.php: -------------------------------------------------------------------------------- 1 | packageUrl = config('mailviewer.url'); 14 | 15 | $router = $this->app['router']; 16 | 17 | $middlewares = config('mailviewer.middlewares'); 18 | 19 | $router->get($this->packageUrl, 'JoggApp\MailViewer\Controllers\MailViewerController@index') 20 | ->middleware($middlewares); 21 | 22 | $router->get($this->packageUrl . '/{mail}', 'JoggApp\MailViewer\Controllers\MailViewerController@show') 23 | ->middleware($middlewares) 24 | ->name('mv-mailviewer'); 25 | } 26 | 27 | /** @test */ 28 | public function it_lists_all_the_mailables_on_the_url_configured_in_config_file() 29 | { 30 | $this->get($this->packageUrl) 31 | ->assertSee('All Mails') 32 | ->assertSee('TestEmailForMailViewer'); 33 | } 34 | 35 | /** @test */ 36 | public function it_renders_the_mailable_without_dependencies_on_its_dedicated_route() 37 | { 38 | $this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\TestEmailForMailViewer')) 39 | ->assertSee('The test email view'); 40 | } 41 | 42 | /** @test */ 43 | public function it_renders_the_mailable_without_dependencies_or_constructor_on_its_dedicated_route() 44 | { 45 | $this->get('/mails') 46 | ->assertSee('All Mails'); 47 | } 48 | 49 | /** @test */ 50 | public function it_renders_the_mailable_with_dependencies_on_its_dedicated_route() 51 | { 52 | $this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\TestEmailWithDependencies')) 53 | ->assertSee('The test email view'); 54 | } 55 | 56 | /** @test */ 57 | public function it_renders_the_mailable_with_state_on_its_dedicated_route() 58 | { 59 | $this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\TestEmailWithState')) 60 | ->assertSee('The test email view') 61 | ->assertSee('Is awesome: yes'); 62 | } 63 | 64 | /** @test */ 65 | public function it_renders_the_correct_mailable_having_similar_class_name_as_another_mailable_in_different_namespace() 66 | { 67 | $this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\NamespaceOne\TestEmail')) 68 | ->assertSee('The test email view for email in namespace one.'); 69 | 70 | $this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\NamespaceTwo\TestEmail')) 71 | ->assertSee('The test email view for email in namespace two.'); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tests/Stubs/Mail/NamespaceOne/TestEmail.php: -------------------------------------------------------------------------------- 1 | view('mailviewer::stubs.emailtestview_for_namespace_one'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Stubs/Mail/NamespaceTwo/TestEmail.php: -------------------------------------------------------------------------------- 1 | view('mailviewer::stubs.emailtestview_for_namespace_two'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Stubs/Mail/TestEmailForMailViewer.php: -------------------------------------------------------------------------------- 1 | view('mailviewer::stubs.emailtestview'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Stubs/Mail/TestEmailWithDependencies.php: -------------------------------------------------------------------------------- 1 | view('mailviewer::stubs.emailtestview'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Stubs/Mail/TestEmailWithNoConstructor.php: -------------------------------------------------------------------------------- 1 | view('mailviewer::stubs.emailtestview'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Stubs/Mail/TestEmailWithState.php: -------------------------------------------------------------------------------- 1 | object = $object; 24 | } 25 | 26 | /** 27 | * Build the message. 28 | * 29 | * @return $this 30 | */ 31 | public function build() 32 | { 33 | return $this->view('mailviewer::stubs.emailtestview_withstate'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Stubs/Models/Test.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Laravel Mail Viewer 9 | 10 | 35 | 36 | 37 | @if(empty($mails)) 38 |

There are no mails

39 | @else 40 |
    41 |

    All Mails

    42 | @foreach($mails as $mail) 43 |
  1. {{ $mail }}
  2. 44 | @endforeach 45 |
46 | @endif 47 | 48 | -------------------------------------------------------------------------------- /views/stubs/emailtestview.blade.php: -------------------------------------------------------------------------------- 1 | The test email view -------------------------------------------------------------------------------- /views/stubs/emailtestview_for_namespace_one.blade.php: -------------------------------------------------------------------------------- 1 | The test email view for email in namespace one. -------------------------------------------------------------------------------- /views/stubs/emailtestview_for_namespace_two.blade.php: -------------------------------------------------------------------------------- 1 | The test email view for email in namespace two. -------------------------------------------------------------------------------- /views/stubs/emailtestview_withstate.blade.php: -------------------------------------------------------------------------------- 1 | The test email view 2 | 3 | Is awesome: {{ $object->is_awesome }} 4 | --------------------------------------------------------------------------------