Repository: laravel/framework (php)

Issue:
Laravel 9 - Error when sending email with priority using MailMessage
<!-- DO NOT THROW THIS AWAY -->
<!-- Fill out the FULL versions with patch versions -->

- Laravel Version: 9.1.0
- PHP Version: 8.0.8

### Description:
Sending email with priority using Illuminate\Notifications\Messages\MailMessage cause error:
```
Call to undefined method Illuminate\Mail\Message::setPriority()
```
This is because calling wrong function name. Need to replace from `setPriority()` to `priority()` in Illuminate\Notifications\Channels\MailChannel:146


Pull request description:
[9.x] Fix setPriority Call for MailChannel
Fixes #41119 

There seems to be some leftover from Swiftmailer which still uses setPriority.

Patch:
diff --git a/src/Illuminate/Database/Console/Factories/stubs/factory.stub b/src/Illuminate/Database/Console/Factories/stubs/factory.stub
index 5649e3f708..0759b5d2ac 100644
--- a/src/Illuminate/Database/Console/Factories/stubs/factory.stub
+++ b/src/Illuminate/Database/Console/Factories/stubs/factory.stub
@@ -12,7 +12,7 @@ class {{ factory }}Factory extends Factory
     /**
      * Define the model's default state.
      *
-     * @return array
+     * @return array<string, mixed>
      */
     public function definition()
     {
diff --git a/src/Illuminate/Foundation/Http/FormRequest.php b/src/Illuminate/Foundation/Http/FormRequest.php
index ec757b65d5..ec01119b0a 100644
--- a/src/Illuminate/Foundation/Http/FormRequest.php
+++ b/src/Illuminate/Foundation/Http/FormRequest.php
@@ -212,13 +212,7 @@ public function safe(array $keys = null)
      */
     public function validated($key = null, $default = null)
     {
-        if (! is_null($key)) {
-            return data_get(
-                $this->validator->validated(), $key, $default
-            );
-        }
-
-        return $this->validator->validated();
+        return data_get($this->validator->validated(), $key, $default);
     }
 
     /**
diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php
index 594320d5b7..fd3a3cc289 100644
--- a/src/Illuminate/Notifications/Channels/MailChannel.php
+++ b/src/Illuminate/Notifications/Channels/MailChannel.php
@@ -143,7 +143,7 @@ protected function buildMessage($mailMessage, $notifiable, $notification, $messa
         $this->addAttachments($mailMessage, $message);
 
         if (! is_null($message->priority)) {
-            $mailMessage->setPriority($message->priority);
+            $mailMessage->priority($message->priority);
         }
 
         if ($message->tags) {
diff --git a/src/Illuminate/Queue/CallQueuedHandler.php b/src/Illuminate/Queue/CallQueuedHandler.php
index c9993a3b28..6b681a31b4 100644
--- a/src/Illuminate/Queue/CallQueuedHandler.php
+++ b/src/Illuminate/Queue/CallQueuedHandler.php
@@ -179,12 +179,13 @@ protected function ensureSuccessfulBatchJobIsRecorded($command)
         $uses = class_uses_recursive($command);
 
         if (! in_array(Batchable::class, $uses) ||
-            ! in_array(InteractsWithQueue::class, $uses) ||
-            is_null($command->batch())) {
+            ! in_array(InteractsWithQueue::class, $uses)) {
             return;
         }
 
-        $command->batch()->recordSuccessfulJob($command->job->uuid());
+        if ($batch = $command->batch()) {
+            $batch->recordSuccessfulJob($command->job->uuid());
+        }
     }
 
     /**
@@ -273,12 +274,13 @@ public function failed(array $data, $e, string $uuid)
      */
     protected function ensureFailedBatchJobIsRecorded(string $uuid, $command, $e)
     {
-        if (! in_array(Batchable::class, class_uses_recursive($command)) ||
-            is_null($command->batch())) {
+        if (! in_array(Batchable::class, class_uses_recursive($command))) {
             return;
         }
 
-        $command->batch()->recordFailedJob($uuid, $e);
+        if ($batch = $command->batch()) {
+            $batch->recordFailedJob($uuid, $e);
+        }
     }
 
     /**


Test patch:
diff --git a/tests/Integration/Notifications/SendingMailNotificationsTest.php b/tests/Integration/Notifications/SendingMailNotificationsTest.php
index 0530870540..5fe74775f2 100644
--- a/tests/Integration/Notifications/SendingMailNotificationsTest.php
+++ b/tests/Integration/Notifications/SendingMailNotificationsTest.php
@@ -98,7 +98,7 @@ public function testMailIsSent()
 
                 $message->shouldReceive('subject')->once()->with('Test Mail Notification');
 
-                $message->shouldReceive('setPriority')->once()->with(1);
+                $message->shouldReceive('priority')->once()->with(1);
 
                 $closure($message);
 
@@ -144,7 +144,7 @@ public function testMailIsSentToNamedAddress()
 
                 $message->shouldReceive('subject')->once()->with('Test Mail Notification');
 
-                $message->shouldReceive('setPriority')->once()->with(1);
+                $message->shouldReceive('priority')->once()->with(1);
 
                 $closure($message);