diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index f9fd315c..eba13004 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.1'] + php: ['8.1', '8.3'] coverage-driver: [pcov] name: PHP ${{ matrix.php }} steps: diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 805d040f..71075746 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.1'] + php: ['8.3'] coverage-driver: [pcov] name: PHP ${{ matrix.php }} steps: diff --git a/.github/workflows/psalm-analysis.yml b/.github/workflows/psalm-analysis.yml new file mode 100644 index 00000000..e0b766da --- /dev/null +++ b/.github/workflows/psalm-analysis.yml @@ -0,0 +1,44 @@ +name: Psalm Static Analysis + +on: + push: + pull_request: + schedule: + - cron: "0 9 * * 1" + +jobs: + psalm: + runs-on: ubuntu-latest + strategy: + matrix: + php: [ '8.3' ] + coverage-driver: [ pcov ] + name: PHP ${{ matrix.php }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: gmp + coverage: pcov + tools: composer:v2, infection + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Update composer + run: composer self-update + + - name: Composer install + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install -n + + - name: Run Psalm + run: vendor/bin/psalm \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 931289b4..00000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,14 +0,0 @@ -checks: - php: - code_rating: true - duplication: true -tools: - php_code_coverage: - enabled: true - external_code_coverage: - timeout: 600 -build: - nodes: - analysis: - tests: - override: [php-scrutinizer-run] diff --git a/composer.json b/composer.json index d570c763..0b821b83 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.3", "moneyphp/money": "^3.0 | ^4.0", "hiqdev/php-units": "dev-master", "psr/simple-cache": "^1.0", @@ -52,14 +52,15 @@ "require-dev": { "ext-intl": "*", "behat/behat": "^3.4.3", - "phpunit/phpunit": "^8.1", + "phpunit/phpunit": "^10.0.0", "league/event": "^2.1", "hoa/ruler": "^2.17", "hiqdev/hidev": "dev-master", "hiqdev/hidev-php": "dev-master", "hiqdev/hidev-behat": "dev-master", "hiqdev/hidev-hiqdev": "dev-master", - "vimeo/psalm": "^3.0", + "hiqdev/php-data-mapper": "dev-master", + "vimeo/psalm": "^5.0", "cache/array-adapter": "*", "matthiasnoback/behat-expect-exception": "^v0.3.0" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3c0a4945..804ccd60 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,9 +5,13 @@ ./tests/unit/ - - + + + ./src/ - - + + + ./vendor/ + + diff --git a/psalm.xml b/psalm.xml index dd796efd..c0bb9e83 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,12 +1,25 @@ + + + @@ -23,7 +36,6 @@ - @@ -43,7 +55,6 @@ - diff --git a/src/Money/MultipliedMoney.php b/src/Money/MultipliedMoney.php index e802e674..3cc10b9c 100644 --- a/src/Money/MultipliedMoney.php +++ b/src/Money/MultipliedMoney.php @@ -4,7 +4,7 @@ namespace hiqdev\php\billing\Money; -use Laminas\Code\Reflection\Exception\InvalidArgumentException; +use InvalidArgumentException; use Money\Currencies\ISOCurrencies; use Money\Currency; use Money\Money; @@ -86,7 +86,7 @@ private static function calculateMultiplierToInteger(string $amount): int return 1; } - [$integer, $fraction] = explode('.', $amount, 2); + [, $fraction] = explode('.', $amount, 2); return (int)('1' . implode(array_fill(0, strlen($fraction), 0))); } diff --git a/src/action/AbstractAction.php b/src/action/AbstractAction.php index 4a500531..42857d01 100755 --- a/src/action/AbstractAction.php +++ b/src/action/AbstractAction.php @@ -13,7 +13,6 @@ use DateInterval; use DateTimeImmutable; use hiqdev\php\billing\customer\CustomerInterface; -use hiqdev\php\billing\EntityInterface; use hiqdev\php\billing\Exception\CannotReassignException; use hiqdev\php\billing\sale\SaleInterface; use hiqdev\php\billing\target\TargetInterface; @@ -27,7 +26,7 @@ * * @author Andrii Vasyliev */ -abstract class AbstractAction implements ActionInterface, EntityInterface +abstract class AbstractAction implements \JsonSerializable, ActionInterface { /** @var int */ protected $id; diff --git a/src/action/ActionInterface.php b/src/action/ActionInterface.php index 5ad95bf9..4662c1b0 100644 --- a/src/action/ActionInterface.php +++ b/src/action/ActionInterface.php @@ -12,6 +12,7 @@ use DateTimeImmutable; use hiqdev\php\billing\customer\CustomerInterface; +use hiqdev\php\billing\EntityInterface; use hiqdev\php\billing\price\PriceInterface; use hiqdev\php\billing\sale\SaleInterface; use hiqdev\php\billing\target\TargetInterface; @@ -30,7 +31,7 @@ * * @author Andrii Vasyliev */ -interface ActionInterface extends \JsonSerializable +interface ActionInterface extends EntityInterface { /** * Returns if the given price applicable to this action. diff --git a/src/charge/modifiers/FixedDiscount.php b/src/charge/modifiers/FixedDiscount.php index 32f23c45..203d5283 100644 --- a/src/charge/modifiers/FixedDiscount.php +++ b/src/charge/modifiers/FixedDiscount.php @@ -45,7 +45,7 @@ public function getValue(ChargeInterface $charge = null): Discount public function isAbsolute() { - return $this->getAddon(self::VALUE)->isAbsolute(); + return $this->getValue()->isAbsolute(); } public function isRelative() diff --git a/src/charge/modifiers/FullCombination.php b/src/charge/modifiers/FullCombination.php index 1b34b5c0..5b5ba510 100644 --- a/src/charge/modifiers/FullCombination.php +++ b/src/charge/modifiers/FullCombination.php @@ -57,7 +57,7 @@ public function modifyCharge(?ChargeInterface $charge, ActionInterface $action): return []; // If there was at least one charge, but it disappeared – modifier does not want this charge to happen. Stop. } - $originalChargeExists = array_reduce($leftCharges, function ($result, Charge $item) use ($charge) { + $originalChargeExists = array_reduce($leftCharges, static function ($result, Charge $item) use ($charge) { return $result || $charge === $item; }, false); if ($charge && !$originalChargeExists) { @@ -66,7 +66,6 @@ public function modifyCharge(?ChargeInterface $charge, ActionInterface $action): // $leftCharge will contain original charge and 0+ additional charges (discounts) } - /** @var Charge $leftTotal */ /** @var Charge $charge */ $leftTotal = $this->sumCharges($charge, $leftCharges); if ($this->right->isSuitable($leftTotal, $action)) { @@ -78,7 +77,6 @@ public function modifyCharge(?ChargeInterface $charge, ActionInterface $action): $lastLeftCharge = end($leftCharges); $rightCharges = array_filter($dirtyRightCharges, function (ChargeInterface $charge) use ($leftTotal, $lastLeftCharge) { - /** @var Charge $charge */ if ($charge->getParent() === $leftTotal) { $charge->overwriteParent($lastLeftCharge); } @@ -109,6 +107,7 @@ public function modifyCharge(?ChargeInterface $charge, ActionInterface $action): $charge->setComment($leftTotal->getComment()); } + /** @var Charge $leftTotal */ $events = $leftTotal->releaseEvents(); if (!empty($events)) { foreach ($events as $event) { diff --git a/src/charge/modifiers/Installment.php b/src/charge/modifiers/Installment.php index 2aff7cb6..dcfe6a10 100644 --- a/src/charge/modifiers/Installment.php +++ b/src/charge/modifiers/Installment.php @@ -56,7 +56,7 @@ public function getTarget() return new Target(Target::ANY, Target::ANY); } - public function till($dummy) + public function till($time) { throw new FormulaSemanticsError('till can not be defined for installment'); } @@ -154,7 +154,7 @@ private function createInstallmentFinishingCharge(ChargeInterface $charge, DateT return $result; } - private function createInstallmentStartingCharge(ChargeInterface $charge, DateTimeImmutable $month): ChargeInterface + private function createInstallmentStartingCharge(Charge $charge, DateTimeImmutable $month): ChargeInterface { $charge->recordThat(InstallmentWasStarted::onCharge($charge, $month)); diff --git a/src/charge/modifiers/addons/Period.php b/src/charge/modifiers/addons/Period.php index 9849b49a..5eb9adf0 100644 --- a/src/charge/modifiers/addons/Period.php +++ b/src/charge/modifiers/addons/Period.php @@ -74,5 +74,5 @@ public static function ensureValidValue($value) * * @return DateTimeImmutable time of period end */ - abstract public function addTo(DateTimeImmutable $startTime): DateTimeImmutable; + abstract public function addTo(DateTimeImmutable $since): DateTimeImmutable; } diff --git a/src/formula/Asserter.php b/src/formula/Asserter.php index 58d44a53..6379b2d0 100644 --- a/src/formula/Asserter.php +++ b/src/formula/Asserter.php @@ -13,6 +13,7 @@ use hiqdev\php\billing\charge\modifiers\FullCombination; use Hoa\Ruler\Context; use Hoa\Ruler\Model\Model; +use Hoa\Visitor\Element; /** * @author Andrii Vasyliev @@ -35,6 +36,11 @@ public function makeAnd($lhs, $rhs) public function visitModel(Model $element, &$handle = null, $eldnah = null) { - return $element->getExpression()->accept($this, $handle, $eldnah); + return $this->getExpression($element)->accept($this, $handle, $eldnah); + } + + private function getExpression(Model $element): Element + { + return $element->getExpression(); } } diff --git a/src/order/Calculator.php b/src/order/Calculator.php index 64b59976..15d2ee57 100644 --- a/src/order/Calculator.php +++ b/src/order/Calculator.php @@ -11,7 +11,6 @@ namespace hiqdev\php\billing\order; use Exception; -use hiqdev\php\billing\action\Action; use hiqdev\php\billing\action\ActionInterface; use hiqdev\php\billing\action\TemporaryActionInterface; use hiqdev\php\billing\charge\Charge; @@ -23,7 +22,6 @@ use hiqdev\php\billing\plan\PlanInterface; use hiqdev\php\billing\plan\PlanRepositoryInterface; use hiqdev\php\billing\price\PriceInterface; -use hiqdev\php\billing\sale\Sale; use hiqdev\php\billing\sale\SaleInterface; use hiqdev\php\billing\sale\SaleRepositoryInterface; use hiqdev\php\billing\tools\ActualDateTimeProvider; @@ -63,14 +61,12 @@ public function calculateOrder(OrderInterface $order): array $plans = $this->findPlans($order); $charges = []; foreach ($order->getActions() as $actionKey => $action) { - if ($plans[$actionKey] === null) { - continue; - } - - try { - $charges = array_merge($charges, $this->calculatePlan($plans[$actionKey], $action)); - } catch (Throwable $e) { - throw ActionChargingException::forAction($action, $e); + if (!empty($plans[$actionKey])) { + try { + $charges = array_merge($charges, $this->calculatePlan($plans[$actionKey], $action)); + } catch (Throwable $e) { + throw ActionChargingException::forAction($action, $e); + } } } @@ -157,19 +153,15 @@ public function calculateCharge(PriceInterface $price, ActionInterface $action): /** * @throws Exception - * @return PlanInterface[]|Plan + * @return PlanInterface[] */ - private function findPlans(OrderInterface $order) + private function findPlans(OrderInterface $order): array { $sales = $this->findSales($order); $plans = []; $lookPlanIds = []; foreach ($order->getActions() as $actionKey => $action) { - /** @var Action $action */ - if ($sales[$actionKey] === false) { - /// it is ok when no sale found for upper resellers - $plans[$actionKey] = null; - } else { + if (!empty($sales[$actionKey])) { $sale = $sales[$actionKey]; /** @var Plan|PlanInterface[] $plan */ $plan = $sale->getPlan(); @@ -185,12 +177,15 @@ private function findPlans(OrderInterface $order) } else { $plans[$actionKey] = null; } + } else { + // It is ok when no sale found for upper resellers + $plans[$actionKey] = null; } } if ($lookPlanIds) { $foundPlans = $this->planRepository->findByIds($lookPlanIds); - foreach ($foundPlans as $actionKey => $plan) { + foreach ($foundPlans as $plan) { $foundPlans[$plan->getId()] = $plan; } foreach ($lookPlanIds as $actionKey => $planId) { @@ -205,9 +200,10 @@ private function findPlans(OrderInterface $order) } /** - * @return SaleInterface[]|Sale + * @param OrderInterface $order + * @return SaleInterface[] */ - private function findSales(OrderInterface $order) + private function findSales(OrderInterface $order): array { $sales = []; $lookActions = []; diff --git a/src/plan/Plan.php b/src/plan/Plan.php index 35db5a30..6f79dabf 100755 --- a/src/plan/Plan.php +++ b/src/plan/Plan.php @@ -109,9 +109,9 @@ public function getParentId(): ?int return $this->parent_id; } - public function setParentId(int $id): void + public function setParentId(int $parentId): void { - $this->parent_id = $id; + $this->parent_id = $parentId; } public function hasPrices(): bool diff --git a/src/price/AbstractPrice.php b/src/price/AbstractPrice.php index 606790b9..938a77d1 100755 --- a/src/price/AbstractPrice.php +++ b/src/price/AbstractPrice.php @@ -146,47 +146,20 @@ public function calculateSum(QuantityInterface $quantity): ?Money return $sum; } + /** + * What purpose of this method? Because it looks like duplicate of PriceHydrator::extract() + * Where we are using the result of this method? + * Magic calls can't be determined and I don't know what can be broken if we change the method result. + * Which structure must have the result, because array can contain anything? + * + * @return array + */ public function jsonSerialize(): array { - $data = [ - 'id' => $this->id, - 'class' => (new \ReflectionClass($this))->getShortName(), - 'type' => $this->getType()->getName(), - 'type_id' => $this->getType()->getId(), - 'object_id' => $this->getTarget()->getId(), - 'object' => [ - 'id' => $this->getTarget()->getId(), - 'name' => $this->getTarget()->getName(), - 'type' => $this->getTarget()->getType(), - ], - 'plan_id' => $this->getPlan()?->getId(), - ]; - - if ($this instanceof PriceWithSubpriceInterface) { - $data['subprice'] = $this->getSubprices()->values(); - } - - if ($this instanceof PriceWithRateInterface) { - $data['rate'] = $this->getRate(); - } - - if ($this instanceof PriceWithUnitInterface) { - $data['unit'] = $this->getUnit()->getName(); - } - - if ($this instanceof PriceWithCurrencyInterface) { - $data['currency'] = $this->getCurrency()->getCode(); - } - - if ($this instanceof PriceWithSumsInterface) { - $data['sums'] = $this->getSums()->values(); - } - - if ($this instanceof PriceWithQuantityInterface) { - $data['quantity'] = $this->getPrepaid()->getQuantity(); - } + $res = array_filter(get_object_vars($this)); + unset($res['plan']); - return $data; + return $res; } /** diff --git a/src/price/PriceInvalidArgumentException.php b/src/price/PriceInvalidArgumentException.php index 309e5725..90a49dce 100644 --- a/src/price/PriceInvalidArgumentException.php +++ b/src/price/PriceInvalidArgumentException.php @@ -2,8 +2,8 @@ namespace hiqdev\php\billing\price; -use hiapi\exceptions\HiapiException; +use hiqdev\php\billing\Exception\RuntimeException; -class PriceInvalidArgumentException extends HiapiException +class PriceInvalidArgumentException extends RuntimeException { } diff --git a/src/price/PriceWithSubpriceInterface.php b/src/price/PriceWithSubpriceInterface.php deleted file mode 100644 index 1faf9304..00000000 --- a/src/price/PriceWithSubpriceInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -price; } diff --git a/src/price/Sums.php b/src/price/Sums.php index 2d10117a..f92c2710 100644 --- a/src/price/Sums.php +++ b/src/price/Sums.php @@ -6,6 +6,9 @@ { /** * @param int[]|null $values quantity => total sum for the quantity + * Quantity of what? + * Sum of what? + * If you know answers please write in the comment */ public function __construct(private ?array $values) { @@ -30,6 +33,11 @@ public function values(): ?array return $this->values; } + public function getSum(int $quantity) + { + return $this->values[$quantity] ?? null; + } + public function getMinSum(): int|string { return min($this->values); diff --git a/src/sale/SaleInterface.php b/src/sale/SaleInterface.php index 843104db..ef2727b1 100644 --- a/src/sale/SaleInterface.php +++ b/src/sale/SaleInterface.php @@ -67,11 +67,11 @@ public function getCloseTime(): ?DateTimeImmutable; public function getData(): ?array; /** - * @param DateTimeImmutable $time + * @param DateTimeImmutable $closeTime * @throws InvariantException * @throws ConstraintException */ - public function close(DateTimeImmutable $time): void; + public function close(DateTimeImmutable $closeTime): void; public function cancelClosing(): void; } diff --git a/src/sale/SaleRepositoryInterface.php b/src/sale/SaleRepositoryInterface.php index be469f51..310511c2 100644 --- a/src/sale/SaleRepositoryInterface.php +++ b/src/sale/SaleRepositoryInterface.php @@ -34,7 +34,7 @@ public function findById(string $id): ?object; /** * Finds suitable sales for given order. - * @return PlanInterface[] array: actionKey => plan + * @return SaleInterface[] array: actionKey => sale */ public function findByOrder(OrderInterface $order); diff --git a/src/tools/DbMergingAggregator.php b/src/tools/DbMergingAggregator.php index 771aef5f..cf70c280 100644 --- a/src/tools/DbMergingAggregator.php +++ b/src/tools/DbMergingAggregator.php @@ -12,6 +12,7 @@ use hiqdev\php\billing\bill\BillInterface; use hiqdev\php\billing\bill\BillRepositoryInterface; +use hiqdev\php\billing\charge\Charge; use hiqdev\php\billing\charge\ChargeInterface; /** @@ -74,6 +75,7 @@ private function excludeLocalOnlyZeroBills(array $localBills, array $dbBills): a { foreach ($localBills as $i => $localBill) { foreach ($localBill->getCharges() as $charge) { + /** @var Charge $charge */ if ($charge->hasEvents()) { continue 2; } diff --git a/tests/support/plan/CertificatePlan.php b/tests/support/plan/CertificatePlan.php index 1736aed8..c37acd81 100644 --- a/tests/support/plan/CertificatePlan.php +++ b/tests/support/plan/CertificatePlan.php @@ -108,9 +108,10 @@ public function __construct() */ public function getRawPrice($action) { - $years = $action->getQuantity()->convert(Unit::year())->getQuantity(); + $quantity = $action->getQuantity()->convert(Unit::year())->getQuantity(); - return $this->getRawPrices($action->getType(), $action->getTarget())[$years]; + return $this->getRawPrices($action->getType(), $action->getTarget()) + ->getSum($quantity); } public function getRawPrices($type, $target): Sums diff --git a/tests/unit/charge/modifiers/FixedDiscountTest.php b/tests/unit/charge/modifiers/FixedDiscountTest.php index f18bf542..8e6c1063 100644 --- a/tests/unit/charge/modifiers/FixedDiscountTest.php +++ b/tests/unit/charge/modifiers/FixedDiscountTest.php @@ -21,9 +21,14 @@ */ class FixedDiscountTest extends ActionTest { + private Money $value; + + private string $rate; + protected function setUp(): void { parent::setUp(); + $this->value = Money::USD(1000); $this->rate = '10'; } diff --git a/tests/unit/charge/modifiers/InstallmentTest.php b/tests/unit/charge/modifiers/InstallmentTest.php index dc8c5350..51d19f22 100644 --- a/tests/unit/charge/modifiers/InstallmentTest.php +++ b/tests/unit/charge/modifiers/InstallmentTest.php @@ -14,7 +14,7 @@ use hiqdev\php\billing\charge\modifiers\addons\MonthPeriod; use hiqdev\php\billing\charge\modifiers\addons\YearPeriod; use hiqdev\php\billing\charge\modifiers\event\InstallmentWasStarted; -use hiqdev\php\billing\charge\modifiers\Leasing; +use hiqdev\php\billing\charge\modifiers\Installment; use hiqdev\php\billing\price\SinglePrice; use hiqdev\php\billing\tests\unit\action\ActionTest; use hiqdev\php\billing\type\Type; diff --git a/tests/unit/charge/modifiers/ModifierTest.php b/tests/unit/charge/modifiers/ModifierTest.php index f6d6491c..46f0ffaa 100644 --- a/tests/unit/charge/modifiers/ModifierTest.php +++ b/tests/unit/charge/modifiers/ModifierTest.php @@ -22,7 +22,9 @@ */ class ModifierTest extends \PHPUnit\Framework\TestCase { - protected $modifier; + private DateTimeImmutable $now; + + protected Modifier $modifier; const SOME_TEXT = 'some text'; diff --git a/tests/unit/order/CalculatorTest.php b/tests/unit/order/CalculatorTest.php index a28b3a6c..a9433a1e 100644 --- a/tests/unit/order/CalculatorTest.php +++ b/tests/unit/order/CalculatorTest.php @@ -54,7 +54,7 @@ protected function setUp(): void $this->order = new Order(null, $this->plan->customer, $actions); } - public function testCalculateCharges() + public function testCalculateCharges(): void { $charges = $this->calculator->calculateOrder($this->order); foreach ($this->order->getActions() as $actionKey => $action) { diff --git a/tests/unit/plan/PlanTest.php b/tests/unit/plan/PlanTest.php index 3c5da891..3e7bff4b 100644 --- a/tests/unit/plan/PlanTest.php +++ b/tests/unit/plan/PlanTest.php @@ -31,6 +31,8 @@ class PlanTest extends \PHPUnit\Framework\TestCase protected DateTimeImmutable $time; + private Calculator $calculator; + protected function setUp(): void { $this->plan = CertificatePlan::get(); diff --git a/tests/unit/price/PriceFactoryTest.php b/tests/unit/price/PriceFactoryTest.php index b89a6bc0..6439cebd 100644 --- a/tests/unit/price/PriceFactoryTest.php +++ b/tests/unit/price/PriceFactoryTest.php @@ -25,6 +25,24 @@ */ class PriceFactoryTest extends \PHPUnit\Framework\TestCase { + private string $id; + + private Type $single; + + private Type $enum; + + private Target $target; + + private $prepaid; + + private Money $price; + + private $unit; + + private array $sums; + + private PriceFactory $factory; + protected function setUp(): void { $this->id = 'foo:bar'; diff --git a/tests/unit/price/SinglePriceTest.php b/tests/unit/price/SinglePriceTest.php index 83670713..92829f97 100644 --- a/tests/unit/price/SinglePriceTest.php +++ b/tests/unit/price/SinglePriceTest.php @@ -22,20 +22,17 @@ */ class SinglePriceTest extends \PHPUnit\Framework\TestCase { - /** - * @var SinglePrice - */ - protected $price; + protected SinglePrice $price; - /** - * @var Action - */ - protected $action; + protected Action $action; - /** - * @var Money - */ - protected $money; + protected Money $money; + + private Target $target; + + private Type $type; + + private $quantity; protected function setUp(): void { diff --git a/tests/unit/sale/SaleTest.php b/tests/unit/sale/SaleTest.php index 10bc5724..f60ed6ad 100644 --- a/tests/unit/sale/SaleTest.php +++ b/tests/unit/sale/SaleTest.php @@ -20,14 +20,11 @@ class SaleTest extends PlanTest { - /** - * @var Sale|SaleInterface - */ - protected $sale; - /** - * @var SaleRepositoryInterface|SimpleSaleRepository - */ - protected $repository; + protected DateTimeImmutable $time; + + protected SaleInterface $sale; + + protected SaleRepositoryInterface $repository; protected function setUp(): void { diff --git a/tests/unit/target/TargetTest.php b/tests/unit/target/TargetTest.php index 63a53249..183b78f9 100644 --- a/tests/unit/target/TargetTest.php +++ b/tests/unit/target/TargetTest.php @@ -20,10 +20,49 @@ class TargetTest extends \PHPUnit\Framework\TestCase { protected $id1 = 1; + protected $id2 = 2; + protected $idA = 8; + protected $idB = 9; + private \hiqdev\php\billing\target\AbstractTarget $target_; + + private Target $target1; + + private Target $target2; + + private Target $targetA; + + private Target $targetB; + + private TargetCollection $targets; + + private Target $server_; + + private Target $server1; + + private Target $server2; + + private Target $serverA; + + private Target $serverB; + + private Target $serverN; + + private TargetCollection $servers; + + private Target $domain_; + + private Target $domain1; + + private Target $domain2; + + private Target $domainN; + + private TargetCollection $domains; + protected function setUp(): void { $this->target_ = Target::any(); diff --git a/tests/unit/tools/AggregatorTest.php b/tests/unit/tools/AggregatorTest.php index b192082c..ae7bd4dc 100644 --- a/tests/unit/tools/AggregatorTest.php +++ b/tests/unit/tools/AggregatorTest.php @@ -70,7 +70,7 @@ public function testCalculateCharges(): void $this->assertCount(4, $bills); foreach ($bills as $bill) { - $prices = $this->plan->getRawPrices($bill->getType(), $bill->getTarget()); + $prices = $this->plan->getRawPrices($bill->getType(), $bill->getTarget())->values(); $sum = Money::USD(array_sum($prices)); $this->assertTrue($sum->negative()->equals($bill->getSum())); $this->assertEquals(6, $bill->getQuantity()->getQuantity()); diff --git a/tests/unit/tools/FactoryTest.php b/tests/unit/tools/FactoryTest.php index 197d1012..286e4571 100644 --- a/tests/unit/tools/FactoryTest.php +++ b/tests/unit/tools/FactoryTest.php @@ -55,8 +55,11 @@ class FactoryTest extends \PHPUnit\Framework\TestCase private $priceId = 'price-id'; private $targetId = 'target-id'; + private $target = 'type:name'; + private SimpleFactory $factory; + protected function setUp(): void { $this->factory = new SimpleFactory(); diff --git a/tests/unit/type/TypeTest.php b/tests/unit/type/TypeTest.php index 98c98cfe..731c0a68 100644 --- a/tests/unit/type/TypeTest.php +++ b/tests/unit/type/TypeTest.php @@ -30,6 +30,32 @@ class TypeTest extends \PHPUnit\Framework\TestCase protected $dop1 = 'domain1'; protected $dop2 = 'domain2'; + private Type $nonenone; + + private Type $server11; + private Type $server12; + private Type $server_1; + private Type $server1_; + private Type $serverN1; + private Type $server1N; + private Type $serverN_; + private Type $server_N; + private Type $server22; + private Type $server21; + private Type $server_2; + private Type $server2_; + private Type $serverN2; + private Type $server2N; + + private Type $domain11; + private Type $domain_1; + private Type $domain1_; + private Type $domainN1; + private Type $domain1N; + private Type $domain22; + private Type $domain_2; + private Type $domain2_; + protected function setUp(): void { $this->nonenone = new Type(Type::NONE, Type::NONE);