/** * @covers ::mapTypeToMethodName */ public function test_will_check_the_cache_first() { // ---------------------------------------------------------------- // setup your test // // how this test works: // // step 1 - use the dispatch table as normal to seed the cache // step 2 - replace the type mapper with something that will throw // an exception if it is called // step 3 - repeat step 1. this time, the seeded cache will contain // a match // // our erroring type mapper will only be called if the dispatch table // is not checking the cache // create our dispatch table object $dispatchTable = ['object' => 'checkObject']; $typeMapper = new MapDuckTypeToMethodName(); $unit = new ObjectsOnlyDispatchTable($dispatchTable, $typeMapper); // make sure the type mapper is where we expect it $origTypeMapper = GetProperty::fromObject($unit, 'typeMapper'); $this->assertEquals($typeMapper, $origTypeMapper); // ---------------------------------------------------------------- // perform the change // step 1: seed the cache $unit->mapTypeToMethodName(new stdClass()); // step 2: replace the type mapper SetProperty::inObject($unit, 'typeMapper', new ObjectsOnlyDispatchTableTest_BadTypeMapper()); $badTypeMapper = GetProperty::fromObject($unit, 'typeMapper'); $this->assertNotEquals($typeMapper, $badTypeMapper); // step 3: repeat step 1 $unit->mapTypeToMethodName(new stdClass()); // ---------------------------------------------------------------- // test the results // if we get here and there is no exception, all is good }
/** * @covers ::inObject */ public function testCanSetPublicPropertyinObject() { // ---------------------------------------------------------------- // setup your test $expectedValue = 89; $target = new SetPropertyTest_ObjectTarget(); $origValue = GetProperty::fromObject($target, 'publicProp'); $this->assertNotEquals($expectedValue, $origValue); // ---------------------------------------------------------------- // perform the change SetProperty::inObject($target, 'publicProp', $expectedValue); $actualValue = GetProperty::fromObject($target, 'publicProp'); // ---------------------------------------------------------------- // test the results $this->assertEquals($expectedValue, $actualValue); }
/** * @covers ::fromObject */ public function testCanGetPublicPropertyFromObject() { // ---------------------------------------------------------------- // setup your test $expectedValue = 182; $target = new GetPropertyTest_ObjectTarget(); // ---------------------------------------------------------------- // perform the change $actualValue = GetProperty::fromObject($target, 'publicProp'); // ---------------------------------------------------------------- // test the results $this->assertEquals($expectedValue, $actualValue); }