Permalink
Browse files

Add lazyload test for issue #24 Fix

  • Loading branch information...
1 parent 6ad2e6c commit 660a7458c69a4dcf7763693ae28e1d9a9a654cba @nickl- nickl- committed Feb 22, 2013
Showing with 76 additions and 0 deletions.
  1. +76 −0 tests/library/Respect/Config/Issues/InstantiatorImplementsInvoke.php
@@ -0,0 +1,76 @@
+<?php
+namespace Respect\Config;
+
+class InstatiatorImplementsInvoke extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @group issues
+ * @ticket 24
+ */
+ public function testLazyLoadedParameters()
+ {
+ $config = "
+my_string = 'Hey you!'
+
+[hello Respect\Config\MyLazyLoadedHelloWorld]
+string = [my_string]
+";
+ $expected = 'Hello World!';
+ $container = new Container($config);
+ $container->my_string = $expected;
+ $this->assertEquals($expected, (string) $container->hello);
+ }
+
+ public function testLazyLoadedInstance()
+ {
+ $config = "
+my_string = 'Hey you!'
+
+[hello Respect\Config\MyLazyLoadedHelloWorld]
+string = [my_string]
+
+[consumer Respect\Config\MyLazyLoadedHelloWorldConsumer]
+hello = [hello]
+ ";
+ $expected = 'Hello World!';
+ $container = new Container($config);
+ $container->my_string = $expected;
+ $this->assertEquals($expected, (string) $container->hello);
+ $container = new Container($config);
+ $container->{"hello Respect\\Config\\MyLazyLoadedHelloWorld"} = array('string' => $expected);
+ $this->assertEquals($expected, (string) $container->hello);
+ $container = new Container($config);
+ $container->hello = new MyLazyLoadedHelloWorld($expected);
+ $this->assertEquals($expected, (string) $container->hello);
+ }
+}
+class MyLazyLoadedHelloWorldConsumer
+{
+ protected $string;
+
+ public function __construct($hello)
+ {
+ $this->string = $hello;
+ }
+
+ public function __toString()
+ {
+ return $this->string;
+ }
+}
+
+class MyLazyLoadedHelloWorld
+{
+ protected $string;
+
+ public function __construct($string)
+ {
+ $this->string = $string;
+ }
+
+ public function __toString()
+ {
+ return $this->string;
+ }
+}
+

0 comments on commit 660a745

Please sign in to comment.