generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable dependency injection in check constructors
- Loading branch information
1 parent
dbe8b39
commit 5138e55
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Spatie\Health\Tests\TestClasses\DependencyInjectionCheck; | ||
|
||
it('will use dependency injection to resolve constructor arguments', function () { | ||
$check = DependencyInjectionCheck::new(); | ||
|
||
expect($check->getLogger())->toBeInstanceOf(LoggerInterface::class); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Spatie\Health\Tests\TestClasses; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Spatie\Health\Checks\Check; | ||
use Spatie\Health\Checks\Result; | ||
use Spatie\Health\Enums\Status; | ||
|
||
class DependencyInjectionCheck extends Check | ||
{ | ||
protected LoggerInterface $logger; | ||
|
||
public function __construct(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
public function run(): Result | ||
{ | ||
$this->logger->info('Dependency injection worked'); | ||
|
||
return new Result( | ||
Status::ok(), | ||
); | ||
} | ||
|
||
public function getLogger(): LoggerInterface | ||
{ | ||
return $this->logger; | ||
} | ||
} |