-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Doug Nelson
committed
Jun 12, 2020
1 parent
9b60e63
commit 9d4e367
Showing
6 changed files
with
104 additions
and
29 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
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,18 @@ | ||
<?php | ||
|
||
namespace Silktide\Syringe\IntegrationTests\Lazy; | ||
|
||
class LazyClass | ||
{ | ||
public static $loaded = false; | ||
|
||
public function __construct() | ||
{ | ||
self::$loaded = true; | ||
} | ||
|
||
public function getTrue() : bool | ||
{ | ||
return true; | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
|
||
namespace Silktide\Syringe\IntegrationTests\Lazy; | ||
|
||
|
||
use PHPUnit\Framework\TestCase; | ||
use Silktide\Syringe\IntegrationTests\Examples\ExampleClass; | ||
use Silktide\Syringe\Syringe; | ||
|
||
class LazyTest extends TestCase | ||
{ | ||
public function testLazyLoading() | ||
{ | ||
$container = Syringe::build([ | ||
"paths" => [__DIR__], | ||
"files" => ["file1.yml"] | ||
]); | ||
|
||
/** | ||
* @var LazyClass $myService | ||
*/ | ||
$myService = $container["my_service"]; | ||
$this->assertInstanceOf(LazyClass::class, $myService); | ||
$this->assertFalse(LazyClass::$loaded); | ||
$myService->getTrue(); | ||
$this->assertTrue(LazyClass::$loaded); | ||
} | ||
} |
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,4 @@ | ||
services: | ||
my_service: | ||
class: Silktide\Syringe\IntegrationTests\Lazy\LazyClass | ||
lazy: true |