Skip to content

Commit

Permalink
The TaxCategoryType interface is bound to the container
Browse files Browse the repository at this point in the history
- Added the getType() method to the `TaxCategory` interface
  • Loading branch information
fulopattila122 committed Feb 26, 2024
1 parent 7b9e4f1 commit 7b8ffa9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Taxes/Contracts/TaxCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ interface TaxCategory
{
public function getName(): string;

public function getType(): TaxCategoryType;

public static function findByName(string $name): ?TaxCategory;
}
7 changes: 7 additions & 0 deletions src/Taxes/Models/TaxCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
use Illuminate\Database\Eloquent\Model;
use Konekt\Enum\Eloquent\CastsEnums;
use Vanilo\Taxes\Contracts\TaxCategory as TaxCategoryContract;
use Vanilo\Taxes\Contracts\TaxCategoryType;

/**
* @property-read int $id
* @property string $name
* @property TaxCategoryType $type
* @property bool $is_active
* @property Carbon $created_at
* @property Carbon $updated_at
Expand Down Expand Up @@ -53,6 +55,11 @@ public function getName(): string
return $this->name;
}

public function getType(): TaxCategoryType
{
return $this->type;
}

public function scopeActives(Builder $query): Builder
{
return $query->where('is_active', true);
Expand Down
2 changes: 2 additions & 0 deletions src/Taxes/Providers/ModuleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Vanilo\Taxes\Providers;

use Konekt\Concord\BaseModuleServiceProvider;
use Vanilo\Taxes\Contracts\TaxRateResolver;
use Vanilo\Taxes\Models\TaxCategory;
use Vanilo\Taxes\Models\TaxCategoryType;
use Vanilo\Taxes\Models\TaxRate;
Expand All @@ -36,5 +37,6 @@ public function register(): void
parent::register();

$this->app->singleton(TaxEngineManager::class, fn ($app) => new TaxEngineManager($app));
$this->app->bind(TaxRateResolver::class, fn ($app) => $app->make(TaxEngineManager::class)->driver());
}
}
15 changes: 15 additions & 0 deletions src/Taxes/Tests/TaxCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ public function it_can_be_created_with_minimal_data()
$this->assertEquals('Reduced Rate', $taxCategory->name);
}

/** @test */
public function it_complies_with_the_interface()
{
$taxCategory = TaxCategory::create(['name' => 'Events', 'type' => TaxCategoryType::EVENT_RELATED_SERVICES])->fresh();

$this->assertInstanceOf(\Vanilo\Taxes\Contracts\TaxCategory::class, $taxCategory);
$this->assertInstanceOf(\Vanilo\Taxes\Contracts\TaxCategoryType::class, $taxCategory->getType());
$this->assertEquals('Events', $taxCategory->getName());

$instanceViaLookup = TaxCategory::findByName('Events');
$this->assertInstanceOf(\Vanilo\Taxes\Contracts\TaxCategory::class, $instanceViaLookup);
$this->assertInstanceOf(\Vanilo\Taxes\Contracts\TaxCategoryType::class, $instanceViaLookup->getType());
$this->assertEquals('Events', $instanceViaLookup->getName());
}

/** @test */
public function it_is_active_by_default()
{
Expand Down

0 comments on commit 7b8ffa9

Please sign in to comment.