Files
Php-Template/tests/ServiceProviders/AbstractServiceProvider.php
Ron Rise de0c95db2a
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m40s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m42s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m53s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m55s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m42s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m24s
feat: enhance service providers with provides method and integrate command bus in handlers
2025-12-22 13:18:13 -05:00

44 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Siteworxpro\Tests\ServiceProviders;
use Illuminate\Container\Container;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\ServiceProvider;
use Siteworxpro\Tests\Unit;
abstract class AbstractServiceProvider extends Unit
{
abstract protected function getProviderClass(): string;
/**
* @throws BindingResolutionException
*/
public function testProvider(): void
{
$container = new Container();
$providerClass = $this->getProviderClass();
/** @var ServiceProvider $providerClass */
$provider = new $providerClass($container);
$this->assertInstanceOf($providerClass, $provider);
$provider->register();
$abstract = $provider->provides()[0];
$concrete = get_class($container->make($abstract));
$this->assertTrue($container->bound($abstract), "The $abstract is not bound in the container.");
$this->assertNotNull($container->make($abstract), "The $abstract could not be resolved.");
$this->assertInstanceOf(
$concrete,
$container->make($abstract),
"The $abstract is not an instance of $concrete."
);
}
}