-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed DisposalBuilder and ReversionFinder
- Loading branch information
Showing
8 changed files
with
265 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 92 additions & 6 deletions
98
domain/tests/Aggregates/SharePoolingAsset/Services/QuantityAdjuster/QuantityAdjusterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,114 @@ | ||
<?php | ||
|
||
use Domain\Aggregates\SharePoolingAsset\Entities\Exceptions\SharePoolingAssetAcquisitionException; | ||
use Domain\Aggregates\SharePoolingAsset\Entities\SharePoolingAssetAcquisition; | ||
use Domain\Aggregates\SharePoolingAsset\Entities\SharePoolingAssetDisposal; | ||
use Domain\Aggregates\SharePoolingAsset\Entities\SharePoolingAssetTransactions; | ||
use Domain\Aggregates\SharePoolingAsset\Services\QuantityAdjuster\Exceptions\QuantityAdjusterException; | ||
use Domain\Aggregates\SharePoolingAsset\Services\QuantityAdjuster\QuantityAdjuster; | ||
use Domain\Aggregates\SharePoolingAsset\ValueObjects\SharePoolingAssetTransactionId; | ||
use Domain\ValueObjects\Quantity; | ||
|
||
it('cannot revert a disposal because an acquisition cannot be found', function () { | ||
it('cannot process a disposal because an acquisition cannot be found', function (string $method) { | ||
$disposal = SharePoolingAssetDisposal::factory() | ||
->withSameDayQuantity(Quantity::zero(), $id = SharePoolingAssetTransactionId::fromString('foo')) | ||
->make(); | ||
|
||
expect(fn () => QuantityAdjuster::revertDisposal($disposal, SharePoolingAssetTransactions::make())) | ||
expect(fn () => QuantityAdjuster::$method($disposal, SharePoolingAssetTransactions::make())) | ||
->toThrow(QuantityAdjusterException::class, QuantityAdjusterException::transactionNotFound($id)->getMessage()); | ||
}); | ||
})->with(['applyDisposal', 'revertDisposal']); | ||
|
||
it('cannot revert a disposal because a transaction is not an acquisition', function () { | ||
it('cannot process a disposal because a transaction is not an acquisition', function (string $method) { | ||
$disposal = SharePoolingAssetDisposal::factory() | ||
->withSameDayQuantity(Quantity::zero(), $id = SharePoolingAssetTransactionId::fromString('foo')) | ||
->make(); | ||
|
||
$transactions = SharePoolingAssetTransactions::make(SharePoolingAssetDisposal::factory()->make(['id' => $id])); | ||
|
||
expect(fn () => QuantityAdjuster::revertDisposal($disposal, $transactions)) | ||
expect(fn () => QuantityAdjuster::$method($disposal, $transactions)) | ||
->toThrow(QuantityAdjusterException::class, QuantityAdjusterException::notAnAcquisition($id)->getMessage()); | ||
}); | ||
})->with(['applyDisposal', 'revertDisposal']); | ||
|
||
it('cannot apply a disposal because of insufficient available quantity to increase', function ( | ||
string $method, | ||
string $quantity, | ||
string $exception | ||
) { | ||
$disposal = SharePoolingAssetDisposal::factory() | ||
->{$method}(new Quantity($quantity), $id = SharePoolingAssetTransactionId::fromString('foo')) | ||
->make(); | ||
|
||
$transactions = SharePoolingAssetTransactions::make(SharePoolingAssetAcquisition::factory()->make([ | ||
'id' => $id, | ||
'quantity' => $available = new Quantity('10'), | ||
])); | ||
|
||
expect(fn () => QuantityAdjuster::applyDisposal($disposal, $transactions))->toThrow( | ||
SharePoolingAssetAcquisitionException::class, | ||
SharePoolingAssetAcquisitionException::$exception(new Quantity($quantity), $available)->getMessage(), | ||
); | ||
})->with([ | ||
'same-day' => ['withSameDayQuantity', '11', 'insufficientSameDayQuantityToIncrease'], | ||
'30-day' => ['withThirtyDayQuantity', '11', 'insufficientThirtyDayQuantityToIncrease'], | ||
]); | ||
|
||
it('can apply a disposal', function (string $factoryMethod, string $method) { | ||
$disposal = SharePoolingAssetDisposal::factory() | ||
->{$factoryMethod}(new Quantity('10'), $id = SharePoolingAssetTransactionId::fromString('foo')) | ||
->make(); | ||
|
||
$transactions = SharePoolingAssetTransactions::make(SharePoolingAssetAcquisition::factory()->make([ | ||
'id' => $id, | ||
'quantity' => new Quantity('10'), | ||
])); | ||
|
||
expect((string) $transactions->first()->{$method}())->toBe('0'); | ||
|
||
QuantityAdjuster::applyDisposal($disposal, $transactions); | ||
|
||
expect((string) $transactions->first()->{$method}())->toBe('10'); | ||
})->with([ | ||
'same-day' => ['withSameDayQuantity', 'sameDayQuantity'], | ||
'30-day' => ['withThirtyDayQuantity', 'thirtyDayQuantity'], | ||
]); | ||
|
||
it('cannot revert a disposal because of insufficient available quantity to decrease', function ( | ||
string $method, | ||
string $quantity, | ||
string $exception | ||
) { | ||
$disposal = SharePoolingAssetDisposal::factory() | ||
->{$method}(new Quantity($quantity), $id = SharePoolingAssetTransactionId::fromString('foo')) | ||
->make(); | ||
|
||
$transactions = SharePoolingAssetTransactions::make(SharePoolingAssetAcquisition::factory()->make(['id' => $id])); | ||
|
||
expect(fn () => QuantityAdjuster::revertDisposal($disposal, $transactions))->toThrow( | ||
SharePoolingAssetAcquisitionException::class, | ||
SharePoolingAssetAcquisitionException::$exception(new Quantity($quantity), Quantity::zero())->getMessage(), | ||
); | ||
})->with([ | ||
'same-day' => ['withSameDayQuantity', '1', 'insufficientSameDayQuantityToDecrease'], | ||
'30-day' => ['withThirtyDayQuantity', '1', 'insufficientThirtyDayQuantityToDecrease'], | ||
]); | ||
|
||
it('can revert a disposal', function (string $factoryMethod, string $method) { | ||
$disposal = SharePoolingAssetDisposal::factory() | ||
->{$factoryMethod}(new Quantity('10'), $id = SharePoolingAssetTransactionId::fromString('foo')) | ||
->make(); | ||
|
||
$transactions = SharePoolingAssetTransactions::make(SharePoolingAssetAcquisition::factory()->make([ | ||
'id' => $id, | ||
'sameDayQuantity' => new Quantity('10'), | ||
'thirtyDayQuantity' => new Quantity('10'), | ||
])); | ||
|
||
expect((string) $transactions->first()->{$method}())->toBe('10'); | ||
|
||
QuantityAdjuster::revertDisposal($disposal, $transactions); | ||
|
||
expect((string) $transactions->first()->{$method}())->toBe('0'); | ||
})->with([ | ||
'same-day' => ['withSameDayQuantity', 'sameDayQuantity'], | ||
'30-day' => ['withThirtyDayQuantity', 'thirtyDayQuantity'], | ||
]); |
Oops, something went wrong.