Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Command throws on Http Macros #1065

Closed
hettiger opened this issue Sep 21, 2020 · 6 comments
Closed

Generate Command throws on Http Macros #1065

hettiger opened this issue Sep 21, 2020 · 6 comments
Labels

Comments

@hettiger
Copy link

Versions:

Description:

The php artisan ide-helper:generate command throws if there are any Http macros registered:

BadMethodCallException

Disclaimer:
Added \Http::macro('exampleMacro', function () {}); to AppServiceProvider::register() to make the
artisan command fail. This is not part of the demo repository in order to allow for additional tests.

php artisan ide-helper:generate -vvv

   BadMethodCallException

  Method Illuminate\Http\Client\Factory::getFacadeRoot does not exist.

  at vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:77
     73▕      */
     74▕     public static function __callStatic($method, $parameters)
     75▕     {
     76▕         if (! static::hasMacro($method)) {
  ➜  77▕             throw new BadMethodCallException(sprintf(
     78▕                 'Method %s::%s does not exist.', static::class, $method
     79▕             ));
     80▕         }
     81▕

  • Bad Method Call: Did you mean Illuminate\Http\Client\Factory::recorded() ?

  1   vendor/barryvdh/laravel-ide-helper/src/Alias.php:209
      Illuminate\Http\Client\Factory::__callStatic("getFacadeRoot", [])

  2   vendor/barryvdh/laravel-ide-helper/src/Alias.php:73
      Barryvdh\LaravelIdeHelper\Alias::detectFake()

  3   vendor/barryvdh/laravel-ide-helper/src/Generator.php:318
      Barryvdh\LaravelIdeHelper\Alias::__construct(Object(Illuminate\Config\Repository), "Illuminate\Http\Client\Factory", "\Illuminate\Http\Client\Factory", [])

  4   vendor/barryvdh/laravel-ide-helper/src/Generator.php:228
      Barryvdh\LaravelIdeHelper\Generator::addMacroableClasses(Object(Illuminate\Support\Collection))

  5   vendor/barryvdh/laravel-ide-helper/src/Generator.php:88
      Barryvdh\LaravelIdeHelper\Generator::getAliasesByExtendsNamespace()

  6   vendor/barryvdh/laravel-ide-helper/src/Generator.php:78
      Barryvdh\LaravelIdeHelper\Generator::generatePhpHelper()

  7   vendor/barryvdh/laravel-ide-helper/src/Console/GeneratorCommand.php:118
      Barryvdh\LaravelIdeHelper\Generator::generate("php")

  8   vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
      Barryvdh\LaravelIdeHelper\Console\GeneratorCommand::handle()

  9   vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
      call_user_func_array([])

  10  vendor/laravel/framework/src/Illuminate/Container/Util.php:40
      Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()

  11  vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:95
      Illuminate\Container\Util::unwrapIfClosure(Object(Closure))

  12  vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:39
      Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure))

  13  vendor/laravel/framework/src/Illuminate/Container/Container.php:596
      Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), [])

  14  vendor/laravel/framework/src/Illuminate/Console/Command.php:136
      Illuminate\Container\Container::call()

  15  vendor/symfony/console/Command/Command.php:258
      Illuminate\Console\Command::execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))

  16  vendor/laravel/framework/src/Illuminate/Console/Command.php:121
      Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))

  17  vendor/symfony/console/Application.php:916
      Illuminate\Console\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

  18  vendor/symfony/console/Application.php:264
      Symfony\Component\Console\Application::doRunCommand(Object(Barryvdh\LaravelIdeHelper\Console\GeneratorCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

  19  vendor/symfony/console/Application.php:140
      Symfony\Component\Console\Application::doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

  20  vendor/laravel/framework/src/Illuminate/Console/Application.php:93
      Symfony\Component\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

  21  vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:129
      Illuminate\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

  22  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

I've came across this after updating from 2.7.0 to 2.8.1 on an old Laravel 7 project.
-> With 2.7.0 + Laravel 7 the Generate Command did not throw on Http Macros.

Steps To Reproduce:

Tests result
php artisan test

   PASS  Tests\Unit\ExampleTest
  ✓ basic test

   PASS  Tests\Feature\CollectionMacroTest
  ✓ generate command does not throw
  ✓ generate command with collection macro does not throw

   PASS  Tests\Feature\ExampleTest
  ✓ basic test

   FAIL  Tests\Feature\HttpMacroTest
  ✓ generate command does not throw
  ⨯ generate command with http macro does not throw
  ✓ http macro returns string

  ---

  • Tests\Feature\HttpMacroTest > generate command with http macro does not throw
   BadMethodCallException

  Method Illuminate\Http\Client\Factory::getFacadeRoot does not exist.

  at vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:77
     73▕      */
     74▕     public static function __callStatic($method, $parameters)
     75▕     {
     76▕         if (! static::hasMacro($method)) {
  ➜  77▕             throw new BadMethodCallException(sprintf(
     78▕                 'Method %s::%s does not exist.', static::class, $method
     79▕             ));
     80▕         }
     81▕

      +22 vendor frames
  23  tests/Feature/HttpMacroTest.php:23
      Illuminate\Foundation\Testing\TestCase::artisan("ide-helper:generate")


  Tests:  1 failed, 6 passed
  Time:   2.74s
@hettiger hettiger added the bug label Sep 21, 2020
@mfn
Copy link
Collaborator

mfn commented Sep 21, 2020

Probably #1006

@domkrm do you think you can take a look?

@domkrm
Copy link
Contributor

domkrm commented Sep 21, 2020

This PR #1066 should fix the error.

This happens when a macroable class has a function with the name "fake". Then the generator thought that this class is a facade.

@hettiger
Copy link
Author

Can confirm PR #1066 will fix this issue:

Package operations: 0 installs, 1 update, 0 removals
  - Removing barryvdh/laravel-ide-helper (v2.8.1)
  - Installing barryvdh/laravel-ide-helper (dev-master fd3d218): Downloading (100%)
php artisan test

   PASS  Tests\Unit\ExampleTest
  ✓ basic test

   PASS  Tests\Feature\CollectionMacroTest
  ✓ generate command does not throw
  ✓ generate command with collection macro does not throw

   PASS  Tests\Feature\ExampleTest
  ✓ basic test

   PASS  Tests\Feature\HttpMacroTest
  ✓ generate command does not throw
  ✓ generate command with http macro does not throw
  ✓ http macro returns string

  Tests:  7 passed
  Time:   2.88s

@hettiger
Copy link
Author

Closing the issue since the PR #1066 has been merged.

@mfn
Copy link
Collaborator

mfn commented Sep 21, 2020

Thanks @hettiger !

@hettiger
Copy link
Author

Thank you too @mfn and @domkrm 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants