beyondcode / helo-laravel

HELO Laravel helper package to add
MIT License
88 stars 25 forks source link

TypeError Illuminate\Support\Testing\Fakes\MailFake::__construct() #53

Open NoahNxT opened 5 months ago

NoahNxT commented 5 months ago

Hi!

recently the package started to have conflicts with the Barryvdh\LaravelIdeHelper for some reason. Looks like type mismatching since one of the latest updates.

Command: php artisan ide-helper:generate Laravel: v11.11.1 PHP: 8.3.6 Composer: 2.7.4

Also tried reinstalling, deleting the vendor, php artisan clear-compiled

Console

   TypeError 

  Illuminate\Support\Testing\Fakes\MailFake::__construct(): Argument #1 ($manager) must be of type Illuminate\Mail\MailManager, BeyondCode\HeloLaravel\Laravel9Mailer given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Mail.php on line 76

  at vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/MailFake.php:54
     50▕      *
     51▕      * @param  MailManager  $manager
     52▕      * @return void
     53▕      */
  ➜  54▕     public function __construct(MailManager $manager)
     55▕     {
     56▕         $this->manager = $manager;
     57▕     }
     58▕ 

      +20 vendor frames 

  21  artisan:13
      Illuminate\Foundation\Application::handleCommand(Object(Symfony\Component\Console\Input\ArgvInput))

Logs:

[2024-06-21 22:26:22] local.ERROR: Illuminate\Support\Testing\Fakes\MailFake::__construct(): Argument #1 ($manager) must be of type Illuminate\Mail\MailManager, BeyondCode\HeloLaravel\Laravel9Mailer given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Mail.php on line 76 {"exception":"[object] (TypeError(code: 0): Illuminate\\Support\\Testing\\Fakes\\MailFake::__construct(): Argument #1 ($manager) must be of type Illuminate\\Mail\\MailManager, BeyondCode\\HeloLaravel\\Laravel9Mailer given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Mail.php on line 76 at /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/MailFake.php:54)
[stacktrace]
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Mail.php(76): Illuminate\\Support\\Testing\\Fakes\\MailFake->__construct(Object(BeyondCode\\HeloLaravel\\Laravel9Mailer))
#1 /var/www/html/vendor/barryvdh/laravel-ide-helper/src/Alias.php(221): Illuminate\\Support\\Facades\\Mail::fake()
#2 /var/www/html/vendor/barryvdh/laravel-ide-helper/src/Alias.php(77): Barryvdh\\LaravelIdeHelper\\Alias->detectFake()
#3 /var/www/html/vendor/barryvdh/laravel-ide-helper/src/Generator.php(168): Barryvdh\\LaravelIdeHelper\\Alias->__construct(Object(Illuminate\\Config\\Repository), 'Mail', '\\\\Illuminate\\\\Sup...', Array, Array)
#4 /var/www/html/vendor/barryvdh/laravel-ide-helper/src/Generator.php(234): Barryvdh\\LaravelIdeHelper\\Generator->getValidAliases()
#5 /var/www/html/vendor/barryvdh/laravel-ide-helper/src/Generator.php(81): Barryvdh\\LaravelIdeHelper\\Generator->getAliasesByExtendsNamespace()
#6 /var/www/html/vendor/barryvdh/laravel-ide-helper/src/Console/GeneratorCommand.php(116): Barryvdh\\LaravelIdeHelper\\Generator->generate()
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Barryvdh\\LaravelIdeHelper\\Console\\GeneratorCommand->handle()
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#10 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\\Container\\Container->call(Array)
#13 /var/www/html/vendor/symfony/console/Command/Command.php(279): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#15 /var/www/html/vendor/symfony/console/Application.php(1047): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 /var/www/html/vendor/symfony/console/Application.php(316): Symfony\\Component\\Console\\Application->doRunCommand(Object(Barryvdh\\LaravelIdeHelper\\Console\\GeneratorCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#17 /var/www/html/vendor/symfony/console/Application.php(167): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(196): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1198): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#20 /var/www/html/artisan(13): Illuminate\\Foundation\\Application->handleCommand(Object(Symfony\\Component\\Console\\Input\\ArgvInput))
#21 {main}
"} 
gabidj commented 4 months ago

Hello, I got this issue as well and I'm currently investigating it, so far I got to a point that I made it working but I have to warn you this is definitely not for non-local use.

Here's a possible fix if your problem is just generating the ide-helper file.

HeloLaravelServiceProvider.php

    protected function bootMailable()
    {
        $instance = app()->make(MailManager::class, ['app' => app()]);
        $mailerInstance = app()->make(Mailer::class);

        Mail::swap($instance);
        $this->app->instance(MailerContract::class, $mailerInstance);
    }

imports are

use BeyondCode\HeloLaravel\Mailer;
use BeyondCode\HeloLaravel\MailManager;
use Illuminate\Contracts\Mail\Mailer as MailerContract;

In the meantime I'm looking for a more appropriate fix.

gabidj commented 4 months ago

Seems like this issue was raised again, here are some pointers.

https://github.com/beyondcode/helo-laravel/issues/37 https://github.com/barryvdh/laravel-ide-helper/issues/1422

Have do you have multiple Mail::fake() calls by any chance? The ::fake issue was fixed on https://github.com/laravel/framework/pull/46188

AtlasApollo commented 1 month ago

Thank you @gabidj your suggestion above to manually add the changes into HeloLaravelServiceProvider.php helped me get through composer update :)