Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Propaganistas committed Sep 5, 2023
1 parent 41d98f4 commit 5d3b267
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
8 changes: 5 additions & 3 deletions config/disposable-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
| JSON Source URLs
|--------------------------------------------------------------------------
|
| The source URL yielding a list of disposable email domains. Change this
| to whatever source you like. Just make sure it returns a JSON array.
| The source URLs yielding a list of disposable email domains. Change these
| to whatever source you like. Just make sure they all return a JSON array.
|
| A sensible default is provided using jsDelivr's services. jsDelivr is
| a free service, so there are no uptime or support guarantees.
|
*/

'sources' => ['https://cdn.jsdelivr.net/gh/disposable/disposable-email-domains@master/domains.json'],
'sources' => [
'https://cdn.jsdelivr.net/gh/disposable/disposable-email-domains@master/domains.json'
],

/*
|--------------------------------------------------------------------------
Expand Down
21 changes: 12 additions & 9 deletions src/Console/UpdateDisposableDomainsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UpdateDisposableDomainsCommand extends Command
*
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Propaganistas\LaravelDisposableEmail\DisposableDomains $disposable
* @return void
* @return int
*/
public function handle(Config $config, DisposableDomains $disposable)
{
Expand All @@ -40,17 +40,18 @@ public function handle(Config $config, DisposableDomains $disposable)

if (! $fetcher instanceof Fetcher) {
$this->error($fetcherClass . ' should implement ' . Fetcher::class);
return 1;
return Command::FAILURE;
}

$sources = $config->get('disposable-email.sources');

if (!$sources && $config->get('disposable-email.source')) {
$sources = [$config->get('disposable-email.source')];
}

if (! is_array($sources)) {
$this->error('Source URLs should be defined in an array');
return 1;
return Command::FAILURE;
}

$data = [];
Expand All @@ -62,13 +63,15 @@ public function handle(Config $config, DisposableDomains $disposable)

$this->line('Saving response to storage...');

if ($disposable->saveToStorage($data)) {
$this->info('Disposable domains list updated successfully.');
$disposable->bootstrap();
return 0;
} else {
if (! $disposable->saveToStorage($data)) {
$this->error('Could not write to storage (' . $disposable->getStoragePath() . ')!');
return 1;
return Command::FAILURE;
}

$this->info('Disposable domains list updated successfully.');

$disposable->bootstrap();

return Command::SUCCESS;
}
}
18 changes: 10 additions & 8 deletions tests/Console/UpdateDisposableDomainsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,29 @@ public function it_doesnt_overwrite_on_fetch_failure()
}

/** @test */
public function custom_fetchers_need_fetcher_contract()
public function it_can_use_a_custom_fetcher()
{
file_put_contents($this->storagePath, json_encode(['foo']));

$this->app['config']['disposable-email.sources'] = ['bar'];
$this->app['config']['disposable-email.fetcher'] = InvalidFetcher::class;
$this->app['config']['disposable-email.fetcher'] = CustomFetcher::class;

$this->artisan('disposable:update')
->assertExitCode(1);
->assertExitCode(0);

$this->assertFileExists($this->storagePath);

$domains = $this->disposable()->getDomains();
$this->assertNotEquals(['foo'], $domains);
$this->assertEquals(['bar'], $domains);
}

/** @test */
public function custom_source_is_not_array()
public function custom_fetchers_need_fetcher_contract()
{
file_put_contents($this->storagePath, json_encode(['foo']));

$this->app['config']['disposable-email.sources'] = 'bar';
$this->app['config']['disposable-email.sources'] = ['bar'];
$this->app['config']['disposable-email.fetcher'] = InvalidFetcher::class;

$this->artisan('disposable:update')
->assertExitCode(1);
Expand All @@ -94,11 +95,12 @@ public function custom_source_is_not_array()
}

/** @test */
public function it_can_use_a_custom_fetcher()
public function it_processes_legacy_source_config()
{
file_put_contents($this->storagePath, json_encode(['foo']));

$this->app['config']['disposable-email.sources'] = ['bar'];
$this->app['config']['disposable-email.sources'] = null;
$this->app['config']['disposable-email.source'] = 'bar';
$this->app['config']['disposable-email.fetcher'] = CustomFetcher::class;

$this->artisan('disposable:update')
Expand Down

0 comments on commit 5d3b267

Please sign in to comment.