diff --git a/config/disposable-email.php b/config/disposable-email.php index e159947..e555078 100644 --- a/config/disposable-email.php +++ b/config/disposable-email.php @@ -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' + ], /* |-------------------------------------------------------------------------- diff --git a/src/Console/UpdateDisposableDomainsCommand.php b/src/Console/UpdateDisposableDomainsCommand.php index f6abe85..1e31c44 100644 --- a/src/Console/UpdateDisposableDomainsCommand.php +++ b/src/Console/UpdateDisposableDomainsCommand.php @@ -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) { @@ -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 = []; @@ -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; } } diff --git a/tests/Console/UpdateDisposableDomainsCommandTest.php b/tests/Console/UpdateDisposableDomainsCommandTest.php index 4bcb11a..9ee337b 100644 --- a/tests/Console/UpdateDisposableDomainsCommandTest.php +++ b/tests/Console/UpdateDisposableDomainsCommandTest.php @@ -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); @@ -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')