/**
  * @test
  * it should return the var value when directly requested
  */
 public function it_should_return_the_var_value_when_directly_requested()
 {
     $container = new tad_DI52_Container();
     $container['some-var'] = 23;
     $value = $container->resolve('%some-var%');
     $this->assertEquals(23, $value);
 }
Esempio n. 2
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);
 }
Esempio n. 3
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);
 }
 /**
  * @test
  * it should allow a deferred service provider to bind and singleton classes
  */
 public function it_should_allow_a_deferred_service_provider_to_bind_and_singleton_classes()
 {
     $container = new tad_DI52_Container();
     $container->register('DeferredServiceProviderThree');
     $instance1 = $container->resolve('TestInterfaceOne');
     $instance2 = $container->resolve('TestInterfaceOne');
     $this->assertSame($instance1, $instance2);
     $instance3 = $container->resolve('TestInterfaceTwo');
     $instance4 = $container->resolve('TestInterfaceTwo');
     $this->assertEquals($instance3, $instance4);
     $this->assertNotSame($instance3, $instance4);
 }
Esempio n. 5
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);
<?php

$di52 = new tad_DI52_Container();
//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);
Esempio n. 11
0
 protected function resolveValue($value)
 {
     return $this->container->resolve($value);
 }
Esempio n. 12
0
<?php

$container = new tad_DI52_Container();
$container->register('idlikethis_ServiceProviders_Shortcodes');
$container->register('idlikethis_ServiceProviders_Endpoints');
$container->register('idlikethis_ServiceProviders_Scripts');
$container->register('idlikethis_ServiceProviders_CommentsTable');
$container->register('idlikethis_ServiceProviders_MetaBoxes');
return $container;