コード例 #1
0
 /**
  * @param string $syntax
  * @param array  $data
  * @return string
  */
 public function render($syntax, array $data = array())
 {
     ArgumentChecker::check($syntax, 'string');
     $renderer = new ValueRenderer();
     if (self::$color) {
         $renderer->setTheme(new DefaultTheme());
     }
     return preg_replace_callback('/\\?/', function () use(&$data, $renderer) {
         $r = $renderer->render(array_shift($data));
         return $r;
     }, $syntax);
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 public function testRenderAnythingConstant()
 {
     $this->assert($this->renderer->render(self::ANYTHING))->equals('<ANYTHING>');
 }
コード例 #4
0
ファイル: MockManager.php プロジェクト: elliotchance/concise
 protected function renderArguments(array $args = null)
 {
     if (null === $args) {
         return '';
     }
     $valueRenderer = new ValueRenderer();
     return $valueRenderer->renderAll($args);
 }
コード例 #5
0
ファイル: MockBuilder.php プロジェクト: elliotchance/concise
 /**
  * Expected arguments when invoking the mock.
  *
  * @throws \Exception
  * @return MockBuilder
  */
 public function with()
 {
     $methodArguments = new MethodArguments();
     $this->currentWith = $methodArguments->getMethodArgumentValues(func_get_args(), $this->getClassName() . "::" . $this->currentRules[0]);
     foreach ($this->currentRules as $rule) {
         if ($this->rules[$rule][md5('null')]['hasSetTimes']) {
             $renderer = new ValueRenderer();
             $converter = new NumberToTimesConverter();
             $args = $renderer->renderAll($this->currentWith);
             $times = $this->rules[$rule][md5('null')]['times'];
             $convertToMethod = $converter->convertToMethod($times);
             throw new Exception(sprintf("%s:\n  ->expects('%s')->with(%s)->%s", "When using with you must specify expectations for each with()", $rule, $args, $convertToMethod));
         }
         $this->rules[$rule][md5('null')]['times'] = -1;
     }
     $this->setupWith(new Action\ReturnValueAction(array(null)), $this->isExpecting ? 1 : -1);
     return $this;
 }