Skip to content

Commit b0b60e8

Browse files
committed
HP-2508 Support representations retrieval by price type
1 parent 00663c0 commit b0b60e8

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/product/Application/BillingRegistryService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public function __construct(private readonly BillingRegistryInterface $registry)
2727

2828
public function getRepresentationsByType(string $representationClass): array
2929
{
30-
if (!class_exists($representationClass)) {
30+
if (!class_exists($representationClass) && !interface_exists($representationClass)) {
3131
throw new InvalidRepresentationException("Class '$representationClass' does not exist");
3232
}
3333

34-
if (!is_subclass_of($representationClass, RepresentationInterface::class)) {
34+
if (class_exists($representationClass) && !is_subclass_of($representationClass, RepresentationInterface::class)) {
3535
throw new InvalidBehaviorException(
3636
sprintf('Representation class "%s" does not implement RepresentationInterface', $representationClass)
3737
);

tests/unit/product/Application/BillingRegistryServiceTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace hiqdev\php\billing\tests\unit\product\Application;
44

5+
use hiqdev\billing\registry\invoice\InvoiceRepresentation;
6+
use hiqdev\billing\registry\invoice\PaymentRequestRepresentation;
57
use hiqdev\php\billing\product\Application\BillingRegistryService;
68
use hiqdev\php\billing\product\behavior\BehaviorNotFoundException;
79
use hiqdev\php\billing\product\BillingRegistry;
810
use hiqdev\php\billing\product\Exception\AggregateNotFoundException;
911
use hiqdev\php\billing\product\invoice\InvalidRepresentationException;
12+
use hiqdev\php\billing\product\invoice\RepresentationInterface;
1013
use hiqdev\php\billing\product\TariffTypeDefinition;
1114
use hiqdev\php\billing\tests\unit\product\behavior\FakeBehavior;
1215
use hiqdev\php\billing\tests\unit\product\behavior\TestBehavior;
@@ -39,6 +42,28 @@ public function testGetAggregateThrowsExceptionWhenNotFound(): void
3942
$this->registryService->getAggregate('non-existent-type');
4043
}
4144

45+
public function testGetRepresentationsByInterfaceReturnsAllRepresentations(): void
46+
{
47+
$tariffType = new DummyTariffType();
48+
$tariffTypeDefinition = new TariffTypeDefinition($tariffType);
49+
50+
$tariffTypeDefinition
51+
->withPrices()
52+
->priceType(Type::anyId('dummy'))
53+
->documentRepresentation()
54+
->attach(new InvoiceRepresentation("Invoice"))
55+
->attach(new PaymentRequestRepresentation("Payment Request"))
56+
->end()
57+
->end()
58+
->end();
59+
60+
$this->registry->addTariffType($tariffTypeDefinition);
61+
62+
$representations = $this->registryService->getRepresentationsByType(RepresentationInterface::class);
63+
64+
$this->assertCount(2, $representations);
65+
}
66+
4267
public function testGetBehavior(): void
4368
{
4469
$tariffType = new DummyTariffType();

0 commit comments

Comments
 (0)