BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Blax\Shop\Tests\Feature\Loan;
|
|
|
|
|
|
|
|
|
|
use Blax\Shop\Enums\ProductType;
|
|
|
|
|
use Blax\Shop\Enums\StockStatus;
|
|
|
|
|
use Blax\Shop\Enums\StockType;
|
2026-05-17 13:20:58 +00:00
|
|
|
use Blax\Shop\Events\StockClaimed;
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
use Blax\Shop\Events\StockDepleted;
|
|
|
|
|
use Blax\Shop\Events\StockIncreased;
|
2026-05-17 13:20:58 +00:00
|
|
|
use Blax\Shop\Events\StockReleased;
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
use Blax\Shop\Events\StockReplenished;
|
|
|
|
|
use Blax\Shop\Models\Product;
|
|
|
|
|
use Blax\Shop\Models\ProductStock;
|
|
|
|
|
use Blax\Shop\Tests\TestCase;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
|
|
|
use Workbench\App\Models\User;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loans go through HasStocks::decreaseStock() and (host-driven) increaseStock()
|
|
|
|
|
* for return, so they automatically participate in the StockDecreased /
|
|
|
|
|
* StockIncreased / StockDepleted / StockReplenished event chain. EventsWiredUpTest
|
|
|
|
|
* proves those events fire for direct decrease/increase calls; this file
|
|
|
|
|
* pins down that the LOAN-driven paths (checkOutTo, markReturned-then-restock)
|
|
|
|
|
* benefit from the same wiring, so external listeners (low-stock alerts,
|
|
|
|
|
* search reindex, librarian notifications) react identically regardless of
|
|
|
|
|
* whether stock moved via a checkout or a loan.
|
|
|
|
|
*/
|
|
|
|
|
class LoanStockEventsTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
use RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
private User $borrower;
|
|
|
|
|
private EventLoanBook $book;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->borrower = User::factory()->create();
|
|
|
|
|
$this->book = EventLoanBook::create(['name' => 'Hyperion', 'sku' => 'HYP-EV-1']);
|
|
|
|
|
$this->book->increaseStock(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Test]
|
2026-05-17 13:20:58 +00:00
|
|
|
public function checkOutTo_dispatches_stock_claimed_with_a_physically_claimed_row(): void
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
{
|
2026-05-17 13:20:58 +00:00
|
|
|
// Loans go through the claim machinery (PHYSICALLY_CLAIMED type), so
|
|
|
|
|
// the canonical "stock has moved" event is StockClaimed — not
|
|
|
|
|
// StockDecreased. The bookkeeping DECREASE row that claimStock writes
|
|
|
|
|
// internally bypasses the public decreaseStock() path (and so does
|
|
|
|
|
// not fire StockDecreased), matching how bookings have always worked.
|
|
|
|
|
Event::fake([StockClaimed::class]);
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
|
2026-05-17 13:20:58 +00:00
|
|
|
$loan = $this->book->checkOutTo($this->borrower);
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
|
|
|
|
|
Event::assertDispatched(
|
2026-05-17 13:20:58 +00:00
|
|
|
StockClaimed::class,
|
|
|
|
|
fn (StockClaimed $e) => $e->product->is($this->book)
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
&& $e->entry instanceof ProductStock
|
2026-05-17 13:20:58 +00:00
|
|
|
&& (int) $e->entry->quantity === 1
|
|
|
|
|
&& $e->entry->type === StockType::PHYSICALLY_CLAIMED
|
|
|
|
|
&& $e->entry->status === StockStatus::PENDING
|
|
|
|
|
&& (string) $e->entry->reference_id === (string) $loan->id,
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
public function checking_out_the_last_copy_dispatches_stock_depleted(): void
|
|
|
|
|
{
|
2026-05-17 13:20:58 +00:00
|
|
|
// 3 copies on the shelf — borrow all three. The third call crosses
|
|
|
|
|
// the last-copy boundary; claimStock's dispatchStockTransitions fires
|
|
|
|
|
// StockDepleted regardless of whether the decrement came from a
|
|
|
|
|
// direct decreaseStock or a claim.
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
$this->book->checkOutTo(User::factory()->create());
|
|
|
|
|
$this->book->checkOutTo(User::factory()->create());
|
|
|
|
|
|
2026-05-17 13:20:58 +00:00
|
|
|
Event::fake([StockDepleted::class, StockClaimed::class]);
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
|
|
|
|
|
$this->book->checkOutTo($this->borrower);
|
|
|
|
|
|
2026-05-17 13:20:58 +00:00
|
|
|
Event::assertDispatched(StockClaimed::class);
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
Event::assertDispatched(
|
|
|
|
|
StockDepleted::class,
|
|
|
|
|
fn (StockDepleted $e) => $e->product->is($this->book),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
public function partial_checkout_does_not_dispatch_stock_depleted(): void
|
|
|
|
|
{
|
|
|
|
|
Event::fake([StockDepleted::class]);
|
|
|
|
|
|
|
|
|
|
$this->book->checkOutTo($this->borrower);
|
|
|
|
|
|
|
|
|
|
Event::assertNotDispatched(StockDepleted::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Test]
|
2026-05-17 13:20:58 +00:00
|
|
|
public function returning_a_fully_loaned_book_dispatches_replenished_and_released(): void
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
{
|
2026-05-17 13:20:58 +00:00
|
|
|
// Single-copy book, borrow it (depletes to 0), then return it.
|
|
|
|
|
// markReturned() releases the paired claim, which creates the
|
|
|
|
|
// offsetting RETURN entry via the package's release() helper — so
|
|
|
|
|
// StockIncreased + StockReleased both fire, and the 0→1 boundary
|
|
|
|
|
// crossing additionally triggers StockReplenished. No host call
|
|
|
|
|
// to increaseStock() needed.
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
$single = EventLoanBook::create(['name' => 'Solitaire', 'sku' => 'SOL-EV-1']);
|
|
|
|
|
$single->increaseStock(1);
|
|
|
|
|
$loan = $single->checkOutTo($this->borrower);
|
|
|
|
|
|
|
|
|
|
$this->assertSame(0, $single->fresh()->getAvailableStock());
|
|
|
|
|
|
2026-05-17 13:20:58 +00:00
|
|
|
Event::fake([StockReplenished::class, StockIncreased::class, StockReleased::class]);
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
|
2026-05-17 13:20:58 +00:00
|
|
|
$loan->markReturned();
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
|
|
|
|
|
Event::assertDispatched(StockIncreased::class);
|
2026-05-17 13:20:58 +00:00
|
|
|
Event::assertDispatched(StockReleased::class);
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
Event::assertDispatched(
|
|
|
|
|
StockReplenished::class,
|
|
|
|
|
fn (StockReplenished $e) => $e->product->is($single) && $e->availableAfter === 1,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Test]
|
2026-05-17 13:20:58 +00:00
|
|
|
public function returning_when_other_copies_are_free_does_not_dispatch_replenished(): void
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
{
|
2026-05-17 13:20:58 +00:00
|
|
|
// 3-copy book, borrow 1 → 2 available. Returning goes 2→3, NOT a
|
|
|
|
|
// 0→>0 transition, so StockReplenished must stay silent.
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
$loan = $this->book->checkOutTo($this->borrower);
|
|
|
|
|
|
|
|
|
|
Event::fake([StockReplenished::class]);
|
|
|
|
|
|
2026-05-17 13:20:58 +00:00
|
|
|
$loan->markReturned();
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
|
|
|
|
|
Event::assertNotDispatched(StockReplenished::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
public function event_wiring_holds_across_a_full_borrow_return_cycle(): void
|
|
|
|
|
{
|
2026-05-17 13:20:58 +00:00
|
|
|
// Full sequence: borrow → return. checkOutTo fires StockClaimed (no
|
|
|
|
|
// StockDecreased — claim machinery bypasses it). markReturned fires
|
|
|
|
|
// StockReleased + StockIncreased (the release writes a RETURN entry
|
|
|
|
|
// through increaseStock). The 3→2 and 2→3 transitions are boundary-
|
|
|
|
|
// free so StockDepleted/StockReplenished stay quiet.
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
Event::fake([
|
2026-05-17 13:20:58 +00:00
|
|
|
StockClaimed::class,
|
|
|
|
|
StockReleased::class,
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
StockIncreased::class,
|
|
|
|
|
StockDepleted::class,
|
|
|
|
|
StockReplenished::class,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$loan = $this->book->checkOutTo($this->borrower);
|
|
|
|
|
$loan->markReturned();
|
|
|
|
|
|
2026-05-17 13:20:58 +00:00
|
|
|
Event::assertDispatchedTimes(StockClaimed::class, 1);
|
|
|
|
|
Event::assertDispatchedTimes(StockReleased::class, 1);
|
BF commands, A command tests, I traits
- Implement CommandReinstallTest to verify the behavior of the shop:reinstall command, including force and fresh flags, and confirmation prompts.
- Create CommandReleaseExpiredStocksTest to test the shop:release-expired-stocks command, ensuring it correctly releases expired stock claims based on configuration.
- Add CommandStatsTest to validate the shop:stats command, checking counts and revenue calculations for products, purchases, carts, and orders.
- Introduce LoanShopCommandsTest to cover loanable products in stock management, ensuring accurate reporting of assigned, used, and available stock.
- Implement LoanStockEventsTest to verify that stock events are dispatched correctly during loan operations, including checkouts and returns.
- Add NextAvailableAtTest to ensure the nextAvailableAt method behaves correctly for loanable products, considering loans and claims.
2026-05-17 11:25:34 +00:00
|
|
|
Event::assertDispatchedTimes(StockIncreased::class, 1);
|
|
|
|
|
Event::assertNotDispatched(StockDepleted::class, '3→2 is not a depletion');
|
|
|
|
|
Event::assertNotDispatched(StockReplenished::class, '2→3 is not a replenishment');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Same plug-n-pray fixture as CheckOutToTest's: declare DEFAULT_TYPE so the
|
|
|
|
|
* MayBeLoanableProduct creating-hook flips the row into loan mode.
|
|
|
|
|
*/
|
|
|
|
|
class EventLoanBook extends Product
|
|
|
|
|
{
|
|
|
|
|
public const DEFAULT_TYPE = ProductType::LOANABLE;
|
|
|
|
|
|
|
|
|
|
protected $guarded = [];
|
|
|
|
|
}
|