Skip to content

Commit

Permalink
Merge branch '11.x' into feat/middleware-priority-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieread authored Oct 30, 2024
2 parents 070226f + 17acf83 commit d365fa7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Illuminate/Foundation/Console/MailMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ protected function writeMarkdownTemplate()
str_replace('.', '/', $this->getView()).'.blade.php'
);

if ($this->files->exists($path)) {
return $this->components->error(sprintf('%s [%s] already exists.', 'Markdown view', $path));
}

$this->files->ensureDirectoryExists(dirname($path));

$this->files->put($path, file_get_contents(__DIR__.'/stubs/markdown.stub'));
Expand All @@ -88,6 +92,10 @@ protected function writeView()
str_replace('.', '/', $this->getView()).'.blade.php'
);

if ($this->files->exists($path)) {
return $this->components->error(sprintf('%s [%s] already exists.', 'View', $path));
}

$this->files->ensureDirectoryExists(dirname($path));

$stub = str_replace(
Expand Down
51 changes: 51 additions & 0 deletions tests/Integration/Generators/MailMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ public function testItCanGenerateMailFileWithMarkdownOption()
], 'resources/views/foo-mail.blade.php');
}

public function testErrorsWillBeDisplayedWhenMarkdownsAlreadyExist()
{
$existingMarkdownPath = 'resources/views/existing-markdown.blade.php';
$this->app['files']
->put(
$this->app->basePath($existingMarkdownPath),
'<x-mail::message>My existing markdown</x-mail::message>'
);
$this->artisan('make:mail', ['name' => 'FooMail', '--markdown' => 'existing-markdown'])
->expectsOutputToContain('already exists.')
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Mail;',
'use Illuminate\Mail\Mailable;',
'class FooMail extends Mailable',
'return new Content(',
"markdown: 'existing-markdown',",
], 'app/Mail/FooMail.php');
$this->assertFileContains([
'<x-mail::message>',
'My existing markdown',
'</x-mail::message>',
], $existingMarkdownPath);
}

public function testItCanGenerateMailFileWithViewOption()
{
$this->artisan('make:mail', ['name' => 'FooMail', '--view' => 'foo-mail'])
Expand All @@ -63,6 +89,31 @@ public function testItCanGenerateMailFileWithViewOption()
$this->assertFilenameExists('resources/views/foo-mail.blade.php');
}

public function testErrorsWillBeDisplayedWhenViewsAlreadyExist()
{
$existingViewPath = 'resources/views/existing-template.blade.php';
$this->app['files']
->put(
$this->app->basePath($existingViewPath),
'<div>My existing template</div>'
);
$this->artisan('make:mail', ['name' => 'FooMail', '--view' => 'existing-template'])
->expectsOutputToContain('already exists.')
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Mail;',
'use Illuminate\Mail\Mailable;',
'class FooMail extends Mailable',
'return new Content(',
"view: 'existing-template',",
], 'app/Mail/FooMail.php');
$this->assertFilenameExists($existingViewPath);
$this->assertFileContains([
'<div>My existing template</div>',
], $existingViewPath);
}

public function testItCanGenerateMailFileWithTest()
{
$this->artisan('make:mail', ['name' => 'FooMail', '--test' => true])
Expand Down

0 comments on commit d365fa7

Please sign in to comment.