예제 #1
0
 public function testPrepareValue()
 {
     $values = array('one' => 'Foo', 'two' => 'BAR', 'three' => function () {
         return 'baz';
     });
     $context = new Context($values);
     $varA = new Variable('four', 'qux');
     $this->assertInstanceOf('Ruler\\Value', $varA->prepareValue($context));
     $this->assertEquals('qux', $varA->prepareValue($context)->getValue(), "Variables should return the default value if it's missing from the context.");
     $varB = new Variable('one', 'FAIL');
     $this->assertEquals('Foo', $varB->prepareValue($context)->getValue());
     $varC = new Variable('three', 'FAIL');
     $this->assertEquals('baz', $varC->prepareValue($context)->getValue());
     $varD = new Variable(null, 'qux');
     $this->assertInstanceOf('Ruler\\Value', $varD->prepareValue($context));
     $this->assertEquals('qux', $varD->prepareValue($context)->getValue(), "Anonymous variables don't require a name to prepare value");
 }