/** * @covers ::mapTypeToMethodName */ public function test_can_change_the_default_fallback_when_no_match_found() { // ---------------------------------------------------------------- // setup your test $item = true; $dispatchTable = []; $expectedResult = "nothingComparesToYou"; $typeMapper = new MapDuckTypeToMethodName(); $unit = new AllPurposeDispatchTable($dispatchTable, $typeMapper, $expectedResult); // ---------------------------------------------------------------- // perform the change $actualResult = $unit->mapTypeToMethodName($item); // ---------------------------------------------------------------- // test the results $this->assertEquals($expectedResult, $actualResult); }
$method = $cachingTable->mapTypeToMethodName($item); } $endTime = microtime(true); $totalTime = round($endTime - $startTime, 3); echo "[Objects only ] Total time: " . $totalTime . PHP_EOL; // let's compare that with our type-driven caching dispatch table $startTime = microtime(true); $cachingTable = new TypeOnlyDispatchTable($dispatchTable, new MapStrictTypeToMethodName()); for ($i = 0; $i < $maxIterations; $i++) { $method = $cachingTable->mapTypeToMethodName($item); } $endTime = microtime(true); $totalTime = round($endTime - $startTime, 3); echo "[Type only ] Total time: " . $totalTime . PHP_EOL; // let's compare that with our caching dispatch table $startTime = microtime(true); $cachingTable = new AllPurposeDispatchTable($dispatchTable, new MapStrictTypeToMethodName()); for ($i = 0; $i < $maxIterations; $i++) { $method = $cachingTable->mapTypeToMethodName($item); } $endTime = microtime(true); $totalTime = round($endTime - $startTime, 3); echo "[All Purpose ] Total time: " . $totalTime . PHP_EOL; // finally, not using a caching dispatch table at all $startTime = microtime(true); for ($i = 0; $i < $maxIterations; $i++) { $method = MapStrictTypeToMethodName::using($item, $dispatchTable); } $endTime = microtime(true); $totalTime = round($endTime - $startTime, 3); echo "[No cache ] Total time: " . $totalTime . PHP_EOL;