/** * @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 TypeOnlyDispatchTable($dispatchTable, $typeMapper, $expectedResult); // ---------------------------------------------------------------- // perform the change $actualResult = $unit->mapTypeToMethodName($item); // ---------------------------------------------------------------- // test the results $this->assertEquals($expectedResult, $actualResult); }
} $endTime = microtime(true); $totalTime = round($endTime - $startTime, 3); echo "[Manual cache 2 ] Total time: " . $totalTime . PHP_EOL; // let's compare that with our object-driven caching dispatch table $startTime = microtime(true); $cachingTable = new ObjectsOnlyDispatchTable($dispatchTable, new MapStrictTypeToMethodName()); for ($i = 0; $i < $maxIterations; $i++) { $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;