Skip to content

Commit

Permalink
TASK: Remove Gherkin specific logic from static fake factories
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 10, 2024
1 parent 1761ae9 commit 9772caf
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Neos\ContentRepository\TestSuite\Fakes\GherkinTableNodeBasedContentDimensionSource;
use Neos\ContentRepository\TestSuite\Fakes\GherkinTableNodeBasedContentDimensionSourceFactory;
use Neos\EventStore\EventStoreInterface;
use Symfony\Component\Yaml\Yaml;

/**
* Subject provider for behavioral tests
Expand Down Expand Up @@ -59,23 +60,25 @@ protected function getContentRepository(ContentRepositoryId $contentRepositoryId
*/
public function usingNoContentDimensions(): void
{
GherkinTableNodeBasedContentDimensionSourceFactory::$contentDimensionsToUse = GherkinTableNodeBasedContentDimensionSource::createEmpty();
GherkinTableNodeBasedContentDimensionSourceFactory::setWithoutDimensions();
}

/**
* @Given /^using the following content dimensions:$/
*/
public function usingTheFollowingContentDimensions(TableNode $contentDimensions): void
{
GherkinTableNodeBasedContentDimensionSourceFactory::initializeFromTableNode($contentDimensions);
GherkinTableNodeBasedContentDimensionSourceFactory::setContentDimensionSource(
GherkinTableNodeBasedContentDimensionSource::fromGherkinTableNode($contentDimensions)
);
}

/**
* @Given /^using the following node types:$/
*/
public function usingTheFollowingNodeTypes(PyStringNode $serializedNodeTypesConfiguration): void
{
GherkinPyStringNodeBasedNodeTypeManagerFactory::initializeWithPyStringNode($serializedNodeTypesConfiguration);
GherkinPyStringNodeBasedNodeTypeManagerFactory::setConfiguration(Yaml::parse($serializedNodeTypesConfiguration->getRaw()) ?? []);
}

/**
Expand All @@ -99,8 +102,11 @@ public function iChangeTheContentDimensionsInContentRepositoryTo(string $content
throw new \DomainException('undeclared content repository ' . $contentRepositoryId);
} else {
$contentRepository = $this->contentRepositories[$contentRepositoryId];
GherkinPyStringNodeBasedNodeTypeManagerFactory::$nodeTypesToUse = $contentRepository->getNodeTypeManager();
GherkinTableNodeBasedContentDimensionSourceFactory::initializeFromTableNode($contentDimensions);
// ensure that the current node types of exactly THE content repository are preserved
GherkinPyStringNodeBasedNodeTypeManagerFactory::setNodeTypeManager($contentRepository->getNodeTypeManager());
GherkinTableNodeBasedContentDimensionSourceFactory::setContentDimensionSource(
GherkinTableNodeBasedContentDimensionSource::fromGherkinTableNode($contentDimensions)
);
$this->contentRepositories[$contentRepositoryId] = $this->createContentRepository(ContentRepositoryId::fromString($contentRepositoryId));
if ($this->currentContentRepository->id->value === $contentRepositoryId) {
$this->currentContentRepository = $this->contentRepositories[$contentRepositoryId];
Expand All @@ -119,8 +125,9 @@ public function iChangeTheNodeTypesInContentRepositoryTo(
throw new \DomainException('undeclared content repository ' . $contentRepositoryId);
} else {
$contentRepository = $this->contentRepositories[$contentRepositoryId];
GherkinPyStringNodeBasedNodeTypeManagerFactory::initializeWithPyStringNode($serializedNodeTypesConfiguration);
GherkinTableNodeBasedContentDimensionSourceFactory::$contentDimensionsToUse = $contentRepository->getContentDimensionSource();
// ensure that the current node types of exactly THE content repository are preserved
GherkinTableNodeBasedContentDimensionSourceFactory::setContentDimensionSource($contentRepository->getContentDimensionSource());
GherkinPyStringNodeBasedNodeTypeManagerFactory::setConfiguration(Yaml::parse($serializedNodeTypesConfiguration->getRaw()) ?? []);
$this->contentRepositories[$contentRepositoryId] = $this->createContentRepository(ContentRepositoryId::fromString($contentRepositoryId));
if ($this->currentContentRepository->id->value === $contentRepositoryId) {
$this->currentContentRepository = $this->contentRepositories[$contentRepositoryId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,42 @@

namespace Neos\ContentRepository\TestSuite\Fakes;

use Behat\Gherkin\Node\PyStringNode;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\Factory\NodeTypeManager\NodeTypeManagerFactoryInterface;
use Symfony\Component\Yaml\Yaml;

/**
* Factory for node type managers from gherkin py strings
*/
final class GherkinPyStringNodeBasedNodeTypeManagerFactory implements NodeTypeManagerFactoryInterface
{
public static ?NodeTypeManager $nodeTypesToUse = null;
private static ?NodeTypeManager $nodeTypeManager = null;

/**
* @param array<string,mixed> $options
*/
public function build(ContentRepositoryId $contentRepositoryId, array $options): NodeTypeManager
{
if (!self::$nodeTypesToUse) {
throw new \DomainException('NodeTypeManagerFactory uninitialized');
if (!self::$nodeTypeManager) {
throw new \RuntimeException('NodeTypeManagerFactory uninitialized');
}
return self::$nodeTypesToUse;
return self::$nodeTypeManager;
}

public static function initializeWithPyStringNode(PyStringNode $nodeTypesToUse): void
public static function setConfiguration(array $nodeTypesToUse): void
{
self::$nodeTypesToUse = new NodeTypeManager(
fn (): array => Yaml::parse($nodeTypesToUse->getRaw()) ?? []
self::$nodeTypeManager = new NodeTypeManager(
fn (): array => $nodeTypesToUse
);
}

public static function setNodeTypeManager(NodeTypeManager $nodeTypeManager): void
{
self::$nodeTypeManager = $nodeTypeManager;
}

public static function reset(): void
{
self::$nodeTypesToUse = null;
self::$nodeTypeManager = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@

/**
* The node creation trait for behavioral tests
* todo colocate with GherkinTableNodeBasedContentDimensionSourceFactory
*/
final readonly class GherkinTableNodeBasedContentDimensionSource implements ContentDimensionSourceInterface
{
/** @param array<string,ContentDimension> $contentDimensions */
private function __construct(
/** @var array<string,ContentDimension> */
private array $contentDimensions
) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,52 @@

namespace Neos\ContentRepository\TestSuite\Fakes;

use Behat\Gherkin\Node\TableNode;
use Neos\ContentRepository\Core\Dimension\ContentDimension;
use Neos\ContentRepository\Core\Dimension\ContentDimensionId;
use Neos\ContentRepository\Core\Dimension\ContentDimensionSourceInterface;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\Factory\ContentDimensionSource\ContentDimensionSourceFactoryInterface;

class GherkinTableNodeBasedContentDimensionSourceFactory implements ContentDimensionSourceFactoryInterface
{
public static ?ContentDimensionSourceInterface $contentDimensionsToUse = null;
private static ?ContentDimensionSourceInterface $contentDimensionSource = null;

/**
* @param array<string,mixed> $options
*/
public function build(ContentRepositoryId $contentRepositoryId, array $options): ContentDimensionSourceInterface
{
if (!self::$contentDimensionsToUse) {
throw new \DomainException('Content dimension source not initialized.');
if (!self::$contentDimensionSource) {
throw new \RuntimeException('Content dimension source not initialized.');
}
return self::$contentDimensionsToUse;
return self::$contentDimensionSource;
}

public static function initializeFromTableNode(TableNode $contentDimensionsToUse): void
public static function setContentDimensionSource(ContentDimensionSourceInterface $contentDimensionSource): void
{
self::$contentDimensionsToUse = GherkinTableNodeBasedContentDimensionSource::fromGherkinTableNode($contentDimensionsToUse);
self::$contentDimensionSource = $contentDimensionSource;
}

/**
* Configures a zero-dimensional content repository
*/
public static function setWithoutDimensions(): void
{
self::$contentDimensionSource = new class implements ContentDimensionSourceInterface
{
public function getDimension(ContentDimensionId $dimensionId): ?ContentDimension
{
return null;
}
public function getContentDimensionsOrderedByPriority(): array
{
return [];
}
};
}

public static function reset(): void
{
self::$contentDimensionsToUse = null;
self::$contentDimensionSource = null;
}
}

0 comments on commit 9772caf

Please sign in to comment.