. */ namespace SP\Tests\Domain\Plugin\Services; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\MockObject\Exception; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Plugin\Models\Plugin as PluginModel; use SP\Domain\Plugin\Ports\Plugin; use SP\Domain\Plugin\Ports\PluginManagerService; use SP\Domain\Plugin\Services\PluginLoader; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Tests\UnitaryTestCase; /** * Class PluginLoaderTest */ #[Group('unitary')] class PluginLoaderTest extends UnitaryTestCase { /** * @throws Exception * @throws ConstraintException * @throws QueryException */ public function testLoadForWithEnabled() { $pluginManagerService = $this->createMock(PluginManagerService::class); $plugin = $this->createStub(Plugin::class); $plugin->method('getName')->willReturn('test_plugin'); $pluginModel = new PluginModel(['enabled' => true]); $pluginManagerService ->expects($this->once()) ->method('getByName') ->with('test_plugin') ->willReturn($pluginModel); $pluginLoader = new PluginLoader($this->application, $pluginManagerService); $pluginLoader->loadFor($plugin); } /** * @throws Exception * @throws ConstraintException * @throws QueryException */ public function testLoadForWithDisabled() { $pluginManagerService = $this->createMock(PluginManagerService::class); $plugin = $this->createStub(Plugin::class); $plugin->method('getName')->willReturn('test_plugin'); $pluginModel = new PluginModel(['enabled' => false]); $pluginManagerService ->expects($this->once()) ->method('getByName') ->with('test_plugin') ->willReturn($pluginModel); $pluginLoader = new PluginLoader($this->application, $pluginManagerService); $pluginLoader->loadFor($plugin); } /** * @throws Exception * @throws ConstraintException * @throws QueryException */ public function testLoadForWithException() { $pluginManagerService = $this->createMock(PluginManagerService::class); $plugin = $this->createStub(Plugin::class); $plugin->method('getName')->willReturn('test_plugin'); $pluginManagerService ->expects($this->once()) ->method('getByName') ->willThrowException(NoSuchItemException::error('test')); $pluginLoader = new PluginLoader($this->application, $pluginManagerService); $pluginLoader->loadFor($plugin); } }