Development

Changeset 20954

You must first sign up to be able to contribute.

Changeset 20954

Show
Ignore:
Timestamp:
08/09/09 12:38:45 (5 years ago)
Author:
bschussek
Message:

Fixed: Classes with final methods can be mocked

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/lime/branches/2.0-experimental/lib/mock/LimeMock.php

    r20332 r20954  
    201201    foreach ($class->getMethods() as $method) 
    202202    { 
    203       if (!in_array($method->getName(), self::$illegalMethods)) 
     203      /* @var $method ReflectionMethod */ 
     204      if (!in_array($method->getName(), self::$illegalMethods) && !$method->isFinal()) 
    204205      { 
    205         /* @var $method ReflectionMethod */ 
    206206        $modifiers = Reflection::getModifierNames($method->getModifiers()); 
    207207        $modifiers = array_diff($modifiers, array('abstract')); 
  • tools/lime/branches/2.0-experimental/test/unit/mock/LimeMockTest.php

    r20496 r20954  
    5353} 
    5454 
     55class TestClassWithFinalMethods 
     56{ 
     57  public static $calls = 0; 
     58 
     59  public final function testMethod() 
     60  { 
     61    ++self::$calls; 
     62  } 
     63} 
     64 
    5565class TestException extends Exception {} 
    5666 
    5767 
    58 $t = new LimeTest(79); 
     68$t = new LimeTest(80); 
    5969 
    6070 
     
    133143  $t->is(TestClass::$calls, 0, 'The method has not been called'); 
    134144 
     145 
     146// @Test: Final methods cannot be mocked 
     147 
     148  // fixtures 
     149  TestClassWithFinalMethods::$calls = 0; 
     150  $m = LimeMock::create('TestClassWithFinalMethods'); 
     151  $m->replay(); 
     152  // test 
     153  $m->testMethod(); 
     154  // assertions 
     155  $t->is(TestClassWithFinalMethods::$calls, 1, 'The method has been called'); 
    135156 
    136157