コード例 #1
0
 /**
  * @test
  */
 public function renderCanRenderMultipleComplexObjects()
 {
     $array = array('foo' => array('bar' => 'Baz'));
     $object = new \stdClass();
     $object->foo = 'Foo';
     $this->view->assign('array', $array)->assign('object', $object)->assign('someOtherVariable', 'Value3');
     $this->view->setVariablesToRender(array('array', 'object'));
     $expectedResult = '{"array":{"foo":{"bar":"Baz"}},"object":{"foo":"Foo"}}';
     $actualResult = $this->view->render();
     $this->assertEquals($expectedResult, $actualResult);
 }
コード例 #2
0
 /**
  * @test
  */
 public function viewAcceptsJsonEncodingOptions()
 {
     $array = array('foo' => array('bar' => 'Baz', 'foo' => '1'));
     $this->view->setOption('jsonEncodingOptions', JSON_PRETTY_PRINT);
     $this->view->assign('array', $array);
     $this->view->setVariablesToRender(array('array'));
     $expectedResult = json_encode($array, JSON_PRETTY_PRINT);
     $actualResult = $this->view->render();
     $this->assertEquals($expectedResult, $actualResult);
     $unexpectedResult = json_encode($array);
     $this->assertNotEquals($unexpectedResult, $actualResult);
 }