Skip to content
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

Update test workflow #1936

Closed
wants to merge 12 commits into from
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
laravel: [11.*, 10.*]
dependency-version: [prefer-stable]
testsuite: [core, admin, shipping, stripe]
phpunit-config: [phpunit.xml, phpunit.extending.xml]
include:
- laravel: 11.*
testbench: 9.*
Expand Down Expand Up @@ -47,4 +48,4 @@ jobs:
APP_ENV: testing
DB_CONNECTION: testing
DB_DATABASE: ":memory:"
run: ./vendor/bin/pest --testsuite ${{ matrix.testsuite }}
run: ./vendor/bin/pest --testsuite ${{ matrix.testsuite }} -c ${{ matrix.phpunit-config }}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
},
"autoload-dev": {
"psr-4": {
"Lunar\\Tests\\": "tests",
"Lunar\\Tests\\Stubs\\": "tests/stubs",
"Lunar\\Tests\\Admin\\": "tests/admin",
"Lunar\\Tests\\Core\\": "tests/core",
"Lunar\\Tests\\Opayo\\": "tests/opayo",
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/Base/Traits/HasModelExtending.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lunar\Base\Traits;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Arr;
use Lunar\Facades\ModelManifest;

Expand Down Expand Up @@ -46,6 +47,20 @@ public static function modelClass(): string
return ModelManifest::get($contractClass) ?? static::class;
}

/**
* Returns the morph class for a model class registered in the model manifest.
*/
public function getMorphClass(): string
{
$morphMap = Relation::morphMap();

if (! empty($morphMap) && in_array(static::modelClass(), $morphMap)) {
return array_search(static::modelClass(), $morphMap, true);
}

return parent::getMorphClass();
}

public static function isLunarInstance(): bool
{
return static::class == static::modelClass();
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/Pipelines/Cart/ApplyDiscounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
use Closure;
use Lunar\Facades\Discounts;
use Lunar\Models\Cart;
use Lunar\Models\Contracts\Cart as CartContract;

final class ApplyDiscounts
{
/**
* Called just before cart totals are calculated.
*
* @return void
* @param Closure(CartContract): mixed $next
* @return Closure
*/
public function handle(Cart $cart, Closure $next)
public function handle(CartContract $cart, Closure $next): mixed
{
/** @var Cart $cart */
$cart->discounts = collect([]);
$cart->discountBreakdown = collect([]);

Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/Pipelines/Cart/ApplyShipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
use Lunar\DataTypes\Price;
use Lunar\Facades\ShippingManifest;
use Lunar\Models\Cart;
use Lunar\Models\Contracts\Cart as CartContract;

final class ApplyShipping
{
/**
* Called just before cart totals are calculated.
*
* @return void
* @param Closure(CartContract): mixed $next
* @return Closure
*/
public function handle(Cart $cart, Closure $next)
public function handle(CartContract $cart, Closure $next): mixed
{
/** @var Cart $cart */
$shippingSubTotal = 0;
$shippingBreakdown = $cart->shippingBreakdown ?: new ShippingBreakdown;

Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/Pipelines/Cart/Calculate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
use Closure;
use Lunar\DataTypes\Price;
use Lunar\Models\Cart;
use Lunar\Models\Contracts\Cart as CartContract;

class Calculate
{
/**
* Called just before cart totals are calculated.
*
* @return void
* @param Closure(CartContract): mixed $next
* @return Closure
*/
public function handle(Cart $cart, Closure $next)
public function handle(CartContract $cart, Closure $next): mixed
{
/** @var Cart $cart */
$discountTotal = $cart->lines->sum('discountTotal.value');

$subTotal = $cart->lines->sum('subTotal.value');
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/Pipelines/Cart/CalculateLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
use Illuminate\Pipeline\Pipeline;
use Lunar\DataTypes\Price;
use Lunar\Models\Cart;
use Lunar\Models\Contracts\Cart as CartContract;

class CalculateLines
{
/**
* Called just before cart totals are calculated.
*
* @return void
* @param Closure(CartContract): mixed $next
* @return Closure
*/
public function handle(Cart $cart, Closure $next)
public function handle(CartContract $cart, Closure $next): mixed
{
/** @var Cart $cart */
foreach ($cart->lines as $line) {
$cartLine = app(Pipeline::class)
->send($line)
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/Pipelines/Cart/CalculateTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
use Lunar\Facades\ShippingManifest;
use Lunar\Facades\Taxes;
use Lunar\Models\Cart;
use Lunar\Models\Contracts\Cart as CartContract;

class CalculateTax
{
/**
* Called just before cart totals are calculated.
*
* @return void
* @param Closure(CartContract): mixed $next
* @return Closure
*/
public function handle(Cart $cart, Closure $next)
public function handle(CartContract $cart, Closure $next): mixed
{
/** @var Cart $cart */
$taxBreakDownAmounts = collect();

foreach ($cart->lines as $cartLine) {
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/Pipelines/CartLine/GetUnitPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
use Lunar\DataTypes\Price;
use Lunar\Facades\Pricing;
use Lunar\Models\CartLine;
use Lunar\Models\Contracts\CartLine as CartLineContract;
use Spatie\LaravelBlink\BlinkFacade as Blink;

class GetUnitPrice
{
/**
* Called just before cart totals are calculated.
*
* @return mixed
* @param Closure(CartLineContract): mixed $next
* @return Closure
*/
public function handle(CartLine $cartLine, Closure $next)
public function handle(CartLineContract $cartLine, Closure $next)
{
/** @var CartLine $cart */
$purchasable = $cartLine->purchasable;
$cart = $cartLine->cart;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
namespace Lunar\Pipelines\Order\Creation;

use Closure;
use Lunar\Models\Contracts\Order as OrderContract;
use Lunar\Models\Order;

class CleanUpOrderLines
{
/**
* @param Closure(OrderContract): mixed $next
* @return Closure
*/
public function handle(Order $order, Closure $next)
public function handle(OrderContract $order, Closure $next): mixed
{
/** @var Order $order */
$cart = $order->cart;

$purchasableIds = $cart->lines->pluck('purchasable_id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
namespace Lunar\Pipelines\Order\Creation;

use Closure;
use Illuminate\Support\Facades\App;
use Lunar\Models\Contracts\Order as OrderContract;
use Lunar\Models\Contracts\OrderAddress as OrderAddressContract;
use Lunar\Models\Order;
use Lunar\Models\OrderAddress;

class CreateOrderAddresses
{
/**
* @param Closure(OrderContract): mixed $next
* @return Closure
*/
public function handle(Order $order, Closure $next)
public function handle(OrderContract $order, Closure $next): mixed
{
/** @var Order $order */
$orderAddresses = $order->addresses;

foreach ($order->cart->addresses as $address) {
/** @var OrderAddress $addressModel */
$addressModel = $orderAddresses->first(function ($orderAddress) use ($address) {
return $orderAddress->type == $address->type &&
$orderAddress->postcode == $address->postcode;
}) ?: new OrderAddress;
}) ?: App::make(OrderAddressContract::class);

$addressModel->fill(
collect(
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/Pipelines/Order/Creation/CreateOrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
namespace Lunar\Pipelines\Order\Creation;

use Closure;
use Illuminate\Support\Facades\App;
use Lunar\Models\Contracts\Order as OrderContract;
use Lunar\Models\Contracts\OrderLine as OrderLineContract;
use Lunar\Models\Order;
use Lunar\Models\OrderLine;

class CreateOrderLines
{
/**
* @param Closure(OrderContract): mixed $next
* @return Closure
*/
public function handle(Order $order, Closure $next)
public function handle(OrderContract $order, Closure $next): mixed
{
/** @var Order $order */
if (! $order->id) {
$order->save();
}
Expand All @@ -22,10 +27,11 @@ public function handle(Order $order, Closure $next)
$cart->recalculate();

foreach ($cart->lines as $cartLine) {
/** @var OrderLine $orderLine */
$orderLine = $order->lines->first(function ($line) use ($cartLine) {
return $line->purchasable_id == $cartLine->purchasable_id &&
$line->purchasable_type == $cartLine->purchasable_type;
}) ?: new OrderLine;
}) ?: App::make(OrderLineContract::class);

$orderLine->fill([
'order_id' => $order->id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@
namespace Lunar\Pipelines\Order\Creation;

use Closure;
use Illuminate\Support\Facades\App;
use Lunar\DataTypes\ShippingOption;
use Lunar\Models\Contracts\Order as OrderContract;
use Lunar\Models\Contracts\OrderLine as OrderLineContract;
use Lunar\Models\Order;
use Lunar\Models\OrderLine;

class CreateShippingLine
{
/**
* @param Closure(OrderContract): mixed $next
* @return Closure
*/
public function handle(Order $order, Closure $next)
public function handle(OrderContract $order, Closure $next): mixed
{
/** @var Order $order */
$cart = $order->cart->recalculate();

// If we have a shipping address with a shipping option.
if (($shippingAddress = $cart->shippingAddress) &&
($shippingOption = $cart->getShippingOption())
) {
/** @var OrderLine $shippingLine */
$shippingLine = $order->lines->first(function ($orderLine) use ($shippingOption) {
return $orderLine->type == 'shipping' &&
$orderLine->purchasable_type == ShippingOption::class &&
$orderLine->identifier == $shippingOption->getIdentifier();
}) ?: new OrderLine;
}) ?: App::make(OrderLineContract::class);

$shippingLine->fill([
'order_id' => $order->id,
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/Pipelines/Order/Creation/FillOrderFromCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
namespace Lunar\Pipelines\Order\Creation;

use Closure;
use Illuminate\Support\Facades\App;
use Lunar\Actions\Orders\GenerateOrderReference;
use Lunar\Models\Currency;
use Lunar\Models\Contracts\Currency as CurrencyContract;
use Lunar\Models\Contracts\Order as OrderContract;
use Lunar\Models\Order;

class FillOrderFromCart
{
/**
* @param Closure(OrderContract): mixed $next
* @return Closure
*/
public function handle(Order $order, Closure $next)
public function handle(OrderContract $order, Closure $next): mixed
{
/** @var Order $order */
$cart = $order->cart->calculate();

$order->fill([
Expand All @@ -33,7 +37,7 @@ public function handle(Order $order, Closure $next)
'tax_total' => $cart->taxTotal->value,
'currency_code' => $cart->currency->code,
'exchange_rate' => $cart->currency->exchange_rate,
'compare_currency_code' => Currency::getDefault()?->code,
'compare_currency_code' => App::make(CurrencyContract::class)::getDefault()?->code,
'meta' => $cart->meta,
])->save();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
namespace Lunar\Pipelines\Order\Creation;

use Closure;
use Lunar\Models\Contracts\Order as OrderContract;
use Lunar\Models\Order;

class MapDiscountBreakdown
{
/**
* @param Closure(OrderContract): mixed $next
* @return Closure
*/
public function handle(Order $order, Closure $next)
public function handle(OrderContract $order, Closure $next): mixed
{
/** @var Order $order */
$cart = $order->cart;

$cartLinesMappedToOrderLines = [];
Expand Down
Loading
Loading