neos / flow-development-collection

The unified repository containing the Flow core packages, used for Flow development.
https://flow.neos.io/
MIT License
138 stars 188 forks source link

BUG: Entities are broken in Testing context #3190

Open bwaidelich opened 1 year ago

bwaidelich commented 1 year ago

Is there an existing issue for this?

Current Behavior

Loading entities in some Testing context leads to an exception.

E.g. the example below returns

Flow Variable Dump
Neos\Flow\Persistence\Doctrine\QueryResult(empty)

and logs the follwing exception:

Exception #1542792708 in line 133 of Packages/Libraries/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php: Failure while fetching class schema class "Neos\Flow\Security\Account": No class schema found for "Neos\Flow\Security\Account".

34 Neos\Flow\Persistence\Doctrine\Mapping\Driver\FlowAnnotationDriver_Original::loadMetadataForClass("Neos\Flow\Security\Account", Neos\Flow\Persistence\Doctrine\Mapping\ClassMetadata)
33 Doctrine\ORM\Mapping\ClassMetadataFactory::doLoadMetadata(Neos\Flow\Persistence\Doctrine\Mapping\ClassMetadata, NULL, false, array|0|)
32 Doctrine\Persistence\Mapping\AbstractClassMetadataFactory::loadMetadata("Neos\Flow\Security\Account")
31 Doctrine\Persistence\Mapping\AbstractClassMetadataFactory::getMetadataFor("Neos\Flow\Security\Account")
30 Doctrine\ORM\EntityManager::getClassMetadata("Neos\Flow\Security\Account")
29 Doctrine\ORM\Query\Parser::RangeVariableDeclaration()
28 Doctrine\ORM\Query\Parser::IdentificationVariableDeclaration()
27 Doctrine\ORM\Query\Parser::FromClause()
26 Doctrine\ORM\Query\Parser::SelectStatement()
25 Doctrine\ORM\Query\Parser::QueryLanguage()
24 Doctrine\ORM\Query\Parser::getAST()
23 Doctrine\ORM\Query\Parser::parse()
22 Doctrine\ORM\Query::parse()
21 Doctrine\ORM\Query::_doExecute()
20 Doctrine\ORM\AbstractQuery::executeIgnoreQueryCache(NULL, 4)
19 Doctrine\ORM\AbstractQuery::execute(NULL, 4)
18 Doctrine\ORM\AbstractQuery::getSingleResult(4)
17 Doctrine\ORM\AbstractQuery::getSingleScalarResult()
16 Neos\Flow\Persistence\Doctrine\Query_Original::count()
15 Neos\Flow\Persistence\Doctrine\QueryResult_Original::count()
14 count(Neos\Flow\Persistence\Doctrine\QueryResult)
13 Neos\Flow\Error\Debugger::renderArrayDump(Neos\Flow\Persistence\Doctrine\QueryResult, 1, true, true)
12 Neos\Flow\Error\Debugger::renderDump(Neos\Flow\Persistence\Doctrine\QueryResult, 0, true, true)
11 Neos\Flow\var_dump(Neos\Flow\Persistence\Doctrine\QueryResult)
10 Neos\Flow\Command\TestCommandController_Original::testCommand()
9 Neos\Flow\Cli\CommandController_Original::callCommandMethod()
8 Neos\Flow\Cli\CommandController_Original::processRequest(Neos\Flow\Cli\Request, Neos\Flow\Cli\Response)
7 Neos\Flow\Cli\Dispatcher_Original::dispatch(Neos\Flow\Cli\Request, Neos\Flow\Cli\Response)
6 Neos\Flow\Cli\CommandRequestHandler::Neos\Flow\Cli\{closure}()
5 Closure::__invoke()
4 Neos\Flow\Security\Context_Original::withoutAuthorizationChecks(Closure)
3 Neos\Flow\Cli\CommandRequestHandler::handleRequest()
2 Neos\Flow\Core\Bootstrap::run()
1 require("Packages/Framework/Neos.Flow/Scripts/flow.php")

Previous exception: Exception #1295973082 in line 184 of Data/Temporary/Testing/Cache/Code/Flow_Object_Classes/Neos_Flow_Persistence_Doctrine_Mapping_Driver_FlowAnnotationDriver.php: No class schema found for "Neos\Flow\Security\Account".

35 Neos\Flow\Persistence\Doctrine\Mapp

Expected Behavior

The accounts should be returned and no exception thrown

Steps To Reproduce

In an installation with at least one account, create the following CLI command controller:

<?php
namespace Neos\Flow\Command;

use Neos\Flow\Cli\CommandController;
use Neos\Flow\Security\AccountRepository;

class TestCommandController extends CommandController
{

    public function __construct(private AccountRepository $accountRepository)
    {
        parent::__construct();
    }

    public function testCommand(): void
    {
        \Neos\Flow\var_dump($this->accountRepository->findAll());
    }
}

and execute it with

FLOW_CONTEXT=Testing ./flow test:test

Environment

- Flow: 9.0 (probably a regression introduced with #3101)

Anything else?

For the record:

With FLOW_CONTEXT=Development and FLOW_CONTEXT=Production everything works as expected

kitsunet commented 1 year ago

Just to have it here:

Maybe we should roll (the addition of the Testing context condition) back together with the test and see if we can come up with a way to enable it for one test, recompile do test and flush/reset afterwards. It might just make sense to introduce this as a setting and use that in the condition (and set the setting differently per context), that way it would be easier to set it on a case by case basis and people could disable it if it causes issues. Maybe we can then overwrite the setting for one test with a pre/post flush? IDK.