Changeset 1371

Show
Ignore:
Timestamp:
02/25/08 23:27:22 (3 months ago)
Author:
mikey
Message:

finished enhancement #97: added tests for new use cases and some more tests for better code coverage of the ioc container

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ioc/ioc.php

    r1222 r1371  
    77 * @subpackage  ioc 
    88 */ 
     9// @codeCoverageIgnoreStart 
    910stubClassLoader::load('net::stubbles::ioc::stubBinder'); 
     11// @codeCoverageIgnoreEnd 
    1012?> 
  • trunk/src/main/php/net/stubbles/ioc/stubAbstractIOCPreInterceptor.php

    r1301 r1371  
    2929    { 
    3030        $binder = stubRegistry::get(stubBinder::REGISTRY_KEY); 
    31         if ($binder === null) { 
     31        if (null === $binder) { 
    3232            $binder = new stubBinder(); 
    3333            stubRegistry::set(stubBinder::REGISTRY_KEY, $binder); 
    3434        } 
     35         
    3536        $this->configure($binder); 
    3637    } 
    3738 
    3839    /** 
    39      * Configure the binder 
     40     * configure the binder 
    4041     * 
    4142     * @param  stubBinder  $binder 
  • trunk/src/main/php/net/stubbles/ioc/stubBinder.php

    r1301 r1371  
    7878    public function bindConstant() 
    7979    { 
    80         $binding = new stubConstantBinding($this->injector); 
     80        $binding = new stubConstantBinding(); 
    8181        $this->injector->addBinding($binding); 
    8282        return $binding; 
  • trunk/src/main/php/net/stubbles/ioc/stubBinding.php

    r1370 r1371  
    3737     */ 
    3838    public function getKey(); 
    39  
    40     /** 
    41      * get the scope for this binding 
    42      * 
    43      * @return  stubBindingScope 
    44      */ 
    45     public function getScope(); 
    4639} 
    4740?> 
  • trunk/src/main/php/net/stubbles/ioc/stubClassBinding.php

    r1370 r1371  
    190190        return $this->type . '#' . $this->name; 
    191191    } 
    192  
    193     /** 
    194      * get the scope of the binding 
    195      * 
    196      * @return  stubBindingScope 
    197      */ 
    198     public function getScope() 
    199     { 
    200         return $this->scope; 
    201     } 
    202  
    203192} 
    204193?> 
  • trunk/src/main/php/net/stubbles/ioc/stubConstantBinding.php

    r1370 r1371  
    2121     * This string is used when generating the key for a constant binding. 
    2222     */ 
    23     const TYPE          = '__CONSTANT__'; 
    24     /** 
    25      * injector used by this binding 
    26      * 
    27      * @var  stubInjector 
    28      */ 
    29     protected $injector = null; 
     23    const TYPE               = '__CONSTANT__'; 
    3024    /** 
    3125     * annotated with a name 
     
    3327     * @var  string 
    3428     */ 
    35     protected $name     = null; 
     29    protected $name          = null; 
    3630    /** 
    3731     * provider that holds the binded value 
     
    4337    /** 
    4438     * constructor 
    45      * 
    46      * @param  stubInjector  $injector 
    4739     */ 
    48     public function __construct($injector
     40    public function __construct(
    4941    { 
    50         $this->injector      = $injector; 
    5142        $this->valueProvider = new stubValueInjectionProvider(); 
    5243    } 
     
    9586        return self::TYPE . '#' . $this->name; 
    9687    } 
    97  
    98     /** 
    99      * constant bindings have no scope 
    100      * 
    101      * @return  stubBindingScope 
    102      */ 
    103     public function getScope() 
    104     { 
    105         return null; 
    106     } 
    10788} 
    10889?> 
  • trunk/src/main/php/net/stubbles/ioc/stubInjector.php

    r1370 r1371  
    153153         
    154154        foreach ($class->getMethods() as $method) { 
    155             if (strncmp($method->getName(), '__', 2) === 0) { 
    156                 continue; 
    157             } 
    158              
    159             if ($method->isPublic() === false) { 
    160                 continue; 
    161             } 
    162              
    163             if ($method->hasAnnotation('Inject') === false) { 
     155            if (strncmp($method->getName(), '__', 2) === 0 || $method->isPublic() === false || $method->hasAnnotation('Inject') === false) { 
    164156                continue; 
    165157            } 
  • trunk/src/test/php/net/stubbles/ioc/IOCTestSuite.php

    r1235 r1371  
    2929        $suite->addTestFile($dir . '/annotations/stubNamedAnnotationTestCase.php'); 
    3030        $suite->addTestFile($dir . '/annotations/stubSingletonAnnotationTestCase.php'); 
     31        $suite->addTestFile($dir . '/stubAbstractIOCPreInterceptorTestCase.php'); 
    3132        $suite->addTestFile($dir . '/stubBinderTestCase.php'); 
    3233        $suite->addTestFile($dir . '/stubInjectorBasicTestCase.php'); 
     
    3435        $suite->addTestFile($dir . '/stubInjectorImplementedByTestCase.php'); 
    3536        $suite->addTestFile($dir . '/stubInjectorNamedTestCase.php'); 
     37        $suite->addTestFile($dir . '/stubInjectorProviderTestCase.php'); 
    3638        $suite->addTestFile($dir . '/stubInjectorSingletonTestCase.php'); 
    3739        $suite->addTestFile($dir . '/stubIOCPreInterceptorTestCase.php'); 
  • trunk/src/test/php/net/stubbles/ioc/stubBinderTestCase.php

    r1235 r1371  
    55 * @author      Stephan Schmidt <schst@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  ioc_injection_test 
     7 * @subpackage  ioc_test 
    88 */ 
    99stubClassLoader::load('net::stubbles::ioc::stubBinder'); 
     
    1313 * 
    1414 * @package     stubbles 
    15  * @subpackage  ioc_injection_test 
     15 * @subpackage  ioc_test 
    1616 */ 
    1717class stubBinderTestCase extends PHPUnit_Framework_TestCase 
  • trunk/src/test/php/net/stubbles/ioc/stubInjectorBasicTestCase.php

    r1235 r1371  
    489489        $this->assertType('stubInjectorTestCase_Goodyear', $obj->getGoodyearBySetter()); 
    490490    } 
     491 
     492    /** 
     493     * given injector should be used instead of creating a new one 
     494     * 
     495     * @test 
     496     */ 
     497    public function injectedInjectorIsUsed() 
     498    { 
     499        $injector = new stubInjector(); 
     500        $binder   = new stubBinder($injector); 
     501        $this->assertSame($injector, $binder->getInjector()); 
     502    } 
     503 
     504    /** 
     505     * requesting a missing binding throws a binding exception 
     506     * 
     507     * @test 
     508     * @expectedException  stubBindingException 
     509     */ 
     510    public function missingBindingThrowsBindingException() 
     511    { 
     512        $injector = new stubInjector(); 
     513        $injector->getInstance('stubInjectorTestCase_Vehicle'); 
     514    } 
     515 
     516    /** 
     517     * requesting a missing binding throws a binding exception 
     518     * 
     519     * @test 
     520     * @expectedException  stubBindingException 
     521     */ 
     522    public function missingBindingOnInjectionHandlingThrowsBindingException() 
     523    { 
     524        $injector = new stubInjector(); 
     525        $class    = new stubInjectorTestCase_Bike(); 
     526        $injector->handleInjections($class); 
     527    } 
    491528} 
    492529?> 
  • trunk/src/test/php/net/stubbles/ioc/stubInjectorConstantTestCase.php

    r1235 r1371  
    55 * @author      Stephan Schmidt <schst@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  ioc_injection_test 
     7 * @subpackage  ioc_test 
    88 */ 
    99stubClassLoader::load('net::stubbles::ioc::stubBinder'); 
     
    2929 * 
    3030 * @package     stubbles 
    31  * @subpackage  ioc_injection_test 
     31 * @subpackage  ioc_test 
    3232 */ 
    3333class stubInjectorConstantTestCase extends PHPUnit_Framework_TestCase 
  • trunk/src/test/php/net/stubbles/ioc/stubInjectorImplementedByTestCase.php

    r1235 r1371  
    55 * @author      Stephan Schmidt <schst@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  ioc_injection_test 
     7 * @subpackage  ioc_test 
    88 */ 
    99stubClassLoader::load('net::stubbles::ioc::stubBinder'); 
     
    3434 * 
    3535 * @package     stubbles 
    36  * @subpackage  ioc_injection_test 
     36 * @subpackage  ioc_test 
    3737 */ 
    3838class stubInjectorImplementedByTestCase extends PHPUnit_Framework_TestCase 
  • trunk/src/test/php/net/stubbles/ioc/stubInjectorNamedTestCase.php

    r1235 r1371  
    55 * @author      Stephan Schmidt <schst@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  ioc_injection_test 
     7 * @subpackage  ioc_test 
    88 */ 
    99stubClassLoader::load('net::stubbles::ioc::stubBinder'); 
     
    5656 * 
    5757 * @package     stubbles 
    58  * @subpackage  ioc_injection_test 
     58 * @subpackage  ioc_test 
    5959 */ 
    6060class stubInjectorNamedTestCase extends PHPUnit_Framework_TestCase 
  • trunk/src/test/php/net/stubbles/ioc/stubInjectorSingletonTestCase.php

    r1235 r1371  
    55 * @author      Stephan Schmidt <schst@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  ioc_injection_test 
     7 * @subpackage  ioc_test 
    88 */ 
    99stubClassLoader::load('net::stubbles::ioc::stubBinder'); 
     
    7777 * 
    7878 * @package     stubbles 
    79  * @subpackage  ioc_injection_test 
     79 * @subpackage  ioc_test 
    8080 */ 
    8181class stubInjectorSingletonTestCase extends PHPUnit_Framework_TestCase