Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/9.0' into task/phpstanInDerBahn
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 2, 2023
2 parents a5fed27 + 6e9e6a2 commit d496755
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 112 deletions.
3 changes: 2 additions & 1 deletion .composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"../../bin/behat -f progress -c Neos.ContentRepository.BehavioralTests/Tests/Behavior/behat.yml.dist",
"../../bin/behat -f progress -c Neos.ContentGraph.DoctrineDbalAdapter/Tests/Behavior/behat.yml.dist",
"../../flow doctrine:migrate --quiet; ../../flow cr:setup",
"../../bin/behat -f progress -c Neos.Neos/Tests/Behavior/behat.yml"
"../../bin/behat -f progress -c Neos.Neos/Tests/Behavior/behat.yml",
"../../bin/behat -f progress -c Neos.ContentRepository.LegacyNodeMigration/Tests/Behavior/behat.yml.dist"
],
"test:behavioral:stop-on-failure": [
"../../bin/behat -vvv --stop-on-failure -f progress -c Neos.ContentRepository.BehavioralTests/Tests/Behavior/behat.yml.dist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
* source code.
*/

require_once(__DIR__ . '/../../../../../../Application/Neos.Behat/Tests/Behat/FlowContextTrait.php');
require_once(__DIR__ . '/ProjectionIntegrityViolationDetectionTrait.php');

use Behat\Behat\Context\Context as BehatContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Neos\Behat\Tests\Behat\FlowContextTrait;
use Neos\Behat\FlowBootstrapTrait;
use Neos\ContentGraph\DoctrineDbalAdapter\Tests\Behavior\Features\Bootstrap\ProjectionIntegrityViolationDetectionTrait;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\CRBehavioralTestsSubjectProvider;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinPyStringNodeBasedNodeTypeManagerFactory;
Expand All @@ -33,7 +32,7 @@
*/
class FeatureContext implements BehatContext
{
use FlowContextTrait;
use FlowBootstrapTrait;
use ProjectionIntegrityViolationDetectionTrait;
use CRTestSuiteTrait;
use CRBehavioralTestsSubjectProvider;
Expand All @@ -42,11 +41,8 @@ class FeatureContext implements BehatContext

public function __construct()
{
if (self::$bootstrap === null) {
self::$bootstrap = $this->initializeFlow();
}
$this->objectManager = self::$bootstrap->getObjectManager();
$this->contentRepositoryRegistry = $this->objectManager->get(ContentRepositoryRegistry::class);
self::bootstrapFlow();
$this->contentRepositoryRegistry = $this->getObject(ContentRepositoryRegistry::class);

$this->setupCRTestSuiteTrait();
$this->setupDbalGraphAdapterIntegrityViolationTrait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

/**
* Custom context trait for projection integrity violation detection specific to the Doctrine DBAL content graph adapter
*
* @todo move this class somewhere where its autoloaded
*/
trait ProjectionIntegrityViolationDetectionTrait
{
Expand All @@ -41,6 +43,14 @@ trait ProjectionIntegrityViolationDetectionTrait

protected Result $lastIntegrityViolationDetectionResult;

/**
* @template T of object
* @param class-string<T> $className
*
* @return T
*/
abstract private function getObject(string $className): object;

protected function getTableNamePrefix(): string
{
return DoctrineDbalContentGraphProjectionFactory::graphProjectionTableNamePrefix(
Expand All @@ -50,7 +60,7 @@ protected function getTableNamePrefix(): string

public function setupDbalGraphAdapterIntegrityViolationTrait()
{
$this->dbalClient = $this->getObjectManager()->get(DbalClient::class);
$this->dbalClient = $this->getObject(DbalClient::class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* source code.
*/

require_once(__DIR__ . '/../../../../../Application/Neos.Behat/Tests/Behat/FlowContextTrait.php');
// @todo remove this require statement
require_once(__DIR__ . '/../../../../Neos.ContentGraph.DoctrineDbalAdapter/Tests/Behavior/Features/Bootstrap/ProjectionIntegrityViolationDetectionTrait.php');

use Behat\Behat\Context\Context as BehatContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use GuzzleHttp\Psr7\Uri;
use Neos\Behat\Tests\Behat\FlowContextTrait;
use Neos\Behat\FlowBootstrapTrait;
use Neos\ContentGraph\DoctrineDbalAdapter\Tests\Behavior\Features\Bootstrap\ProjectionIntegrityViolationDetectionTrait;
use Neos\ContentRepository\BehavioralTests\ProjectionRaceConditionTester\Dto\TraceEntryType;
use Neos\ContentRepository\BehavioralTests\ProjectionRaceConditionTester\RedisInterleavingLogger;
Expand All @@ -38,14 +38,13 @@
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\StructureAdjustmentsTrait;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;

/**
* Features context
*/
class FeatureContext implements BehatContext
{
use FlowContextTrait;
use FlowBootstrapTrait;
use CRTestSuiteTrait;
use CRBehavioralTestsSubjectProvider;
use ProjectionIntegrityViolationDetectionTrait;
Expand All @@ -58,22 +57,19 @@ class FeatureContext implements BehatContext

public function __construct()
{
if (self::$bootstrap === null) {
self::$bootstrap = $this->initializeFlow();
}
$this->objectManager = self::$bootstrap->getObjectManager();
self::bootstrapFlow();

$this->dbalClient = $this->getObjectManager()->get(DbalClientInterface::class);
$this->dbalClient = $this->getObject(DbalClientInterface::class);
$this->setupCRTestSuiteTrait();
$this->setUpInterleavingLogger();
$this->contentRepositoryRegistry = $this->objectManager->get(ContentRepositoryRegistry::class);
$this->contentRepositoryRegistry = $this->getObject(ContentRepositoryRegistry::class);
}

private function setUpInterleavingLogger(): void
{
// prepare race tracking for debugging into the race log
if (class_exists(RedisInterleavingLogger::class)) { // the class must exist (the package loaded)
$raceConditionTrackerConfig = $this->getObjectManager()->get(ConfigurationManager::class)
$raceConditionTrackerConfig = $this->getObject(ConfigurationManager::class)
->getConfiguration(
ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
'Neos.ContentRepository.BehavioralTests.raceConditionTracker'
Expand Down Expand Up @@ -115,11 +111,6 @@ public function resetContentRepositoryComponents(BeforeScenarioScope $scope): vo
GherkinPyStringNodeBasedNodeTypeManagerFactory::reset();
}

protected function getObjectManager(): ObjectManagerInterface
{
return $this->objectManager;
}

protected function getContentRepositoryService(
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php
declare(strict_types=1);

require_once(__DIR__ . '/../../../../../Application/Neos.Behat/Tests/Behat/FlowContextTrait.php');

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use League\Flysystem\FileAttributes;
use League\Flysystem\Filesystem;
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
use Neos\Behat\Tests\Behat\FlowContextTrait;
use Neos\Behat\FlowBootstrapTrait;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\CRBehavioralTestsSubjectProvider;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinPyStringNodeBasedNodeTypeManagerFactory;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinTableNodeBasedContentDimensionSourceFactory;
Expand Down Expand Up @@ -43,7 +41,7 @@
*/
class FeatureContext implements Context
{
use FlowContextTrait;
use FlowBootstrapTrait;
use CRTestSuiteTrait;
use CRBehavioralTestsSubjectProvider;

Expand All @@ -70,11 +68,8 @@ class FeatureContext implements Context

public function __construct()
{
if (self::$bootstrap === null) {
self::$bootstrap = $this->initializeFlow();
}
$this->objectManager = self::$bootstrap->getObjectManager();
$this->contentRepositoryRegistry = $this->objectManager->get(ContentRepositoryRegistry::class);
self::bootstrapFlow();
$this->contentRepositoryRegistry = $this->getObject(ContentRepositoryRegistry::class);

$this->mockFilesystemAdapter = new InMemoryFilesystemAdapter();
$this->mockFilesystem = new Filesystem($this->mockFilesystemAdapter);
Expand Down Expand Up @@ -120,7 +115,7 @@ public function iHaveTheFollowingNodeDataRows(TableNode $nodeDataRows): void
public function iRunTheEventMigration(string $contentStream = null): void
{
$nodeTypeManager = $this->currentContentRepository->getNodeTypeManager();
$propertyMapper = $this->getObjectManager()->get(PropertyMapper::class);
$propertyMapper = $this->getObject(PropertyMapper::class);
$contentGraph = $this->currentContentRepository->getContentGraph();
$nodeFactory = (new \ReflectionClass($contentGraph))
->getProperty('nodeFactory')
Expand All @@ -130,7 +125,7 @@ public function iRunTheEventMigration(string $contentStream = null): void
->getValue($nodeFactory);
$interDimensionalVariationGraph = $this->currentContentRepository->getVariationGraph();

$eventNormalizer = $this->getObjectManager()->get(EventNormalizer::class);
$eventNormalizer = $this->getObject(EventNormalizer::class);
$migration = new NodeDataToEventsProcessor(
$nodeTypeManager,
$propertyMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Neos\ContentRepositoryRegistry\TestSuite\Behavior;

use Doctrine\DBAL\Connection;
use Neos\Behat\Tests\Behat\FlowContextTrait;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
Expand All @@ -24,15 +23,11 @@
use Neos\ContentRepositoryRegistry\Exception\ContentRepositoryNotFoundException;
use Neos\EventStore\EventStoreInterface;

require_once(__DIR__ . '/../../../../../Application/Neos.Behat/Tests/Behat/FlowContextTrait.php');

/**
* The node creation trait for behavioral tests
*/
trait CRRegistrySubjectProvider
{
use FlowContextTrait;

protected ContentRepositoryRegistry $contentRepositoryRegistry;

protected ?ContentRepository $currentContentRepository = null;
Expand All @@ -42,13 +37,17 @@ trait CRRegistrySubjectProvider
*/
protected array $alreadySetUpContentRepositories = [];

/**
* @template T of object
* @param class-string<T> $className
*
* @return T
*/
abstract protected function getObject(string $className): object;

protected function setUpCRRegistry(): void
{
if (self::$bootstrap === null) {
self::$bootstrap = $this->initializeFlow();
}
$this->objectManager = self::$bootstrap->getObjectManager();
$this->contentRepositoryRegistry = $this->objectManager->get(ContentRepositoryRegistry::class);
$this->contentRepositoryRegistry = $this->getObject(ContentRepositoryRegistry::class);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Neos.Neos/Classes/Service/EditorContentStreamZookeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ final class EditorContentStreamZookeeper
public function relayEditorAuthentication(Authentication\TokenInterface $token): void
{
$requestHandler = $this->bootstrap->getActiveRequestHandler();
assert($requestHandler instanceof HttpRequestHandlerInterface);
if (!$requestHandler instanceof HttpRequestHandlerInterface) {
// we might be in testing context
return;
}
$siteDetectionResult = SiteDetectionResult::fromRequest($requestHandler->getHttpRequest());
$contentRepository = $this->contentRepositoryRegistry->get($siteDetectionResult->contentRepositoryId);

Expand Down
23 changes: 13 additions & 10 deletions Neos.Neos/Tests/Behavior/Features/Bootstrap/BrowserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ trait BrowserTrait
use CRTestSuiteRuntimeVariables;

/**
* @return \Neos\Flow\ObjectManagement\ObjectManagerInterface
* @var \Neos\Flow\Http\Client\Browser
*/
abstract protected function getObjectManager();
protected $browser;

/**
* @var \Neos\Flow\Http\Client\Browser
* @template T of object
* @param class-string<T> $className
*
* @return T
*/
protected $browser;
abstract private function getObject(string $className): object;

/**
* @BeforeScenario
Expand All @@ -50,11 +53,11 @@ public function setupBrowserForEveryScenario()
{
// we reset the security context at the beginning of every scenario; such that we start with a clean session at
// every scenario and SHARE the session throughout the scenario!
$this->getObjectManager()->get(\Neos\Flow\Security\Context::class)->clearContext();
$this->getObject(\Neos\Flow\Security\Context::class)->clearContext();

$this->browser = new \Neos\Flow\Http\Client\Browser();
$this->browser->setRequestEngine(new \Neos\Neos\Testing\CustomizedInternalRequestEngine());
$bootstrap = $this->getObjectManager()->get(\Neos\Flow\Core\Bootstrap::class);
$bootstrap = $this->getObject(\Neos\Flow\Core\Bootstrap::class);

$requestHandler = new \Neos\Flow\Tests\FunctionalTestRequestHandler($bootstrap);
$serverRequestFactory = new ServerRequestFactory(new UriFactory());
Expand Down Expand Up @@ -229,7 +232,7 @@ protected function replacePlaceholders($nodeAddressString)
*/
public function iSendTheFollowingChanges(TableNode $changeDefinition)
{
$this->getObjectManager()->get(\Neos\Neos\Ui\Domain\Model\FeedbackCollection::class)->reset();
$this->getObject(\Neos\Neos\Ui\Domain\Model\FeedbackCollection::class)->reset();

$changes = [];
foreach ($changeDefinition->getHash() as $singleChange) {
Expand All @@ -244,7 +247,7 @@ public function iSendTheFollowingChanges(TableNode $changeDefinition)
}

$server = [
'HTTP_X_FLOW_CSRFTOKEN' => $this->getObjectManager()->get(\Neos\Flow\Security\Context::class)->getCsrfProtectionToken(),
'HTTP_X_FLOW_CSRFTOKEN' => $this->getObject(\Neos\Flow\Security\Context::class)->getCsrfProtectionToken(),
];
$this->currentResponse = $this->browser->request('http://localhost/neos/ui-services/change', 'POST', ['changes' => $changes], [], $server);
$this->currentResponseContents = $this->currentResponse->getBody()->getContents();
Expand All @@ -257,15 +260,15 @@ public function iSendTheFollowingChanges(TableNode $changeDefinition)
*/
public function iPublishTheFollowingNodes(string $targetWorkspaceName, TableNode $nodesToPublish)
{
$this->getObjectManager()->get(\Neos\Neos\Ui\Domain\Model\FeedbackCollection::class)->reset();
$this->getObject(\Neos\Neos\Ui\Domain\Model\FeedbackCollection::class)->reset();

$nodeContextPaths = [];
foreach ($nodesToPublish->getHash() as $singleChange) {
$nodeContextPaths[] = $this->replacePlaceholders($singleChange['Subject Node Address']);
}

$server = [
'HTTP_X_FLOW_CSRFTOKEN' => $this->getObjectManager()->get(\Neos\Flow\Security\Context::class)->getCsrfProtectionToken(),
'HTTP_X_FLOW_CSRFTOKEN' => $this->getObject(\Neos\Flow\Security\Context::class)->getCsrfProtectionToken(),
];
$payload = [
'nodeContextPaths' => $nodeContextPaths,
Expand Down
24 changes: 10 additions & 14 deletions Neos.Neos/Tests/Behavior/Features/Bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

use Behat\Behat\Context\Context as BehatContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Neos\Behat\Tests\Behat\FlowContextTrait;
use Neos\Behat\FlowBootstrapTrait;
use Neos\Behat\FlowEntitiesTrait;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\CRBehavioralTestsSubjectProvider;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinPyStringNodeBasedNodeTypeManagerFactory;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinTableNodeBasedContentDimensionSourceFactory;
Expand All @@ -24,13 +25,11 @@
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\MigrationsTrait;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Utility\Environment;
use Neos\Utility\Files;

require_once(__DIR__ . '/../../../../../../Application/Neos.Behat/Tests/Behat/FlowContextTrait.php');

class FeatureContext implements BehatContext
{
use FlowContextTrait;
use FlowBootstrapTrait;
use FlowEntitiesTrait;
use BrowserTrait;

use CRTestSuiteTrait;
Expand All @@ -45,12 +44,9 @@ class FeatureContext implements BehatContext

public function __construct()
{
if (self::$bootstrap === null) {
self::$bootstrap = $this->initializeFlow();
}
$this->objectManager = self::$bootstrap->getObjectManager();
$this->environment = $this->objectManager->get(Environment::class);
$this->contentRepositoryRegistry = $this->objectManager->get(ContentRepositoryRegistry::class);
self::bootstrapFlow();
$this->environment = $this->getObject(Environment::class);
$this->contentRepositoryRegistry = $this->getObject(ContentRepositoryRegistry::class);

$this->setupCRTestSuiteTrait(true);
}
Expand All @@ -72,13 +68,13 @@ public function resetPersistenceManagerAndFeedbackCollection()
// FIXME: we have some strange race condition between the scenarios; my theory is that
// somehow projectors still run in the background when we start from scratch...
sleep(2);
$this->getObjectManager()->get(\Neos\Flow\Persistence\PersistenceManagerInterface::class)->clearState();
$this->getObject(\Neos\Flow\Persistence\PersistenceManagerInterface::class)->clearState();
// FIXME: FeedbackCollection is a really ugly, hacky SINGLETON; so it needs to be RESET!
$this->getObjectManager()->get(\Neos\Neos\Ui\Domain\Model\FeedbackCollection::class)->reset();
$this->getObject(\Neos\Neos\Ui\Domain\Model\FeedbackCollection::class)->reset();

// The UserService has a runtime cache - which we need to reset as well as our users get new IDs.
// Did I already mention I LOVE in memory caches? ;-) ;-) ;-)
$userService = $this->getObjectManager()->get(\Neos\Neos\Domain\Service\UserService::class);
$userService = $this->getObject(\Neos\Neos\Domain\Service\UserService::class);
\Neos\Utility\ObjectAccess::setProperty($userService, 'runtimeUserCache', [], true);
}

Expand Down
Loading

0 comments on commit d496755

Please sign in to comment.