-
Notifications
You must be signed in to change notification settings - Fork 0
Crash without PHPUnit installed #2
Comments
Even if I install phpunit, it still crashes with a different error:
Perhaps it is not supposed to be installed with |
Running |
The 1st error - for some reason it tries to register this testcase as a service: Would excluding the class in here help? |
Excluding does not seem to work. The search extension checks for the class existence before checking if it is excluded I verified by dumping object(stdClass)#205 (7) {
["in"]=>
string(71) "/home/jtojnar/Projects/eudyptes/vendor/barista/barista/src/DI/../../src"
["exclude"]=>
object(stdClass)#201 (3) {
["classes"]=>
array(3) {
[0]=>
string(39) "Barista\Testing\Macro\AbstractMacroTest"
[1]=>
string(34) "Barista\DI\BaristaContainerFactory"
[2]=>
string(28) "Barista\Configuration\Option"
}
["implements"]=>
array(1) {
[0]=>
string(39) "Barista\Contract\LatteUpgraderInterface"
}
["extends"]=>
array(0) {
}
}
["files"]=>
array(0) {
}
["classes"]=>
array(0) {
}
["extends"]=>
array(0) {
}
["implements"]=>
array(0) {
}
["tags"]=>
array(0) {
}
} |
I see. And the class existance probably invokes the parent class autoloading. |
You are probably more qualified to answer that. Is it not possible to use Composer autoloading for Nette autowiring? It seems to work pretty well in app projects (unless Nette somehow still uses RobotLoader internally) but I am not really sure how it is supposed to work in tools installed as Composer dependencies. I would expect them to just use the autoloader of the parent project but removing the Fatal error: Uncaught Nette\DI\MissingServiceException: Service of type Barista\FileSystem\LatteFilesFinder not found. Did you add it to configuration file? in /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Autowiring.php:57 |
I don't know how exactly the search componet works. I think that to make code work, we have to:
It should be still available without installing phpunit as extra dependency. |
It loads the app’s autoload file and Actually looking at the autowiring code, it is able to find the class, or it would crash with a different error. Will do more dumping. |
My rought guess is that it crashes on |
That behaviour is probably intentional so that Nette DI does not create random classes. Another alternative could be removing the RobotLoader in favour of explicitly listed factories. The following seems to work for the --- a/config/services.neon
+++ b/config/services.neon
@@ -1,14 +1,3 @@
-# autodiscovery, see https://doc.nette.org/en/dependency-injection/configuration#toc-search
-search:
- in: %appDir%/../../src
- exclude:
- classes:
- - Barista\DI\BaristaContainerFactory
- - Barista\Configuration\Option
- implements:
- # register manually the rules you want to apply
- - Barista\Contract\LatteUpgraderInterface
-
decorator:
Barista\Command\AbstractBaristaCommand:
inject: true
@@ -21,6 +10,9 @@
class: Barista\Command\LintCommand
arguments:
latteProviderFile: %latteProviderFile%
+
+ - Barista\FileSystem\LatteFilesFinder
+ - Barista\Console\ApplicationFactory
- Latte\Compiler\TemplateParser
- Latte\Compiler\TemplateLexer Well, “work” it will then print the same error as in the second comment. But that is probably unrelated issue. |
That would force us to register everything manually and kill the point of Nette 3.0 search feature. |
No, it crashed in Composer autoloader code triggered by the
Not everything, just the stuff we want auto-wired. Which, at the moment seems to be the two classes listed in my patch. To be honest, I have always felt that RobotLoader is a misfeature since Composer already has all the necessary information available statically (as long as you use Composer autoloading – but there is no excuse to avoid it these days, IMO). Unless I am missing something, the search extension should be able to look at all the explicitly registered services and try to register their dependencies, rather than scanning a directory and registering all classes it finds it does now. |
I want to keep the search here, to allow scaling services without thinking about manual registration. I'm doing the same in Symfony last 4 years. |
This should fix it: 08fa2df Barista is a dev tool with abstract test case, so the PHPUnit is expected here. |
Thanks, will do. I have opened nette/di#282 just in case it ditching the RobotLoader is interesting for David. |
Though pondering it a bit more, the abstract test case is not really relevant to the dev tool so it might be cleanest to split it into a separate composer package. Though I understand that adding an extra dependency is probably the most pragmatic choice. |
At first sight, it would hell to maintain for a just a few classes. Yet the test case is very useful for the upgrade. It should be part of the Latte 2 project already, while this package runs on Latte 3. |
Running
vendor/bin/barista analyze app
in a Nette project that does not use PHPUnit (nette/tester
is okay) crashes:The text was updated successfully, but these errors were encountered: