Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Factories/AbstractWidgetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function instantiateWidget(array $params = [])
throw new InvalidWidgetClassException('Class "'.$widgetClass.'" must extend "Arrilot\Widgets\AbstractWidget" class');
}

$this->widget = new $widgetClass($this->widgetConfig);
$this->widget = $this->app->make($widgetClass, ['config' => $this->widgetConfig]);

if (static::$allowOnlyWidgetsWithDisabledEncryption && $this->widget->encryptParams) {
throw new EncryptException('Widget "'.$widgetClass.'" was not called properly');
Expand Down
7 changes: 7 additions & 0 deletions tests/Support/TestApplicationWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Arrilot\Widgets\Test\Support;

use Arrilot\Widgets\AbstractWidget;
use Arrilot\Widgets\Contracts\ApplicationWrapperContract;
use Arrilot\Widgets\Factories\AsyncWidgetFactory;
use Arrilot\Widgets\Factories\WidgetFactory;
Expand Down Expand Up @@ -97,6 +98,12 @@ public function make($abstract, array $parameters = [])
return new TestEncrypter();
}

if (is_subclass_of($abstract, AbstractWidget::class)) {
$app = \Illuminate\Container\Container::getInstance();

return $app->makeWith($abstract, $parameters);
}

throw new InvalidArgumentException("Binding {$abstract} cannot be resolved while testing");
}
}