Пример #1
0
 /**
  * @test
  * it should allow a service provider to bind at boot
  */
 public function it_should_allow_a_service_provider_to_bind_at_boot()
 {
     $container = new tad_DI52_Container();
     $container->register('ServiceProviderTwo');
     $container->boot();
     $out = $container->make('TestInterfaceThree');
     $this->assertInstanceOf('TestInterfaceThree', $out);
 }
Пример #2
0
 /**
  * @test
  * it should allow not specifying the class of simple objects
  */
 public function it_should_allow_not_specifying_the_class_of_simple_objects()
 {
     // not specifying a ctor method for tad_Dependency
     // $this->sut->setCtor( 'dependency', 'DependencyObjectOne' );
     $this->sut->setVar('string', 'foo');
     $this->sut->setVar('int', 23);
     $class = 'DependingClassThree';
     $dependencyClass = 'ConcreteClassOne';
     $this->sut->setCtor('object', $class, '~' . $dependencyClass);
     $i = $this->sut->make('object');
     $this->assertInstanceOf($class, $i);
     $this->assertInstanceOf($dependencyClass, $i->classOne);
 }
Пример #3
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);
<?php

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

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

$di52 = new tad_DI52_Container();
for ($i = 0; $i < $argv[1]; $i++) {
    $j = $di52->make('J');
}
$results = ['time' => 0, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);