ShopConfigurator example

class ShopConfigurationService
{
    /** * @param Shop $shop */
    public function updateShop(array $shop, Connection $connection): void
    {
        if (empty($shop['locale']) || empty($shop['host'])) {
            throw new \RuntimeException('Please fill in all required fields. (shop configuration)');
        }

        $shopConfigurator = new ShopConfigurator($connection);
        $shopConfigurator->updateBasicInformation($shop['name']$shop['email']);
        $shopConfigurator->setDefaultLanguage($shop['locale']);
        $shopConfigurator->setDefaultCurrency($shop['currency']);

        $this->deleteAllSalesChannelCurrencies($connection);

        $newSalesChannelId = Uuid::randomBytes();
        $this->createSalesChannel($newSalesChannelId$shop$connection);
        $this->createSalesChannelDomain($newSalesChannelId$shop$connection);
    }

    

    private ShopConfigurator $shopConfigurator;

    /** * @var Connection&MockObject */
    private Connection $connection;

    protected function setUp(): void
    {
        $this->connection = $this->createMock(Connection::class);
        $this->shopConfigurator = new ShopConfigurator($this->connection);
    }

    public function testUpdateBasicInformation(): void
    {
        $this->connection->expects(static::exactly(2))->method('executeStatement')->willReturnCallback(function Dstring $sql, array $parameters): void {
            static::assertEquals(
                trim($sql),
                'INSERT INTO `system_config` (`id`, `configuration_key`, `configuration_value`, `sales_channel_id`, `created_at`) VALUES (:id, :key, :value, NULL, NOW()) ON DUPLICATE KEY UPDATE `configuration_value` = :value, `updated_at` = NOW()'
Home | Imprint | This part of the site doesn't use cookies.