-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved Service Provider test to own class.
- Loading branch information
1 parent
9745fc8
commit d6310ac
Showing
7 changed files
with
154 additions
and
56 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,27 @@ | ||
<?php | ||
|
||
/** | ||
* Qubus\Injector | ||
* | ||
* @link https://github.com/QubusPHP/injector | ||
* @copyright 2021 Joshua Parker <[email protected]> | ||
* @license https://opensource.org/licenses/mit-license.php MIT License | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Qubus\Injector\Tests\ServiceProvider; | ||
|
||
use Qubus\Injector\ServiceContainer; | ||
use Qubus\Injector\ServiceProvider\BaseServiceProvider; | ||
|
||
class FakeServiceProvider extends BaseServiceProvider | ||
{ | ||
public function register(ServiceContainer $container): void | ||
{ | ||
$container->alias('user.model', UserModel::class) | ||
->define('user.model', [':userName' => new Person('Joseph Smith')]); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
/** | ||
* Qubus\Injector | ||
* | ||
* @link https://github.com/QubusPHP/injector | ||
* @copyright 2021 Joshua Parker <[email protected]> | ||
* @license https://opensource.org/licenses/mit-license.php MIT License | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Qubus\Injector\Tests\ServiceProvider; | ||
|
||
interface Identity | ||
{ | ||
} |
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,20 @@ | ||
<?php | ||
|
||
/** | ||
* Qubus\Injector | ||
* | ||
* @link https://github.com/QubusPHP/injector | ||
* @copyright 2021 Joshua Parker <[email protected]> | ||
* @license https://opensource.org/licenses/mit-license.php MIT License | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Qubus\Injector\Tests\ServiceProvider; | ||
|
||
interface Model | ||
{ | ||
public function userName(): Identity; | ||
} |
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,22 @@ | ||
<?php | ||
|
||
/** | ||
* Qubus\Injector | ||
* | ||
* @link https://github.com/QubusPHP/injector | ||
* @copyright 2021 Joshua Parker <[email protected]> | ||
* @license https://opensource.org/licenses/mit-license.php MIT License | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Qubus\Injector\Tests\ServiceProvider; | ||
|
||
class Person implements Identity | ||
{ | ||
public function __construct(protected ?string $userName = null) | ||
{ | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
/** | ||
* Qubus\Injector | ||
* | ||
* @link https://github.com/QubusPHP/injector | ||
* @copyright 2021 Joshua Parker <[email protected]> | ||
* @license https://opensource.org/licenses/mit-license.php MIT License | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Qubus\Injector\Tests\ServiceProvider; | ||
|
||
class UserModel implements Model | ||
{ | ||
public function __construct( | ||
protected ?Identity $userName = null | ||
) { | ||
} | ||
|
||
public function userName(): Identity | ||
{ | ||
return $this->userName; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
/** | ||
* Qubus\Injector | ||
* | ||
* @link https://github.com/QubusPHP/injector | ||
* @copyright 2021 Joshua Parker <[email protected]> | ||
* @license https://opensource.org/licenses/mit-license.php MIT License | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
|
||
namespace Qubus\Tests\Injector; | ||
|
||
use PHPUnit\Framework\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
use Qubus\Injector\Config\Factory; | ||
use Qubus\Injector\Psr11\Container; | ||
use Qubus\Injector\Tests\ServiceProvider\FakeServiceProvider; | ||
use Qubus\Injector\Tests\ServiceProvider\Person; | ||
|
||
class ServiceProviderTest extends TestCase | ||
{ | ||
public function testFakeServiceProvider() | ||
{ | ||
$injector = new Container(Factory::create([])); | ||
|
||
$service = new FakeServiceProvider(); | ||
$service->register($injector); | ||
|
||
$name = new Person('Joseph Smith'); | ||
|
||
$injected = $injector->make('user.model'); | ||
|
||
Assert::assertEquals($name, $injected->userName()); | ||
Assert::assertInstanceOf(Person::class, $injected->userName()); | ||
} | ||
} |