slugify
slugify copied to clipboard
TypeError with Nette 3
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 ofNette\DI\Definitions\ServiceDefinition
, instance ofNette\DI\Definitions\FactoryDefinition
given, called invendor/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 Could you create a PR for this? If you need any help please let me know.
@florianeckerstorfer Sorry, I don’t know how to fix the unit tests:
There were 2 errors:
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.
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.
(same problem as PR #231)
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.