Skip to content

Commit

Permalink
Merge pull request #41 from shopware/fix/use-shop-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-Rades authored Oct 24, 2023
2 parents 5a1d2c7 + 37a08b5 commit 6fb93fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions infection.json5
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
},
"mutators": {
"@default": true,
"MatchArmRemoval": {
"ignoreSourceCodeByRegex": [
"default => throw new \\\\RuntimeException\\(sprintf\\('Unsupported type %s', \\$type\\)\\).*"
]
}
}
}
11 changes: 5 additions & 6 deletions src/Entity/ShopRepositoryBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
use Shopware\App\SDK\Shop\ShopRepositoryInterface;

/**
* @implements ShopRepositoryInterface<AbstractShop>
* @implements ShopRepositoryInterface<ShopInterface>
*/
class ShopRepositoryBridge implements ShopRepositoryInterface
{
/**
* @param class-string<AbstractShop> $entityClass
* @param class-string<ShopInterface> $entityClass
*/
public function __construct(
private readonly string $entityClass,
private readonly ManagerRegistry $registry
) {
if (!is_subclass_of($this->entityClass, AbstractShop::class)) {
throw new \InvalidArgumentException(sprintf('The shop entity class "%s" must extend "%s"', $this->entityClass, AbstractShop::class));
if (!is_subclass_of($this->entityClass, ShopInterface::class)) {
throw new \InvalidArgumentException(sprintf('The shop entity class "%s" must implement "%s"', $this->entityClass, ShopInterface::class));
}
if ($this->registry->getManagerForClass($this->entityClass) === null) {
throw new \InvalidArgumentException(sprintf('The shop entity class "%s" must be a doctrine managed entity', $this->entityClass));
Expand Down Expand Up @@ -65,9 +65,8 @@ public function deleteShop(string $shopId): void

private function getManager(): ObjectManager
{
/** @var ObjectManager $manager */
$manager = $this->registry->getManagerForClass($this->entityClass);
// we check that $shopEntity is a doctrine entity in the constructor
assert($manager !== null);
return $manager;
}
}
6 changes: 3 additions & 3 deletions tests/Entity/BaseShopRepositoryBridgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class BaseShopRepositoryBridgeTest extends TestCase
{
public function testConstructionFailsWithIncorrectShopEntity()
public function testConstructionFailsWithIncorrectShopEntity(): void
{
static::expectException(\InvalidArgumentException::class);

Expand All @@ -34,7 +34,7 @@ public function testConstructionFailsWithIncorrectShopEntity()
}


public function testConstructionFailsForNonDoctrineEntities()
public function testConstructionFailsForNonDoctrineEntities(): void
{
$this->expectException(\InvalidArgumentException::class);

Expand All @@ -51,7 +51,7 @@ public function __construct(string $shopId, string $shopUrl, string $shopSecret)
);
}

public function testBridgeCanConstructCustomShopEntity()
public function testBridgeCanConstructCustomShopEntity(): void
{
$customShop = new class ('', '', '') extends AbstractShop {
public function __construct(string $shopId, string $shopUrl, string $shopSecret)
Expand Down

0 comments on commit 6fb93fe

Please sign in to comment.