slugify icon indicating copy to clipboard operation
slugify copied to clipboard

TypeError with Nette 3

Open NoNoNo opened this issue 4 years ago • 3 comments

I get a TypeError with Nette 3:

Argument 1 passed to Cocur\Slugify\Bridge\Nette\SlugifyExtension::Cocur\Slugify\Bridge\Nette\{closure}() must be an instance of Nette\DI\Definitions\ServiceDefinition, instance of Nette\DI\Definitions\FactoryDefinition given, called in vendor/cocur/slugify/src/Bridge/Nette/SlugifyExtension.php on line 42

I managed to fix this with:

diff --git a/src/Bridge/Nette/SlugifyExtension.php b/src/Bridge/Nette/SlugifyExtension.php
index 12fdbe5..34e4d35 100644
--- a/src/Bridge/Nette/SlugifyExtension.php
+++ b/src/Bridge/Nette/SlugifyExtension.php
@@ -3,7 +3,7 @@
 namespace Cocur\Slugify\Bridge\Nette;

 use Nette\DI\CompilerExtension;
-use Nette\DI\ServiceDefinition;
+use Nette\DI\Definitions\FactoryDefinition;

 /**
  * SlugifyExtension
@@ -33,8 +33,8 @@ class SlugifyExtension extends CompilerExtension
         $builder = $this->getContainerBuilder();

         $self = $this;
-        $registerToLatte = function (ServiceDefinition $def) use ($self) {
-            $def->addSetup('addFilter', ['slugify', [$self->prefix('@helper'), 'slugify']]);
+        $registerToLatte = function (FactoryDefinition $def) use ($self) {
+            $def->getResultDefinition()->addSetup('addFilter', ['slugify', [$self->prefix('@helper'), 'slugify']]);
         };

         $latteFactory = $builder->getByType('Nette\Bridges\ApplicationLatte\ILatteFactory') ?: 'nette.latteFactory';

NoNoNo avatar Jan 12 '20 22:01 NoNoNo

@NoNoNo Could you create a PR for this? If you need any help please let me know.

florianeckerstorfer avatar Jan 17 '20 15:01 florianeckerstorfer

@florianeckerstorfer Sorry, I don’t know how to fix the unit tests:

There were 2 errors:

  1. Cocur\Slugify\Tests\Bridge\Nette\SlugifyExtensionTest::testLoadConfiguration

    Mockery\Exception: The class \Nette\DI\ServiceDefinition is marked final and its methods cannot be replaced. Classes marked final can be passed in to \Mockery::mock() as instantiated objects to create a partial mock, but only if the mock is not subject to type hinting checks.

    slugify/tests/Bridge/Nette/SlugifyExtensionTest.php:31

  2. Cocur\Slugify\Tests\Bridge\Nette\SlugifyExtensionTest::testBeforeCompile

    Mockery\Exception: The class \Nette\DI\ServiceDefinition is marked final and its methods cannot be replaced. Classes marked final can be passed in to \Mockery::mock() as instantiated objects to create a partial mock, but only if the mock is not subject to type hinting checks.

    slugify/tests/Bridge/Nette/SlugifyExtensionTest.php:82

(same problem as PR #231)

NoNoNo avatar Jan 21 '20 16:01 NoNoNo

Yeah, I got the same errors as @NoNoNo when I was attempting to fix the unit test in my PR. I thought that there's only something wrong with me, as I write tests in Nette Tester and I don't use Mockery.

VottusCode avatar Jun 01 '20 19:06 VottusCode