Seem like it is expecting registry at a different place than the first constructor argument. Would specifying registry as a named parameter make it work?
But probably a service class would stop you pulling in the uneeded dependencies.
$component = new TestComponent(
registry: new ComponentRegistry(
new AppController(
new ServerRequest()
)
)
);
$component->hiJames();
If you are on CakePHP 4.2 or higher I would rather highly recommend you create a service class and inject it into your command via dependency injection.
Components are only really suited to be shared across controllers, not anything else.
I ended up moving all required functionality to few service classes to solve this. Took quite some time to do it, because these functions we used quite much in other parts of the application.
@jmcd73 Thank you for suggestion, I will test that even though I already moved to service class
@KevinPfeifer Thank you for good video, I founded that video before I wrote this message and ended up using that video as study material. There was one part, which did not work in my setup (cakePHP 5.0.6). I had to change $this->loadModel() to $this->fetchModel().