Skip to content

Commit ae0a86b

Browse files
committed
Make widget classes with the Illuminate Container
Also changed the TestApplicationWrapper to use the Illuminate Container when the abstract class is a subclass of AbstractWidget
1 parent 839f5c0 commit ae0a86b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Factories/AbstractWidgetFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function instantiateWidget(array $params = [])
133133
throw new InvalidWidgetClassException('Class "'.$widgetClass.'" must extend "Arrilot\Widgets\AbstractWidget" class');
134134
}
135135

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

138138
if (static::$allowOnlyWidgetsWithDisabledEncryption && $this->widget->encryptParams) {
139139
throw new EncryptException('Widget "'.$widgetClass.'" was not called properly');

tests/Support/TestApplicationWrapper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Arrilot\Widgets\Test\Support;
44

5+
use Arrilot\Widgets\AbstractWidget;
56
use Arrilot\Widgets\Contracts\ApplicationWrapperContract;
67
use Arrilot\Widgets\Factories\AsyncWidgetFactory;
78
use Arrilot\Widgets\Factories\WidgetFactory;
@@ -97,6 +98,11 @@ public function make($abstract, array $parameters = [])
9798
return new TestEncrypter();
9899
}
99100

101+
if (is_subclass_of($abstract, AbstractWidget::class)) {
102+
$app = \Illuminate\Container\Container::getInstance();
103+
return $app->make($abstract, $parameters);
104+
}
105+
100106
throw new InvalidArgumentException("Binding {$abstract} cannot be resolved while testing");
101107
}
102108
}

0 commit comments

Comments
 (0)