presenter = new ObjectPresenter(); $this->manager = new PresenterManager(); $this->manager->addPresenter(new ScalarPresenter()); $this->manager->addPresenter(new ArrayPresenter()); $this->manager->addPresenter($this->presenter); } public function testPresentEmptyObject() { $empty = new \StdClass(); $this->assertEquals( $this->presenter->presentRef($empty) . ' {}', $this->presenter->present($empty) ); } public function testPresentWithDepth() { $obj = new \StdClass(); $obj->name = 'std'; $obj->type = 'class'; $obj->tags = array('stuff', 'junk'); $obj->child = new \StdClass(); $obj->child->name = 'std, jr'; $hash = spl_object_hash($obj); $childHash = spl_object_hash($obj->child); $expected = <<\<stdClass #$hash> { name: "std", type: "class", tags: Array(2), child: \<stdClass #$childHash> } EOS; $this->assertStringMatchesFormat($expected, $this->presenter->present($obj, 1)); } public function testPresentWithoutDepth() { $obj = new \StdClass(); $obj->name = 'std'; $obj->type = 'class'; $obj->tags = array('stuff', 'junk'); $obj->child = new \StdClass(); $obj->child->name = 'std, jr'; $hash = spl_object_hash($obj); $childHash = spl_object_hash($obj->child); $expected = <<\<stdClass #$hash> { name: "std", type: "class", tags: [ "stuff", "junk" ], child: \<stdClass #$childHash> { name: "std, jr" } } EOS; $this->assertStringMatchesFormat($expected, $this->presenter->present($obj)); } public function testPresentRef() { $obj = new \StdClass(); $formatted = $this->presenter->presentRef($obj); $this->assertStringMatchesFormat('\<stdClass #%s>', $formatted); $this->assertContains(spl_object_hash($obj), $formatted); } public function testPresentVerbose() { $obj = new SimpleClass(); $hash = spl_object_hash($obj); $expected = <<\<Psy\Test\Presenter\Fixtures\SimpleClass #$hash> { hello: "Hello world!", foo: "bar", secret: 42 } EOS; $this->assertStringMatchesFormat($expected, $this->presenter->present($obj, null, Presenter::VERBOSE)); } }