markhuot / craft-pest

https://craft-pest.com
Other
38 stars 11 forks source link

Does not play ball with the link field plugin #82

Closed bleepsandblops closed 1 year ago

bleepsandblops commented 1 year ago

With Pest activated, when creating a new link field, I get: Calling unknown method: lenz\linkfield\fields\LinkField::factoryTypeHint() in "__string_template__2feea56560234f273691feaa93ef7d61" at line 7

markhuot commented 1 year ago

Is the craft-pest plugin installed in the Craft UI? There’s a behavior that provides that method in the plugin init and the only reason I can think it would go missing would be if the plugin is not enabled.

Related: I’m looking at having everything run without needing to install the plugin. But that’s still a PR away and not in a release yet.

JodebaDigitalPulse commented 1 year ago

I have the same issue, the two plugins are enabled. The registration of the behaviour is executed (I can dump something there before errors are thrown).

Full output:

./vendor/bin/pest --verbose

   FAIL  Tests\ExampleTest
  ⨯ it Loads the homepage

  ---

  • Tests\ExampleTest > it Loads the homepage
   PHPUnit\Framework\ExceptionWrapper 

  Calling unknown method: lenz\linkfield\fields\LinkField::factoryTypeHint() in "__string_template__2feea56560234f273691feaa93ef7d61" at line 7

  at vendor/craftcms/cms/src/helpers/Template.php:116
    112▕             // Copy twig_get_attribute()'s BadMethodCallException handling
    113▕             if ($ignoreStrictCheck || !$env->isStrictVariables()) {
    114▕                 return null;
    115▕             }
  ➜ 116▕             throw new RuntimeError($e->getMessage(), -1, $source);
    117▕         }
    118▕     }
    119▕
    120▕     /**

  1   vendor/phpunit/phpunit/src/Framework/TestCase.php:904
      PHPUnit\Framework\TestResult::run()

  2   vendor/phpunit/phpunit/src/Framework/TestSuite.php:675
      PHPUnit\Framework\TestCase::run()

  3   vendor/phpunit/phpunit/src/Framework/TestSuite.php:675
      PHPUnit\Framework\TestSuite::run()

  4   vendor/phpunit/phpunit/src/TextUI/TestRunner.php:653
      PHPUnit\Framework\TestSuite::run()

  5   vendor/phpunit/phpunit/src/TextUI/Command.php:144
      PHPUnit\TextUI\TestRunner::run()

  6   vendor/pestphp/pest/src/Console/Command.php:119
      PHPUnit\TextUI\Command::run()

  7   vendor/pestphp/pest/bin/pest:62
      Pest\Console\Command::run()

  8   vendor/pestphp/pest/bin/pest:63
      {closure}()

  9   vendor/bin/pest:120
      include("*******/vendor/pestphp/pest/bin/pest")
markhuot commented 1 year ago

Ah, this is because the field doesn't call parent::behaviors() so EVENT_DEFINE_BEHAVIORS is never run.

Link field inherits from ForeignField which defines it's behaviors() as,

https://github.com/sebastian-lenz/craft-utils/blob/86403435fdfcab499edd1b363bafc46cf4c1fb4d/src/foreignField/ForeignField.php#L55-L61

Which overrides the default functionality of,

https://github.com/craftcms/cms/blob/ea55235e5a9677aa577f3a701dd4eaa04c2010b7/src/base/Model.php#L96-L107

This fix will be that ForeignField needs to call the parent in order to retain this behavior. I've opened a PR with a potential fix, https://github.com/sebastian-lenz/craft-utils/pull/4.

JodebaDigitalPulse commented 1 year ago

thx! 🙌

markhuot commented 1 year ago

I'm going to close this issue since the root cause is not in craft-pest. Hopefully https://github.com/sebastian-lenz/craft-utils/pull/4 merges soon and resolves this! Feel free to jump over to that PR and submit bump the thread if you have more questions.