-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MakeExceptionCommand for API exceptions
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Nutgram\Laravel\Console; | ||
|
||
class MakeExceptionCommand extends BaseMakeCommand | ||
{ | ||
protected $signature = 'nutgram:make:exception {name : Exception name}'; | ||
|
||
protected $description = 'Create a new Nutgram API Exception'; | ||
|
||
/** | ||
* Return the sub directory name | ||
* @return string | ||
*/ | ||
protected function getSubDirName(): string | ||
{ | ||
return 'Exceptions'; | ||
} | ||
|
||
/** | ||
* Return the stub file path | ||
* @return string | ||
*/ | ||
protected function getStubPath(): string | ||
{ | ||
return __DIR__.'/../Stubs/Exception.stub'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Telegram\{{ namespace }}; | ||
|
||
use SergiX44\Nutgram\Exception\ApiException; | ||
use SergiX44\Nutgram\Nutgram; | ||
use SergiX44\Nutgram\Telegram\Exceptions\TelegramException; | ||
|
||
class {{ name }} extends ApiException | ||
{ | ||
public static ?string $pattern = '.*enter a string contained in the api error message.*'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\File; | ||
use Nutgram\Laravel\Console\MakeExceptionCommand; | ||
|
||
beforeEach(function () { | ||
File::deleteDirectory(config('nutgram.namespace')); | ||
}); | ||
|
||
test('nutgram:make:exception makes an exception', function () { | ||
$this->artisan(MakeExceptionCommand::class, ['name' => 'MyException']) | ||
->expectsOutput('Nutgram Exception created successfully.') | ||
->assertSuccessful(); | ||
|
||
expect(config('nutgram.namespace').'/Exceptions/MyException.php') | ||
->toBeFile() | ||
->getFileContent() | ||
->toContain('class MyException'); | ||
}); |