Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
8 changes: 3 additions & 5 deletions src/Traits/GetDependenciesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function resolveClassMethodDependencies(object $instance, string $method)
}, (new ReflectionMethod($instance, $method))->getParameters());
}

protected function transformDependency(ReflectionParameter $parameter)
protected function transformDependency(ReflectionParameter $parameter): ?string
{
$type = $parameter->getType();

Expand All @@ -29,7 +29,7 @@ protected function transformDependency(ReflectionParameter $parameter)
return interface_exists($type->getName()) ? $this->getClassByInterface($type->getName()) : $type->getName();
}

protected function getClassByInterface($interfaceName)
protected function getClassByInterface($interfaceName): ?string
{
$bindings = Container::getInstance()->getBindings();

Expand All @@ -39,8 +39,6 @@ protected function getClassByInterface($interfaceName)
return null;
}

$classFields = (new ReflectionFunction($implementation))->getStaticVariables();

return $classFields['concrete'];
return get_class(call_user_func($implementation, app()));
}
}
20 changes: 18 additions & 2 deletions tests/SwaggerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
use RonasIT\AutoDoc\Exceptions\UnsupportedDocumentationViewerException;
use RonasIT\AutoDoc\Exceptions\WrongSecurityConfigException;
use RonasIT\AutoDoc\Services\SwaggerService;
use RonasIT\AutoDoc\Tests\Support\Mock\InvokableTestController;
use RonasIT\AutoDoc\Tests\Support\Mock\TestContract;
use RonasIT\AutoDoc\Tests\Support\Mock\TestNotificationSetting;
use RonasIT\AutoDoc\Tests\Support\Mock\TestRequest;
use RonasIT\AutoDoc\Tests\Support\Mock\TestRequestContract;
use RonasIT\AutoDoc\Tests\Support\Traits\SwaggerServiceMockTrait;
use stdClass;

Expand Down Expand Up @@ -682,9 +684,23 @@ public function testAddDataWithNotExistsMethodOnController()
$service->addData($request, $response);
}

public function testAddDataWithBindingInterface()
public static function addDataWithBindingInterface(): array
{
$this->app->bind(TestContract::class, TestRequest::class);
return [
[
'concrete' => TestRequest::class,
],
[
'concrete' => fn ($app) => new TestRequest(),
],
];
}

#[DataProvider('addDataWithBindingInterface')]
public function testAddDataWithBindingInterface($concrete)
{
$this->app->bind(TestContract::class, $concrete);

$this->mockDriverGetEmptyAndSaveProcessTmpData($this->getJsonFixture('tmp_data_get_user_request'));

$service = app(SwaggerService::class);
Expand Down