You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ArgumentCountError: Too few arguments to function SilverStripe\Control\HTTPRequest::__construct(), 0 passed in [...]vendor/silverstripe/framework/src/Core/Injector/InjectionCreator.php on line 35 and at least 2 expected
Thanks @GuySartorelli for pointing out (via user's slack) that it's looking for a pre-registered request.
Seems like this is a new code execution path in CMS 5, as the error doesn't occur when running tests against CMS 4.
The context of the error is attempting to run a PHPUnit test with a normal "just enough" setup (i.e. it's not production traffic):
Interestingly the offending line is notgetRequest() as one might think, but rather doInit()
The execution path is via getCombinedClientConfig() which falls throught to the sudo mode controller that for whatever reason uses Injector::get rather than $this->getRequest(). Using getRequest would cause no issue, as per the default request set (but not registered with Injector) in RequestHandler::__construct():
publicfunction__construct()
{
$this->brokenOnConstruct = false;
$this->setRequest(newNullHTTPRequest()); // because of thisparent::__construct();
}
The text was updated successfully, but these errors were encountered:
You could work around this by injecting the request: Injector::inst()->registerService(HTTPRequest::class, $request);
Given this is only happening in a unit test and there's an obvious workaround I can't promise the issue will be prioritised any time in the near future.
Yes, I was just about to add this in my own comment.
To clarify in the same example from the OP (slightly expanded to include namespace usage changes):
+use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
+use SilverStripe\Core\Injector\Injector;
Resulting in
silverstripe-admin/code/SudoModeController.php
Line 48 in 55ad961
Thanks @GuySartorelli for pointing out (via user's slack) that it's looking for a pre-registered request.
Seems like this is a new code execution path in CMS 5, as the error doesn't occur when running tests against CMS 4.
The context of the error is attempting to run a PHPUnit test with a normal "just enough" setup (i.e. it's not production traffic):
Interestingly the offending line is not
getRequest()
as one might think, but ratherdoInit()
The execution path is via
getCombinedClientConfig()
which falls throught to the sudo mode controller that for whatever reason usesInjector::get
rather than$this->getRequest()
. UsinggetRequest
would cause no issue, as per the default request set (but not registered with Injector) inRequestHandler::__construct()
:The text was updated successfully, but these errors were encountered: