silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
720 stars 820 forks source link

TypeError when running SaphireTest::logInWithPermission #11240

Open Ofthemasses opened 1 month ago

Ofthemasses commented 1 month ago

Module version(s) affected

5.2.7

Description

I am in the process of testing one of my controllers using the FunctionalTest class. One of my tests makes use of the ::logInWithPermission method. Running this alone causes: TypeError "Return value must be of type bool, null returned.

I tested allowing the null to return, returning true and returning false in the function that produces this error. All of these ends up producing SilverStripe\Core\Injector\InjectorNotFoundException: Class SilverStripe\Versioned\RecursiveStagesInterface does not exist

I have silverstripe/versioned installed via composer so I am not sure why this next error is occuring.

How to reproduce

Test:

public function testCheckUserPerms()
{
    $this->logInWithPermission();
}

Possible Solution

I am providing a PR with this, I believe the config should return false on default in this scenario. The InjectionNotFoundException I am not sure about though.

Additional Context

This is a custom silverstripe install without the cms as we are not using Pages

1) Ordino\Lib\Tests\OControllerTests::testCheckUserPerms
TypeError: SilverStripe\ORM\Connect\DBQueryBuilder::shouldBuildTraceComment(): Return value must be of type bool, null returned
Expand to see stack trace ```text /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/Connect/DBQueryBuilder.php:88 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/Connect/DBQueryBuilder.php:76 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/DB.php:141 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/Queries/SQLExpression.php:92 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/Queries/SQLExpression.php:112 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/DataList.php:1031 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/DataList.php:967 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/DataList.php:947 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/DataList.php:1669 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Dev/SapphireTest.php:976 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Dev/SapphireTest.php:1018 /srv/http/ordino-skeleton/ordino-lib/tests/controllers/OControllerTests.php:71 ```
1) Ordino\Lib\Tests\OControllerTests::testCheckUserPerms
SilverStripe\Core\Injector\InjectorNotFoundException: Class SilverStripe\Versioned\RecursiveStagesInterface does not exist
Expand to see stack trace ```text /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Core/Injector/InjectionCreator.php:29 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Core/Injector/Injector.php:631 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Core/Injector/Injector.php:1027 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Core/Injector/Injector.php:979 /srv/http/ordino-skeleton/vendor/silverstripe/versioned/src/RecursiveStagesService.php:28 /srv/http/ordino-skeleton/vendor/silverstripe/versioned/src/RecursivePublishable.php:462 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Core/Extension.php:142 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Core/Extensible.php:438 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/DataObject.php:1251 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/ORM/DataObject.php:1595 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Dev/SapphireTest.php:987 /srv/http/ordino-skeleton/vendor/silverstripe/framework/src/Dev/SapphireTest.php:1018 /srv/http/ordino-skeleton/ordino-lib/tests/controllers/OControllerTests.php:71 ```

Fresh install with similar composer:

SilverStripe\Core\Injector\InjectorNotFoundException: Class SilverStripe\ErrorPage\ErrorPageControllerExtension does not exist in /srv/http/fresh/vendor/silverstripe/framework/src/Core/Injector/InjectionCreator.php:29
Expand to see stack trace ```text #0 /srv/http/fresh/vendor/silverstripe/framework/src/Core/Injector/Injector.php(631): SilverStripe\Core\Injector\InjectionCreator->create() #1 /srv/http/fresh/vendor/silverstripe/framework/src/Core/Injector/Injector.php(1027): SilverStripe\Core\Injector\Injector->instantiate() #2 /srv/http/fresh/vendor/silverstripe/framework/src/Core/Injector/Injector.php(979): SilverStripe\Core\Injector\Injector->getNamedService() #3 /srv/http/fresh/vendor/silverstripe/framework/src/Core/Extensible.php(536): SilverStripe\Core\Injector\Injector->get() #4 /srv/http/fresh/vendor/silverstripe/framework/src/Core/Extensible.php(436): SilverStripe\View\ViewableData->getExtensionInstances() #5 /srv/http/fresh/vendor/silverstripe/framework/src/Control/Controller.php(117): SilverStripe\View\ViewableData->extend() #6 /srv/http/fresh/vendor/silverstripe/framework/src/Dev/SapphireTest.php(896): SilverStripe\Control\Controller->doInit() #7 [internal function]: SilverStripe\Dev\SapphireTest::SilverStripe\Dev\{closure}() #8 /srv/http/fresh/vendor/silverstripe/framework/src/Control/HTTPApplication.php(137): call_user_func() #9 /srv/http/fresh/vendor/silverstripe/framework/src/Control/Middleware/HTTPMiddlewareAware.php(65): SilverStripe\Control\HTTPApplication->SilverStripe\Control\{closure}() #10 /srv/http/fresh/vendor/silverstripe/framework/src/Control/HTTPApplication.php(130): SilverStripe\Control\HTTPApplication->callMiddleware() #11 /srv/http/fresh/vendor/silverstripe/framework/src/Dev/SapphireTest.php(884): SilverStripe\Control\HTTPApplication->execute() #12 /srv/http/fresh/vendor/silverstripe/framework/src/Dev/SapphireTest.php(391): SilverStripe\Dev\SapphireTest::start() #13 /srv/http/fresh/vendor/phpunit/phpunit/src/Framework/TestSuite.php(629): SilverStripe\Dev\SapphireTest::setUpBeforeClass() #14 /srv/http/fresh/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(651): PHPUnit\Framework\TestSuite->run() #15 /srv/http/fresh/vendor/phpunit/phpunit/src/TextUI/Command.php(146): PHPUnit\TextUI\TestRunner->run() #16 /srv/http/fresh/vendor/phpunit/phpunit/src/TextUI/Command.php(99): PHPUnit\TextUI\Command->run() #17 /srv/http/fresh/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main() #18 /srv/http/fresh/vendor/bin/phpunit(122): include('...') #19 {main} ```
Expand to see composer.json ```json { "name": "ordino-nz/ordino-skeleton", "description": "The Ordino Web Skeleton", "require": { "php": "^8.1", "silverstripe/recipe-core": "~5.2.0@stable", "silverstripe/admin": "^2.0", "silverstripe/mimevalidator": "~3.1.0@stable", "silverstripe/config": "~2.1.0@stable", "symfony/process": "^6.3", "ext-yaml": "*" }, "require-dev": { "phpunit/phpunit": "^9.5", "mikey179/vfsstream": "^1.6.11", "squizlabs/php_codesniffer": "^3.7", "gskema/phpcs-type-sniff": "^82.2" }, "config": { "process-timeout": 600, "allow-plugins": { "composer/installers": true, "silverstripe/recipe-plugin": true, "silverstripe/vendor-plugin": true } }, "prefer-stable": true, "minimum-stability": "dev", "extra": { "project-files-installed": [ ".htaccess", "app/.htaccess", "app/_config/mimevalidator.yml", "app/_config/mysite.yml" ] } } ``` composer (fresh): ```json { "name": "silverstripe/installer", "type": "silverstripe-recipe", "description": "The SilverStripe Framework Installer", "require": { "php": "^8.1", "silverstripe/recipe-core": "~5.2.0@stable", "silverstripe/admin": "^2.0", "silverstripe/mimevalidator": "~3.1.0@stable", "silverstripe/config": "~2.1.0@stable", "symfony/process": "^6.3", "ext-yaml": "*" }, "require-dev": { "phpunit/phpunit": "^9.5", "mikey179/vfsstream": "^1.6.11", "squizlabs/php_codesniffer": "^3.7", "gskema/phpcs-type-sniff": "^82.2" }, "extra": { "project-files-installed": [ ".htaccess", "app/.htaccess", "app/_config/mimevalidator.yml", "app/_config/mysite.yml", "app/src/Page.php", "app/src/PageController.php" ], "public-files-installed": [ ".htaccess", "index.php", "web.config" ] }, "config": { "process-timeout": 600, "allow-plugins": { "composer/installers": true, "silverstripe/recipe-plugin": true, "silverstripe/vendor-plugin": true } }, "prefer-stable": true, "minimum-stability": "dev" } ```

Validations

PRs