/** * @param mixed $value * @param string $types comma-separated. * @param int $argumentNumber * @return mixed */ public static function check($value, $types, $argumentNumber = 1) { $checker = new DataTypeChecker(); try { return $checker->check(explode(',', $types), $value); } catch (DataTypeMismatchException $e) { throw new InvalidArgumentException($e->getMessage() . " for argument {$argumentNumber}"); } }
public function __call($words, $args) { if (null !== $words) { $this->syntax .= strtolower(preg_replace('/([A-Z])/', ' $1', $words)) . ' '; } if (count($args) > 0) { $this->data[] = $args[0]; $this->syntax .= '? '; } try { $syntax = ModuleManager::getInstance()->getSyntaxCache()->getSyntax($this->getSyntax()); } catch (Exception $e) { $syntax = null; } if ($syntax) { self::$lastBuilder = null; $class = $syntax->getClass(); /** @var AbstractModule $instance */ $instance = new $class(); $data = $this->getData(); $types = $syntax->getArgumentTypes(); $checker = new DataTypeChecker(); for ($i = 0; $i < count($types); ++$i) { try { $data[$i] = $checker->check($types[$i], $data[$i]); } catch (DataTypeMismatchException $e) { $renderer = new ValueRenderer(); throw new Exception("Argument " . ($i + 1) . ' (' . $renderer->render($data[$i]) . ') must be ' . implode(' or ', $types[$i]) . '.'); } } $instance->setData($data); $instance->syntax = $syntax; try { $instance->{$syntax->getMethod()}(); $this->testCase->assertTrue(true); } catch (DidNotMatchException $e) { $this->handleFailure($e, $instance); } } return $this; }
public function testInterfaceIsAllowedForClassName() { $result = $this->dataTypeChecker->check(array('class'), '\\Concise\\Mock\\MockInterface'); $this->assert($result)->equals('Concise\\Mock\\MockInterface'); }