Changeset 1004

Show
Ignore:
Timestamp:
11/08/07 19:57:51 (1 year ago)
Author:
schst
Message:

Added instanceof check, when binding to an instance

Files:

Legend:

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

    r863 r1004  
    105105     */ 
    106106    public function toInstance($instance) { 
     107        if (!$instance instanceof $this->type) { 
     108            throw new stubIllegalArgumentException("Instance of {$this->type} expectected, " . get_class($instance) . " given."); 
     109        } 
    107110        $this->instance = $instance; 
    108111        return $this; 
  • trunk/src/test/php/net/stubbles/ioc/stubInjectorBasicTestCase.php

    r854 r1004  
    172172 
    173173    /** 
    174      * test setter injections 
     174     * test bindings to an instance 
    175175     */ 
    176176    public function testSetterInjectionByInstance() 
     
    198198 
    199199    /** 
     200     * test bindings to an instance with an invalid type 
     201     */ 
     202    public function testSetterInjectionByInvalidInstance() 
     203    { 
     204        $tire = new stubInjectorTestCase_Goodyear(); 
     205 
     206        $binder = new stubBinder(); 
     207        $this->expectException('stubIllegalArgumentException'); 
     208        $binder->bind('stubInjectorTestCase_Vehicle')->toInstance($tire); 
     209    } 
     210 
     211 
     212    /** 
    200213     * test setter injections 
    201214     */