示例#1
0
 /**
  * Accessor method for a type matcher.
  * 
  * @param   typeName string
  */
 public static function anyOfType($typeName)
 {
     $builder = new MockProxyBuilder();
     $builder->setOverwriteExisting(FALSE);
     $interfaces = array(XPClass::forName('unittest.mock.arguments.IArgumentMatcher'));
     $parentClass = NULL;
     $type = XPClass::forName($typeName);
     if ($type->isInterface()) {
         $interfaces[] = $type;
     } else {
         $parentClass = $type;
     }
     $proxyClass = $builder->createProxyClass(ClassLoader::getDefault(), $interfaces, $parentClass);
     return $proxyClass->newInstance(new TypeMatcher($typeName));
 }
 /**
  * Builds a stub instance for the specified type.
  *
  * @param   string typeName
  * @param   boolean overrideAll
  * @return  lang.Object
  */
 public function createMock($typeName, $overrideAll = TRUE)
 {
     $type = Type::forName($typeName);
     if (!$type instanceof XPClass) {
         throw new IllegalArgumentException('Cannot mock other types than XPClass types.');
     }
     $parentClass = NULL;
     $interfaces = array(XPClass::forName('unittest.mock.IMock'));
     if ($type->isInterface()) {
         $interfaces[] = $type;
     } else {
         $parentClass = $type;
     }
     $proxy = new MockProxyBuilder();
     $proxy->setOverwriteExisting($overrideAll);
     $proxyClass = $proxy->createProxyClass(ClassLoader::getDefault(), $interfaces, $parentClass);
     $mock = $proxyClass->newInstance(new MockProxy());
     $this->mocks[] = $mock;
     return $mock;
 }
 public function reserved_methods_should_not_be_overridden()
 {
     $proxyBuilder = new MockProxyBuilder();
     $proxyBuilder->setOverwriteExisting(TRUE);
     $class = $proxyBuilder->createProxyClass(ClassLoader::getDefault(), array(), XPClass::forName('net.xp_framework.unittest.tests.mock.AbstractDummy'));
     $proxy = $class->newInstance($this->handler);
     $proxy->equals(new Object());
     $this->assertFalse(isset($this->handler->invocations['equals_1']));
 }