sharedStorage = $sharedStorage; $this->randomStringGenerator = $randomStringGenerator; $this->blockFactory = $blockFactory; $this->blockRepository = $blockRepository; } /** * @Given there is a dynamic content block * @Given there is a block in the store */ public function thereIsADynamicContentBlock(): void { $block = $this->createBlock(); $this->saveBlock($block); } /** * @Given there is an existing block with :code code */ public function thereIsABlockWithCode(string $code): void { $block = $this->createBlock($code); $this->saveBlock($block); } /** * @Given there is a block with :code code and :content content */ public function thereIsABlockWithCodeAndContent(string $code, string $content): void { $block = $this->createBlock($code, $content); $this->saveBlock($block); } private function createBlock( ?string $code = null, ?string $content = null, ChannelInterface $channel = null ): BlockInterface { /** @var BlockInterface $block */ $block = $this->blockFactory->createNew(); $block->setCurrentLocale('en_US'); if (null === $channel && $this->sharedStorage->has('channel')) { $channel = $this->sharedStorage->get('channel'); } if (null === $code) { $code = $this->randomStringGenerator->generate(); } if (null === $content) { $content = $this->randomStringGenerator->generate(); } $block->setCode($code); $block->setContent($content); $block->addChannel($channel); return $block; } private function saveBlock(BlockInterface $block): void { $this->blockRepository->add($block); $this->sharedStorage->set('block', $block); } }