Exemple #1
0
 /**
  * $this->invalidArgument(1, $param1, 'PositiveInteger', __FUNCTION__);
  * @param string|Type $expected der Type oder ein String der den Typ beschreibt
  * @cc-ignore
  */
 protected function invalidArgument($num, $actual, $expected, $function)
 {
     $class = Code::getClass($this);
     $namespace = Code::getNamespace($class);
     $context = $class . '::' . $function . '()';
     $expandType = function ($type) use($class, $namespace) {
         if (is_string($type)) {
             $type = Type::create($type);
             if ($type instanceof ObjectType) {
                 $type->expandNamespace($namespace);
             }
         }
         return $type;
     };
     if (is_array($expected)) {
         $composite = Type::create('Composite');
         foreach ($expected as $type) {
             $composite->addComponent($expandType($type));
         }
         $expected = $composite;
     } else {
         $expected = $expandType($expected);
     }
     return Exception::invalidArgument($num, $context, $actual, $expected);
 }
Exemple #2
0
 public function testInvalidArgumentException()
 {
     $this->assertEquals(Exception::invalidArgument(1, 'Psc\\ASimpleObjectClass::doSomething()', 'wrongValue', Type::create('Composite')->setComponents(Type::create('Integer'), Type::create('Object<Psc\\NiceClass>'))), $this->simpleObject->doSomething('wrongValue'));
 }