示例#1
0
 /**
  * @test
  * it should allow binding a singleton to a concrete class
  */
 public function it_should_allow_binding_a_singleton_to_a_concrete_class()
 {
     $bindingsResolver = $this->getMock('tad_DI52_Bindings_ResolverInterface');
     $bindingsResolver->expects($this->once())->method('singleton')->with('ConcreteClassOne', 'ObjectOne', null);
     $bindingsResolver->expects($this->once())->method('resolve')->with('ConcreteClassOne');
     $container = new tad_DI52_Container();
     $container->setBindingsResolver($bindingsResolver);
     $container->singleton('ConcreteClassOne', 'ObjectOne');
     $container->make('ConcreteClassOne');
 }
<?php

$di52 = new tad_DI52_Container();
$di52->singleton('A', 'A');
//Trigger all autoloaders
$a = $di52->make('A');
unset($a);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $a = $di52->make('A');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);