Skip to content

Commit

Permalink
render the correct mailable having similar class name in diff namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
introwit committed Mar 6, 2019
1 parent e2f6de0 commit e8c3b16
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
All notable changes to the Laravel Mail Viewer be documented in this file

## v4.0.4 (06-03-2019)
- The package now renders the correct mailable having similar class name as another mailable in different namespace.
- Big thanks to [Thomas Kane](https://github.com/thomasjohnkane) for pointing out [this issue](https://github.com/JoggApp/laravel-mail-viewer/issues/18).

## v4.0.3 (27-02-2019)
- Update travis config

Expand Down
4 changes: 2 additions & 2 deletions src/MailViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function find(string $mail)
foreach (config('mailviewer.mailables', []) as $mailable => $dependencies) {
$reflection = new ReflectionClass($mailable);

if ($reflection->getShortName() === $mail) {
if ($reflection->getName() === $mail) {
$args = [];

foreach ($dependencies as $dependency) {
Expand Down Expand Up @@ -115,7 +115,7 @@ public static function prepareMails(array $mailables): array
);
}

$mails[] = $reflection->getShortName();
$mails[] = $reflection->getName();
}

return $mails;
Expand Down
6 changes: 5 additions & 1 deletion tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace JoggApp\MailViewer\Tests;

use JoggApp\MailViewer\MailViewerServiceProvider;
use JoggApp\MailViewer\Tests\Stubs\Mail\NamespaceOne\TestEmail as TestEmailInNamespaceOne;
use JoggApp\MailViewer\Tests\Stubs\Mail\NamespaceTwo\TestEmail as TestEmailInNamespaceTwo;
use JoggApp\MailViewer\Tests\Stubs\Mail\TestEmailForMailViewer;
use JoggApp\MailViewer\Tests\Stubs\Mail\TestEmailWithDependencies;
use JoggApp\MailViewer\Tests\Stubs\Mail\TestEmailWithState;
Expand Down Expand Up @@ -50,7 +52,9 @@ protected function getEnvironmentSetUp($app)
'class' => Test::class,
'states' => ['is-awesome']
]
]
],
TestEmailInNamespaceOne::class => [],
TestEmailInNamespaceTwo::class => []
]
);

Expand Down
16 changes: 13 additions & 3 deletions tests/MailViewerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,32 @@ public function it_lists_all_the_mailables_on_the_url_configured_in_config_file(
/** @test */
public function it_renders_the_mailable_without_dependencies_on_its_dedicated_route()
{
$this->get(route('mv-mailviewer', 'TestEmailForMailViewer'))
$this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\TestEmailForMailViewer'))
->assertSee('The test email view');
}

/** @test */
public function it_renders_the_mailable_with_dependencies_on_its_dedicated_route()
{
$this->get(route('mv-mailviewer', 'TestEmailWithDependencies'))
$this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\TestEmailWithDependencies'))
->assertSee('The test email view');
}

/** @test */
public function it_renders_the_mailable_with_state_on_its_dedicated_route()
{
$this->get(route('mv-mailviewer', 'TestEmailWithState'))
$this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\TestEmailWithState'))
->assertSee('The test email view')
->assertSee('Is awesome: yes');
}

/** @test */
public function it_renders_the_correct_mailable_having_similar_class_name_as_another_mailable_in_different_namespace()
{
$this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\NamespaceOne\TestEmail'))
->assertSee('The test email view for email in namespace one.');

$this->get(route('mv-mailviewer', 'JoggApp\MailViewer\Tests\Stubs\Mail\NamespaceTwo\TestEmail'))
->assertSee('The test email view for email in namespace two.');
}
}
32 changes: 32 additions & 0 deletions tests/stubs/mail/NamespaceOne/TestEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace JoggApp\MailViewer\Tests\Stubs\Mail\NamespaceOne;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class TestEmail extends Mailable
{
use Queueable, SerializesModels;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mailviewer::stubs.emailtestview_for_namespace_one');
}
}
32 changes: 32 additions & 0 deletions tests/stubs/mail/NamespaceTwo/TestEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace JoggApp\MailViewer\Tests\Stubs\Mail\NamespaceTwo;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class TestEmail extends Mailable
{
use Queueable, SerializesModels;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mailviewer::stubs.emailtestview_for_namespace_two');
}
}
1 change: 1 addition & 0 deletions views/stubs/emailtestview_for_namespace_one.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The test email view for email in namespace one.
1 change: 1 addition & 0 deletions views/stubs/emailtestview_for_namespace_two.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The test email view for email in namespace two.

0 comments on commit e8c3b16

Please sign in to comment.