Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jan 28, 2017
1 parent 1ee71b5 commit 37d1e0a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2,6 +2,6 @@

All notable changes to `laravel-mailable-test` will be documented in this file

## 1.0.0 - 201X-XX-XX
## 1.0.0 - 2017-XX-XX

- initial release
4 changes: 2 additions & 2 deletions README.md
@@ -1,4 +1,4 @@
# Very short description of the package
# An artisan command to easily test a mailable

[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-mailable-test.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-mailable-test)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
Expand All @@ -8,7 +8,7 @@
[![StyleCI](https://styleci.io/repos/80032119/shield?branch=master)](https://styleci.io/repos/80032119)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-mailable-test.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-mailable-test)

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.


## Postcardware

Expand Down
14 changes: 14 additions & 0 deletions src/Exceptions/InvalidConfiguration.php
@@ -0,0 +1,14 @@
<?php

namespace Spatie\MailableTest\Exceptions;

use Exception;
use Spatie\MailableTest\ArgumentValueProvider;

class InvalidConfiguration extends Exception
{
public static function invalidValueProviderClass(string $className)
{
return new static("The `argument_value_provider_class` config value is invalid. Given class `{$className}` does not extend `" . ArgumentValueProvider::class . "`.");
}
}
9 changes: 8 additions & 1 deletion src/MailableTestServiceProvider.php
Expand Up @@ -2,7 +2,9 @@

namespace Spatie\MailableTest;

use Faker\Factory;
use Illuminate\Support\ServiceProvider;
use Spatie\MailableTest\Exceptions\InvalidConfiguration;

class MailableTestServiceProvider extends ServiceProvider
{
Expand All @@ -21,13 +23,18 @@ public function register()

$argumentValueProviderClass = config('laravel-mailable-test.argument_value_provider_class');

if (! is_a($argumentValueProviderClass, ArgumentValueProvider::class, true)) {

throw InvalidConfiguration::invalidValueProviderClass($argumentValueProviderClass);
}

$argumentValueProvider = app($argumentValueProviderClass);

return new MailableFactory($argumentValueProvider);
});

$this->app->bind(ArgumentValueProvider::class, function() {
$faker = \Faker\Factory::create();
$faker = Factory::create();

return new ArgumentValueProvider($faker);
});
Expand Down
23 changes: 23 additions & 0 deletions tests/ConfigTest.php
@@ -0,0 +1,23 @@
<?php

namespace Spatie\MailableTest\Test;

use Mail;
use Artisan;
use Spatie\MailableTest\Exceptions\InvalidConfiguration;

class ConfigTest extends TestCase
{
/** @test */
public function it_will_throw_an_exception_if_argument_value_provider_class_contains_an_invalid_class()
{
$this->expectException(InvalidConfiguration::class);

$this->app['config']->set('laravel-mailable-test.argument_value_provider_class', '');

Artisan::call('mail:send-test', [
'mailableClass' => TestMailable::class,
'recipient' => 'test@mail.com'
]);
}
}

0 comments on commit 37d1e0a

Please sign in to comment.