Skip to content

Commit

Permalink
Merge pull request #46 from shopware/make-in-memory-the-default
Browse files Browse the repository at this point in the history
feat: make in-memory the default
  • Loading branch information
shyim authored Sep 19, 2024
2 parents c38347d + 61b7f50 commit f6f2a18
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getConfigTreeBuilder(): TreeBuilder

// @phpstan-ignore-next-line
$rootNode->children()
->scalarNode('storage')->defaultValue('doctrine')->end()
->scalarNode('storage')->defaultValue('in-memory')->end()
->arrayNode('doctrine')
->children()
->scalarNode('shop_class')
Expand Down
5 changes: 4 additions & 1 deletion src/DependencyInjection/ShopwareAppExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use AsyncAws\DynamoDb\DynamoDbClient;
use Shopware\App\SDK\Adapter\DynamoDB\DynamoDBRepository;
use Shopware\App\SDK\Shop\ShopRepositoryInterface;
use Shopware\App\SDK\Test\MockShopRepository;
use Shopware\AppBundle\Entity\AbstractShop;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -33,9 +34,11 @@ public function load(array $configs, ContainerBuilder $container): void
$service->setArgument(0, new Reference(DynamoDbClient::class));
$service->setArgument(1, $config['dynamodb']['table_name'] ?? 'shops');
$container->setDefinition(ShopRepositoryInterface::class, $service);
} else {
} elseif ($config['storage'] === 'doctrine') {
$container->getDefinition(ShopRepositoryInterface::class)
->replaceArgument(0, $config['doctrine']['shop_class'] ?? AbstractShop::class);
} else {
$container->setDefinition(ShopRepositoryInterface::class, new Definition(MockShopRepository::class));
}

$container->getDefinition(AppConfigurationFactory::class)
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function getComparableTreeBuilder(): TreeBuilder
$rootNode = $treeBuilder->getRootNode();

$rootNode->children()
->scalarNode('storage')->defaultValue('doctrine')->end()
->scalarNode('storage')->defaultValue('in-memory')->end()
->arrayNode('doctrine')
->children()
->scalarNode('shop_class')
Expand Down
23 changes: 21 additions & 2 deletions tests/DependencyInjection/ShopwareAppExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,36 @@

namespace Shopware\AppBundle\Test\DependencyInjection;

use AsyncAws\DynamoDb\DynamoDbClient;
use PHPUnit\Framework\TestCase;
use Shopware\App\SDK\Adapter\DynamoDB\DynamoDBShop;
use Shopware\App\SDK\Shop\ShopRepositoryInterface;
use Shopware\App\SDK\Test\MockShopRepository;
use Shopware\AppBundle\DependencyInjection\AppConfigurationFactory;
use Shopware\AppBundle\DependencyInjection\ShopwareAppExtension;
use Shopware\AppBundle\Entity\AbstractShop;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class ShopwareAppExtensionTest extends TestCase
{
public function testLoadConfig(): void
public function testDefaultConfig(): void
{
$extension = new ShopwareAppExtension();
$container = new ContainerBuilder();
$extension->load([], $container);

static::assertTrue($container->hasDefinition(ShopRepositoryInterface::class));

static::assertSame(MockShopRepository::class, $container->getDefinition(ShopRepositoryInterface::class)->getClass());
}

public function testLoadConfig(): void
{
$extension = new ShopwareAppExtension();
$container = new ContainerBuilder();
$extension->load(['my_bundle' => ['storage' => 'doctrine']], $container);

static::assertTrue($container->hasDefinition(ShopRepositoryInterface::class));
static::assertTrue($container->hasDefinition(AppConfigurationFactory::class));

Expand All @@ -43,7 +57,7 @@ public function testLoadConfigOverwriteShopClass(): void
{
$extension = new ShopwareAppExtension();
$container = new ContainerBuilder();
$extension->load(['my_bundle' => ['doctrine' => ['shop_class' => DynamoDBShop::class]]], $container);
$extension->load(['my_bundle' => ['storage' => 'doctrine', 'doctrine' => ['shop_class' => DynamoDBShop::class]]], $container);

static::assertTrue($container->hasDefinition(ShopRepositoryInterface::class));
static::assertTrue($container->hasDefinition(AppConfigurationFactory::class));
Expand Down Expand Up @@ -91,6 +105,11 @@ public function testLoadUseDynamoDBOverwriteTableName(): void

static::assertCount(2, $container->getDefinition(ShopRepositoryInterface::class)->getArguments());

$client = $container->getDefinition(ShopRepositoryInterface::class)->getArgument(0);
static::assertInstanceOf(Reference::class, $client);

static::assertSame(DynamoDbClient::class, $client->__toString());

$shopClass = $container->getDefinition(ShopRepositoryInterface::class)->getArgument(1);

static::assertSame('foo', $shopClass);
Expand Down

0 comments on commit f6f2a18

Please sign in to comment.