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

TypeError with Nette 3 #255

Open
NoNoNo opened this issue Jan 12, 2020 · 3 comments
Open

TypeError with Nette 3 #255

NoNoNo opened this issue Jan 12, 2020 · 3 comments

Comments

@NoNoNo
Copy link

NoNoNo commented Jan 12, 2020

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';
@florianeckerstorfer
Copy link
Member

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

@NoNoNo
Copy link
Author

NoNoNo commented Jan 21, 2020

@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)

@VottusCode
Copy link

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.

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

No branches or pull requests

3 participants