Пример #1
0
 /**
  * Accessor method for a type matcher.
  * 
  * @param   typeName string
  */
 public static function anyOfType($typeName)
 {
     $builder = new MockProxyBuilder();
     $builder->setOverwriteExisting(false);
     $interfaces = [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));
 }
Пример #2
0
 /**
  * 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 = [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(\lang\ClassLoader::getDefault(), [], \lang\XPClass::forName('net.xp_framework.unittest.tests.mock.AbstractDummy'));
     $proxy = $class->newInstance($this->handler);
     $proxy->equals(new \lang\Object());
     $this->assertFalse(isset($this->handler->invocations['equals_1']));
 }