Exemplo n.º 1
0
 public function testBehaviorFunctionCalls()
 {
     $this->component->attachBehavior('FooBarBehavior', $behavior = new FooBarBehavior());
     $this->component->attachClassBehavior('FooClassBehavior', $classbehavior = new FooClassBehavior());
     // Test the Class Methods
     $this->assertEquals(12, $this->component->faaEverMore(3, 4));
     // Check that the called object is shifted in front of the array of a class behavior call
     $this->assertEquals($this->component, $this->component->getLastClassObject());
     //Test the FooBarBehavior
     $this->assertEquals(27, $this->component->moreFunction(3, 3));
     $this->assertTrue($this->component->disableBehavior('FooBarBehavior'));
     try {
         $this->assertNull($this->component->moreFunction(3, 4));
         $this->fail('TApplicationException not raised trying to execute a disabled behavior');
     } catch (TApplicationException $e) {
     }
     $this->assertTrue($this->component->enableBehavior('FooBarBehavior'));
     // Test the global event space, this should work and return false because no function implements these methods
     $this->assertNull($this->component->fxSomeUndefinedGlobalEvent());
     $this->assertNull($this->component->dySomeUndefinedIntraObjectEvent());
     $this->component->detachClassBehavior('FooClassBehavior');
     // test object instance behaviors implemented through class-wide behaviors
     $this->component->attachClassBehavior('FooFooBehaviorAsClass', 'FooFooBehavior');
     $component = new NewComponent();
     $this->assertEquals(5, $this->component->faafaaEverMore(3, 4));
     $this->assertEquals(10, $component->faafaaEverMore(6, 8));
     $this->component->detachClassBehavior('FooFooBehaviorAsClass');
     $component->unlisten();
     $component = null;
     try {
         $this->component->faafaaEverMore(3, 4);
         $this->fail('TApplicationException not raised trying to execute a disabled behavior');
     } catch (TApplicationException $e) {
     }
     // make a call to an unpatched fx and dy call so that it's passed through to the __dycall function
     $dynamicComponent = new DynamicCallComponent();
     $this->assertNull($dynamicComponent->fxUndefinedEvent());
     $this->assertNull($dynamicComponent->dyUndefinedEvent());
     //This tests the dynamic __dycall function
     $this->assertEquals(1024, $dynamicComponent->dyPowerFunction(2, 10));
     $this->assertEquals(5, $dynamicComponent->dyDivisionFunction(10, 2));
     $this->assertEquals(2048, $dynamicComponent->fxPowerFunction(2, 10));
     $this->assertEquals(10, $dynamicComponent->fxDivisionFunction(10, 2));
     $dynamicComponent->unlisten();
 }