-
Notifications
You must be signed in to change notification settings - Fork 11
HP-2482/Close_prices_and_notices_for_client_and_reseller #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace hiqdev\php\billing\product\Application; | ||
|
||
use Generator; | ||
use hiqdev\php\billing\product\behavior\BehaviorInterface; | ||
use hiqdev\php\billing\product\behavior\BehaviorNotFoundException; | ||
use hiqdev\php\billing\product\behavior\InvalidBehaviorException; | ||
use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface; | ||
|
||
interface BillingRegistryBehaviorServiceInterface | ||
{ | ||
/** | ||
* @param string $type - full type like 'overuse,lb_capacity_unit' | ||
* @param string $behaviorClassWrapper | ||
* @return BehaviorInterface | ||
* @throws BehaviorNotFoundException | ||
* @throws InvalidBehaviorException | ||
*/ | ||
public function getBehavior(string $type, string $behaviorClassWrapper): BehaviorInterface; | ||
|
||
|
||
/** | ||
* Find all behaviors attached to any TariffType or PriceType by specified Behavior class. | ||
* | ||
* @param string $behaviorClassWrapper | ||
* @return Generator<BehaviorInterface> | ||
*/ | ||
public function getBehaviors(string $behaviorClassWrapper): Generator; | ||
|
||
/** | ||
* Find all PriceTypeDefinition in registry by specified Behavior class. | ||
* | ||
* @param string $behaviorClassWrapper | ||
* @return Generator<PriceTypeDefinitionInterface> | ||
*/ | ||
public function findPriceTypeDefinitionsByBehavior(string $behaviorClassWrapper): Generator; | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,7 +13,7 @@ | |||||
use hiqdev\php\billing\product\quantity\QuantityFormatterInterface; | ||||||
use hiqdev\php\billing\product\TariffTypeDefinitionInterface; | ||||||
|
||||||
interface BillingRegistryServiceInterface | ||||||
interface BillingRegistryServiceInterface extends BillingRegistryTariffServiseInterface, BillingRegistryBehaviorServiceInterface | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo in interface name. There's a typo in the interface name: -interface BillingRegistryServiceInterface extends BillingRegistryTariffServiseInterface, BillingRegistryBehaviorServiceInterface
+interface BillingRegistryServiceInterface extends BillingRegistryTariffServiceInterface, BillingRegistryBehaviorServiceInterface 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||
{ | ||||||
/** | ||||||
* @param string $representationClass | ||||||
|
@@ -23,32 +23,6 @@ public function getRepresentationsByType(string $representationClass): array; | |||||
|
||||||
public function createQuantityFormatter(string $type, FractionQuantityData $data): QuantityFormatterInterface; | ||||||
|
||||||
/** | ||||||
* @param string $type - full type like 'overuse,lb_capacity_unit' | ||||||
* @param string $behaviorClassWrapper | ||||||
* @return BehaviorInterface | ||||||
* @throws BehaviorNotFoundException | ||||||
* @throws InvalidBehaviorException | ||||||
*/ | ||||||
public function getBehavior(string $type, string $behaviorClassWrapper): BehaviorInterface; | ||||||
|
||||||
/** | ||||||
* Find all behaviors attached to any TariffType or PriceType by specified Behavior class. | ||||||
* | ||||||
* @param string $behaviorClassWrapper | ||||||
* @return Generator<BehaviorInterface> | ||||||
*/ | ||||||
public function getBehaviors(string $behaviorClassWrapper): Generator; | ||||||
|
||||||
public function getAggregate(string $type): AggregateInterface; | ||||||
|
||||||
public function findTariffTypeDefinitionByBehavior(BehaviorInterface $behavior): TariffTypeDefinitionInterface; | ||||||
|
||||||
/** | ||||||
* Find all PriceTypeDefinition in registry by specified Behavior class. | ||||||
* | ||||||
* @param string $behaviorClassWrapper | ||||||
* @return Generator<PriceTypeDefinitionInterface> | ||||||
*/ | ||||||
public function findPriceTypeDefinitionsByBehavior(string $behaviorClassWrapper): Generator; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||
<?php | ||||||||
|
||||||||
declare(strict_types=1); | ||||||||
|
||||||||
namespace hiqdev\php\billing\product\Application; | ||||||||
|
||||||||
use hiqdev\php\billing\product\behavior\BehaviorInterface; | ||||||||
use hiqdev\php\billing\product\TariffTypeDefinitionInterface; | ||||||||
|
||||||||
interface BillingRegistryTariffServiseInterface | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Fix typo in interface name The interface name contains a typo: "BillingRegistryTariffServiseInterface" should be "BillingRegistryTariffServiceInterface" (missing 'c' in "Service"). -interface BillingRegistryTariffServiseInterface
+interface BillingRegistryTariffServiceInterface This typo will need to be corrected everywhere this interface is referenced. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||
{ | ||||||||
|
||||||||
public function findTariffTypeDefinitionByBehavior(BehaviorInterface $behavior): TariffTypeDefinitionInterface; | ||||||||
|
||||||||
public function getTariffDefinitionByName(string $tariffName): ?TariffTypeDefinitionInterface; | ||||||||
|
||||||||
public function hasBehaviour(TariffTypeDefinitionInterface $tariffTypeDefinition, string $behaviorClassWrapper): bool; | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace hiqdev\php\billing\tests\unit\product\Application; | ||
|
||
use hiqdev\php\billing\product\Application\BillingRegistryService; | ||
use hiqdev\php\billing\product\behavior\BehaviorNotFoundException; | ||
use hiqdev\php\billing\product\BillingRegistry; | ||
use hiqdev\php\billing\product\Exception\AggregateNotFoundException; | ||
use hiqdev\php\billing\product\invoice\InvalidRepresentationException; | ||
use hiqdev\php\billing\product\TariffTypeDefinition; | ||
use hiqdev\php\billing\tests\unit\product\behavior\FakeBehavior; | ||
use hiqdev\php\billing\tests\unit\product\behavior\TestBehavior; | ||
use hiqdev\php\billing\tests\unit\product\Domain\Model\DummyTariffType; | ||
use hiqdev\php\billing\tests\unit\product\Domain\Model\FakeTariffType; | ||
use hiqdev\php\billing\type\Type; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BillingRegistryBehaviorServiceTest extends TestCase | ||
{ | ||
private BillingRegistry $registry; | ||
|
||
private BillingRegistryService $registryService; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->registry = new BillingRegistry(); | ||
$this->registryService = new BillingRegistryService($this->registry); | ||
} | ||
|
||
public function testGetBehavior(): void | ||
{ | ||
$tariffType = new DummyTariffType(); | ||
$tariffTypeDefinition = new TariffTypeDefinition($tariffType); | ||
$dummyBehavior = new TestBehavior('dummy'); | ||
$type = Type::anyId('dummy'); | ||
$tariffTypeDefinition | ||
->withPrices() | ||
->priceType($type) | ||
->withBehaviors() | ||
->attach($dummyBehavior); | ||
|
||
$this->registry->addTariffType($tariffTypeDefinition); | ||
|
||
$behavior = $this->registryService->getBehavior($type->getName(), TestBehavior::class); | ||
|
||
$this->assertSame($dummyBehavior->getContext(), $behavior->getContext()); | ||
} | ||
|
||
public function testGetBehavior_WithMultipleTariffTypeDefinitions(): void | ||
{ | ||
$tariffType = new DummyTariffType(); | ||
$tariffTypeDefinition = new TariffTypeDefinition($tariffType); | ||
$type1 = Type::anyId('type,dummy1'); | ||
$type2 = Type::anyId('type,dummy2'); | ||
$dummyBehavior1 = new TestBehavior('dummy 1'); | ||
$dummyBehavior2 = new TestBehavior('dummy 2'); | ||
$dummyBehavior3 = new FakeBehavior('dummy 3'); | ||
|
||
$tariffTypeDefinition | ||
->withPrices() | ||
->priceType($type1) | ||
->withBehaviors() | ||
->attach($dummyBehavior1) | ||
->end() | ||
->end() | ||
->priceType($type2) | ||
->withBehaviors() | ||
->attach($dummyBehavior2) | ||
->attach($dummyBehavior3) | ||
->end() | ||
->end() | ||
->end(); | ||
|
||
$this->registry->addTariffType($tariffTypeDefinition); | ||
|
||
$behavior = $this->registryService->getBehavior($type1->getName(), TestBehavior::class); | ||
$this->assertSame($dummyBehavior1->getContext(), $behavior->getContext()); | ||
|
||
$behavior = $this->registryService->getBehavior($type2->getName(), TestBehavior::class); | ||
$this->assertSame($dummyBehavior2->getContext(), $behavior->getContext()); | ||
|
||
$behavior = $this->registryService->getBehavior($type2->getName(), FakeBehavior::class); | ||
$this->assertSame($dummyBehavior3->getContext(), $behavior->getContext()); | ||
} | ||
|
||
public function testGetBehavior_WithMultiplePriceTypeDefinitions(): void | ||
{ | ||
$tariffTypeDefinition1 = new TariffTypeDefinition(new DummyTariffType()); | ||
$testBehavior = new TestBehavior('dummy'); | ||
$type1 = Type::anyId('type,dummy1'); | ||
$tariffTypeDefinition1 | ||
->withPrices() | ||
->priceType($type1) | ||
->withBehaviors() | ||
->attach($testBehavior) | ||
->end() | ||
->end() | ||
->end(); | ||
|
||
$tariffTypeDefinition2 = new TariffTypeDefinition(new FakeTariffType()); | ||
$fakeBehavior = new FakeBehavior('dummy'); | ||
$type2 = Type::anyId('type,dummy2'); | ||
$tariffTypeDefinition2 | ||
->withPrices() | ||
->priceType($type2) | ||
->withBehaviors() | ||
->attach($fakeBehavior) | ||
->end() | ||
->end() | ||
->end(); | ||
|
||
$this->registry->addTariffType($tariffTypeDefinition1); | ||
$this->registry->addTariffType($tariffTypeDefinition2); | ||
|
||
/** @var TestBehavior $testBehaviorActual */ | ||
$testBehaviorActual = $this->registryService->getBehavior($type1->getName(), TestBehavior::class); | ||
$this->assertSame($testBehavior->getContext(), $testBehaviorActual->getContext()); | ||
|
||
/** @var FakeBehavior $fakeBehaviorActual */ | ||
$fakeBehaviorActual = $this->registryService->getBehavior($type2->getName(), FakeBehavior::class); | ||
$this->assertSame($fakeBehavior->getContext(), $fakeBehaviorActual->getContext()); | ||
} | ||
|
||
public function testGetBehaviorThrowsExceptionWhenNotFound(): void | ||
{ | ||
$this->expectException(BehaviorNotFoundException::class); | ||
$this->registryService->getBehavior('non-existent-type', TestBehavior::class); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical bug: Missing method call parentheses
The comparison on line 55 is accessing
name
as a property instead of calling thename()
method. Based on theTariffTypeInterface
(line 7),name()
is a method that should be called.📝 Committable suggestion
🤖 Prompt for AI Agents