Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Illuminate\Tests\Notifications; use Illuminate\Contracts\Mail\Attachable..

Decoded Output download

<?php

namespace Illuminate\Tests\Notifications;

use Illuminate\Contracts\Mail\Attachable;
use Illuminate\Mail\Attachment;
use Illuminate\Notifications\Messages\MailMessage;
use PHPUnit\Framework\TestCase;

class NotificationMailMessageTest extends TestCase
{
    public function testTemplate()
    {
        $message = new MailMessage;

        $this->assertSame('notifications::email', $message->markdown);

        $message->template('notifications::foo');

        $this->assertSame('notifications::foo', $message->markdown);
    }

    public function testHtmlAndPlainView()
    {
        $message = new MailMessage;

        $this->assertNull($message->view);
        $this->assertSame([], $message->viewData);

        $message->view(['notifications::foo', 'notifications::bar'], [
            'foo' => 'bar',
        ]);

        $this->assertSame('notifications::foo', $message->view[0]);
        $this->assertSame('notifications::bar', $message->view[1]);
        $this->assertSame(['foo' => 'bar'], $message->viewData);
    }

    public function testHtmlView()
    {
        $message = new MailMessage;

        $this->assertNull($message->view);
        $this->assertSame([], $message->viewData);

        $message->view('notifications::foo', [
            'foo' => 'bar',
        ]);

        $this->assertSame('notifications::foo', $message->view);
        $this->assertSame(['foo' => 'bar'], $message->viewData);
    }

    public function testPlainView()
    {
        $message = new MailMessage;

        $this->assertNull($message->view);
        $this->assertSame([], $message->viewData);

        $message->view([null, 'notifications::foo'], [
            'foo' => 'bar',
        ]);

        $this->assertSame('notifications::foo', $message->view[1]);
        $this->assertSame(['foo' => 'bar'], $message->viewData);
    }

    public function testCcIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->cc('[email protected]');

        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->cc('[email protected]')
                ->cc('[email protected]', 'Test');

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->cc);

        $message = new MailMessage;
        $message->cc(['[email protected]', 'Test' => '[email protected]']);

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->cc);
    }

    public function testBccIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->bcc('[email protected]');

        $this->assertSame([['[email protected]', null]], $message->bcc);

        $message = new MailMessage;
        $message->bcc('[email protected]')
                ->bcc('[email protected]', 'Test');

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->bcc);

        $message = new MailMessage;
        $message->bcc(['[email protected]', 'Test' => '[email protected]']);

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->bcc);
    }

    public function testReplyToIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->replyTo('[email protected]');

        $this->assertSame([['[email protected]', null]], $message->replyTo);

        $message = new MailMessage;
        $message->replyTo('[email protected]')
                ->replyTo('[email protected]', 'Test');

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->replyTo);

        $message = new MailMessage;
        $message->replyTo(['[email protected]', 'Test' => '[email protected]']);

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->replyTo);
    }

    public function testMetadataIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->metadata('origin', 'test-suite');
        $message->metadata('user_id', 1);

        $this->assertArrayHasKey('origin', $message->metadata);
        $this->assertSame('test-suite', $message->metadata['origin']);
        $this->assertArrayHasKey('user_id', $message->metadata);
        $this->assertSame(1, $message->metadata['user_id']);
    }

    public function testTagIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->tag('test');

        $this->assertContains('test', $message->tags);
    }

    public function testCallbackIsSetCorrectly()
    {
        $callback = function () {
            //
        };

        $message = new MailMessage;
        $message->withSymfonyMessage($callback);

        $this->assertSame([$callback], $message->callbacks);
    }

    public function testWhenCallback()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertTrue($condition);

            $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->when(true, $callback);
        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->when(false, $callback);
        $this->assertSame([], $message->cc);
    }

    public function testWhenCallbackWithReturn()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertTrue($condition);

            return $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->when(true, $callback)->bcc('[email protected]');
        $this->assertSame([['[email protected]', null]], $message->cc);
        $this->assertSame([['[email protected]', null]], $message->bcc);

        $message = new MailMessage;
        $message->when(false, $callback)->bcc('[email protected]');
        $this->assertSame([], $message->cc);
        $this->assertSame([['[email protected]', null]], $message->bcc);
    }

    public function testWhenCallbackWithDefault()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertSame('truthy', $condition);

            $mailMessage->cc('[email protected]');
        };

        $default = function (MailMessage $mailMessage, $condition) {
            $this->assertEquals(0, $condition);

            $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->when('truthy', $callback, $default);
        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->when(0, $callback, $default);
        $this->assertSame([['[email protected]', null]], $message->cc);
    }

    public function testUnlessCallback()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertFalse($condition);

            $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->unless(false, $callback);
        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->unless(true, $callback);
        $this->assertSame([], $message->cc);
    }

    public function testUnlessCallbackWithReturn()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertFalse($condition);

            return $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->unless(false, $callback)->bcc('[email protected]');
        $this->assertSame([['[email protected]', null]], $message->cc);
        $this->assertSame([['[email protected]', null]], $message->bcc);

        $message = new MailMessage;
        $message->unless(true, $callback)->bcc('[email protected]');
        $this->assertSame([], $message->cc);
        $this->assertSame([['[email protected]', null]], $message->bcc);
    }

    public function testUnlessCallbackWithDefault()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertEquals(0, $condition);

            $mailMessage->cc('[email protected]');
        };

        $default = function (MailMessage $mailMessage, $condition) {
            $this->assertSame('truthy', $condition);

            $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->unless(0, $callback, $default);
        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->unless('truthy', $callback, $default);
        $this->assertSame([['[email protected]', null]], $message->cc);
    }

    public function testItAttachesFilesViaAttachableContractFromPath()
    {
        $message = new MailMessage;

        $message->attach(new class() implements Attachable
        {
            public function toMailAttachment()
            {
                return Attachment::fromPath('/foo.jpg')->as('bar')->withMime('image/png');
            }
        });

        $this->assertSame([
            'file' => '/foo.jpg',
            'options' => [
                'as' => 'bar',
                'mime' => 'image/png',
            ],
        ], $message->attachments[0]);
    }

    public function testItAttachesFilesViaAttachableContractFromData()
    {
        $mailMessage = new MailMessage();

        $mailMessage->attach(new class() implements Attachable
        {
            public function toMailAttachment()
            {
                return Attachment::fromData(fn () => 'bar', 'foo.jpg')->withMime('image/png');
            }
        });

        $this->assertSame([
            'data' => 'bar',
            'name' => 'foo.jpg',
            'options' => [
                'mime' => 'image/png',
            ],
        ], $mailMessage->rawAttachments[0]);
    }

    public function testItAttachesManyFiles()
    {
        $mailMessage = new MailMessage();
        $attachable = new class() implements Attachable
        {
            public function toMailAttachment()
            {
                return Attachment::fromData(fn () => 'bar', 'foo.jpg')->withMime('image/png');
            }
        };

        $mailMessage->attachMany([
            $attachable,
            '/path/to/forge.svg',
            '/path/to/vapor.svg' => [
                'as' => 'Logo.svg',
                'mime' => 'image/svg+xml',
            ],
        ]);

        $this->assertSame([
            [
                'data' => 'bar',
                'name' => 'foo.jpg',
                'options' => [
                    'mime' => 'image/png',
                ],
            ],
        ], $mailMessage->rawAttachments);

        $this->assertSame([
            [
                'file' => '/path/to/forge.svg',
                'options' => [],
            ],
            [
                'file' => '/path/to/vapor.svg',
                'options' => [
                    'as' => 'Logo.svg',
                    'mime' => 'image/svg+xml',
                ],
            ],
        ], $mailMessage->attachments);
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

namespace Illuminate\Tests\Notifications;

use Illuminate\Contracts\Mail\Attachable;
use Illuminate\Mail\Attachment;
use Illuminate\Notifications\Messages\MailMessage;
use PHPUnit\Framework\TestCase;

class NotificationMailMessageTest extends TestCase
{
    public function testTemplate()
    {
        $message = new MailMessage;

        $this->assertSame('notifications::email', $message->markdown);

        $message->template('notifications::foo');

        $this->assertSame('notifications::foo', $message->markdown);
    }

    public function testHtmlAndPlainView()
    {
        $message = new MailMessage;

        $this->assertNull($message->view);
        $this->assertSame([], $message->viewData);

        $message->view(['notifications::foo', 'notifications::bar'], [
            'foo' => 'bar',
        ]);

        $this->assertSame('notifications::foo', $message->view[0]);
        $this->assertSame('notifications::bar', $message->view[1]);
        $this->assertSame(['foo' => 'bar'], $message->viewData);
    }

    public function testHtmlView()
    {
        $message = new MailMessage;

        $this->assertNull($message->view);
        $this->assertSame([], $message->viewData);

        $message->view('notifications::foo', [
            'foo' => 'bar',
        ]);

        $this->assertSame('notifications::foo', $message->view);
        $this->assertSame(['foo' => 'bar'], $message->viewData);
    }

    public function testPlainView()
    {
        $message = new MailMessage;

        $this->assertNull($message->view);
        $this->assertSame([], $message->viewData);

        $message->view([null, 'notifications::foo'], [
            'foo' => 'bar',
        ]);

        $this->assertSame('notifications::foo', $message->view[1]);
        $this->assertSame(['foo' => 'bar'], $message->viewData);
    }

    public function testCcIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->cc('[email protected]');

        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->cc('[email protected]')
                ->cc('[email protected]', 'Test');

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->cc);

        $message = new MailMessage;
        $message->cc(['[email protected]', 'Test' => '[email protected]']);

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->cc);
    }

    public function testBccIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->bcc('[email protected]');

        $this->assertSame([['[email protected]', null]], $message->bcc);

        $message = new MailMessage;
        $message->bcc('[email protected]')
                ->bcc('[email protected]', 'Test');

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->bcc);

        $message = new MailMessage;
        $message->bcc(['[email protected]', 'Test' => '[email protected]']);

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->bcc);
    }

    public function testReplyToIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->replyTo('[email protected]');

        $this->assertSame([['[email protected]', null]], $message->replyTo);

        $message = new MailMessage;
        $message->replyTo('[email protected]')
                ->replyTo('[email protected]', 'Test');

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->replyTo);

        $message = new MailMessage;
        $message->replyTo(['[email protected]', 'Test' => '[email protected]']);

        $this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->replyTo);
    }

    public function testMetadataIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->metadata('origin', 'test-suite');
        $message->metadata('user_id', 1);

        $this->assertArrayHasKey('origin', $message->metadata);
        $this->assertSame('test-suite', $message->metadata['origin']);
        $this->assertArrayHasKey('user_id', $message->metadata);
        $this->assertSame(1, $message->metadata['user_id']);
    }

    public function testTagIsSetCorrectly()
    {
        $message = new MailMessage;
        $message->tag('test');

        $this->assertContains('test', $message->tags);
    }

    public function testCallbackIsSetCorrectly()
    {
        $callback = function () {
            //
        };

        $message = new MailMessage;
        $message->withSymfonyMessage($callback);

        $this->assertSame([$callback], $message->callbacks);
    }

    public function testWhenCallback()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertTrue($condition);

            $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->when(true, $callback);
        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->when(false, $callback);
        $this->assertSame([], $message->cc);
    }

    public function testWhenCallbackWithReturn()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertTrue($condition);

            return $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->when(true, $callback)->bcc('[email protected]');
        $this->assertSame([['[email protected]', null]], $message->cc);
        $this->assertSame([['[email protected]', null]], $message->bcc);

        $message = new MailMessage;
        $message->when(false, $callback)->bcc('[email protected]');
        $this->assertSame([], $message->cc);
        $this->assertSame([['[email protected]', null]], $message->bcc);
    }

    public function testWhenCallbackWithDefault()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertSame('truthy', $condition);

            $mailMessage->cc('[email protected]');
        };

        $default = function (MailMessage $mailMessage, $condition) {
            $this->assertEquals(0, $condition);

            $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->when('truthy', $callback, $default);
        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->when(0, $callback, $default);
        $this->assertSame([['[email protected]', null]], $message->cc);
    }

    public function testUnlessCallback()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertFalse($condition);

            $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->unless(false, $callback);
        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->unless(true, $callback);
        $this->assertSame([], $message->cc);
    }

    public function testUnlessCallbackWithReturn()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertFalse($condition);

            return $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->unless(false, $callback)->bcc('[email protected]');
        $this->assertSame([['[email protected]', null]], $message->cc);
        $this->assertSame([['[email protected]', null]], $message->bcc);

        $message = new MailMessage;
        $message->unless(true, $callback)->bcc('[email protected]');
        $this->assertSame([], $message->cc);
        $this->assertSame([['[email protected]', null]], $message->bcc);
    }

    public function testUnlessCallbackWithDefault()
    {
        $callback = function (MailMessage $mailMessage, $condition) {
            $this->assertEquals(0, $condition);

            $mailMessage->cc('[email protected]');
        };

        $default = function (MailMessage $mailMessage, $condition) {
            $this->assertSame('truthy', $condition);

            $mailMessage->cc('[email protected]');
        };

        $message = new MailMessage;
        $message->unless(0, $callback, $default);
        $this->assertSame([['[email protected]', null]], $message->cc);

        $message = new MailMessage;
        $message->unless('truthy', $callback, $default);
        $this->assertSame([['[email protected]', null]], $message->cc);
    }

    public function testItAttachesFilesViaAttachableContractFromPath()
    {
        $message = new MailMessage;

        $message->attach(new class() implements Attachable
        {
            public function toMailAttachment()
            {
                return Attachment::fromPath('/foo.jpg')->as('bar')->withMime('image/png');
            }
        });

        $this->assertSame([
            'file' => '/foo.jpg',
            'options' => [
                'as' => 'bar',
                'mime' => 'image/png',
            ],
        ], $message->attachments[0]);
    }

    public function testItAttachesFilesViaAttachableContractFromData()
    {
        $mailMessage = new MailMessage();

        $mailMessage->attach(new class() implements Attachable
        {
            public function toMailAttachment()
            {
                return Attachment::fromData(fn () => 'bar', 'foo.jpg')->withMime('image/png');
            }
        });

        $this->assertSame([
            'data' => 'bar',
            'name' => 'foo.jpg',
            'options' => [
                'mime' => 'image/png',
            ],
        ], $mailMessage->rawAttachments[0]);
    }

    public function testItAttachesManyFiles()
    {
        $mailMessage = new MailMessage();
        $attachable = new class() implements Attachable
        {
            public function toMailAttachment()
            {
                return Attachment::fromData(fn () => 'bar', 'foo.jpg')->withMime('image/png');
            }
        };

        $mailMessage->attachMany([
            $attachable,
            '/path/to/forge.svg',
            '/path/to/vapor.svg' => [
                'as' => 'Logo.svg',
                'mime' => 'image/svg+xml',
            ],
        ]);

        $this->assertSame([
            [
                'data' => 'bar',
                'name' => 'foo.jpg',
                'options' => [
                    'mime' => 'image/png',
                ],
            ],
        ], $mailMessage->rawAttachments);

        $this->assertSame([
            [
                'file' => '/path/to/forge.svg',
                'options' => [],
            ],
            [
                'file' => '/path/to/vapor.svg',
                'options' => [
                    'as' => 'Logo.svg',
                    'mime' => 'image/svg+xml',
                ],
            ],
        ], $mailMessage->attachments);
    }
}

Function Calls

None

Variables

None

Stats

MD5 460cab91478b738fdc861791a2433170
Eval Count 0
Decode Time 121 ms