public function testCreateReturnsMappedRendererInterface()
 {
     $resultClass = $this->createMock(ResultInterface::class);
     $resultClassName = get_class($resultClass);
     $rendererClassName = get_class($this->createMock(ResultRendererInterface::class));
     $factory = new ResultRendererFactory();
     $factory->registerRenderer($resultClassName, $rendererClassName);
     $returnedRenderer = $factory->create($resultClass);
     $this->assertInstanceOf($rendererClassName, $returnedRenderer);
 }
 public function testExceptionIsThrownIfFactoryReturnsInCorrectRenderer()
 {
     $resultClass = $this->createMock(ResultInterface::class);
     $resultClassName = get_class($resultClass);
     $rendererClassName = get_class($this->createMock(ResultRendererInterface::class));
     $factory = new ResultRendererFactory();
     $factory->registerRenderer($resultClassName, $rendererClassName, function () {
         return new \stdClass();
     });
     $this->expectException(RuntimeException::class);
     $factory->create($resultClass);
 }
Пример #3
0
 /**
  * @param ResultInterface $result
  * @return string
  */
 public function renderResult(ResultInterface $result)
 {
     return $this->resultRendererFactory->create($result)->render($this);
 }
Пример #4
0
}, FakerGenerator::class => function () {
    return FakerFactory::create();
}, RequestRenderer::class => object(), TerminalInterface::class => factory([TerminalFactory::class, 'fromSystem']), 'menu' => factory(MenuFactory::class), MenuFactory::class => object(), ExerciseRenderer::class => function (ContainerInterface $c) {
    return new ExerciseRenderer($c->get('appName'), $c->get(ExerciseRepository::class), $c->get(UserState::class), $c->get(UserStateSerializer::class), $c->get(MarkdownRenderer::class), $c->get(Color::class), $c->get(OutputInterface::class));
}, MarkdownRenderer::class => function (ContainerInterface $c) {
    $docParser = new DocParser(Environment::createCommonMarkEnvironment());
    $cliRenderer = (new MarkdownCliRendererFactory())->__invoke($c);
    return new MarkdownRenderer($docParser, $cliRenderer);
}, UserStateSerializer::class => function (ContainerInterface $c) {
    return new UserStateSerializer(getenv('HOME'), $c->get('workshopTitle'), $c->get(ExerciseRepository::class));
}, UserState::class => function (ContainerInterface $c) {
    return $c->get(UserStateSerializer::class)->deSerialize();
}, SyntaxHighlighter::class => factory(PsxFactory::class), PsxFactory::class => object(), ResetProgress::class => function (ContainerInterface $c) {
    return new ResetProgress($c->get(UserStateSerializer::class));
}, ResultRendererFactory::class => function (ContainerInterface $c) {
    $factory = new ResultRendererFactory();
    $factory->registerRenderer(FunctionRequirementsFailure::class, FunctionRequirementsFailureRenderer::class);
    $factory->registerRenderer(Failure::class, FailureRenderer::class);
    $factory->registerRenderer(CgiResult::class, CgiResultRenderer::class, function (CgiResult $result) use($c) {
        return new CgiResultRenderer($result, $c->get(RequestRenderer::class));
    });
    $factory->registerRenderer(CgiGenericFailure::class, FailureRenderer::class);
    $factory->registerRenderer(CgiRequestFailure::class, CgiRequestFailureRenderer::class);
    $factory->registerRenderer(CliResult::class, CliResultRenderer::class);
    $factory->registerRenderer(CliGenericFailure::class, FailureRenderer::class);
    $factory->registerRenderer(CliRequestFailure::class, CliRequestFailureRenderer::class);
    $factory->registerRenderer(ComparisonFailure::class, ComparisonFailureRenderer::class);
    return $factory;
}, ResultsRenderer::class => function (ContainerInterface $c) {
    return new ResultsRenderer($c->get('appName'), $c->get(Color::class), $c->get(TerminalInterface::class), $c->get(ExerciseRepository::class), $c->get(SyntaxHighlighter::class), $c->get(ResultRendererFactory::class));
}, 'coreContributors' => ['@AydinHassan' => 'Aydin Hassan', '@mikeymike' => 'Michael Woodward', '@shakeyShane' => 'Shane Osbourne', '@chris3ailey' => 'Chris Bailey'], 'appContributors' => [], 'eventListeners' => ['realpath-student-submission' => ['verify.start' => [containerListener(RealPathListener::class)], 'run.start' => [containerListener(RealPathListener::class)]], 'check-exercise-assigned' => ['route.pre.resolve.args' => [containerListener(CheckExerciseAssignedListener::class)]], 'configure-command-arguments' => ['route.pre.resolve.args' => [containerListener(ConfigureCommandListener::class)]], 'prepare-solution' => ['cli.verify.start' => [containerListener(PrepareSolutionListener::class)], 'cli.run.start' => [containerListener(PrepareSolutionListener::class)], 'cgi.verify.start' => [containerListener(PrepareSolutionListener::class)], 'cgi.run.start' => [containerListener(PrepareSolutionListener::class)]], 'code-patcher' => ['cli.verify.start' => [containerListener(CodePatchListener::class, 'patch')], 'cli.verify.finish' => [containerListener(CodePatchListener::class, 'revert')], 'cli.run.start' => [containerListener(CodePatchListener::class, 'patch')], 'cli.run.finish' => [containerListener(CodePatchListener::class, 'revert')], 'cgi.verify.start' => [containerListener(CodePatchListener::class, 'patch')], 'cgi.verify.finish' => [containerListener(CodePatchListener::class, 'revert')], 'cgi.run.start' => [containerListener(CodePatchListener::class, 'patch')], 'cgi.run.finish' => [containerListener(CodePatchListener::class, 'revert')]], 'self-check' => ['verify.post.check' => [containerListener(SelfCheckListener::class)]]]];
 public function testRenderAllFailures()
 {
     $color = new Color();
     $color->setForceStyle(true);
     $resultRendererFactory = new ResultRendererFactory();
     $resultRendererFactory->registerRenderer(Failure::class, FailureRenderer::class, function (Failure $failure) {
         $renderer = $this->prophesize(FailureRenderer::class);
         $renderer->render(Argument::type(ResultsRenderer::class))->willReturn($failure->getReason() . "\n");
         return $renderer->reveal();
     });
     $terminal = $this->prophesize(TerminalInterface::class);
     $terminal->getWidth()->willReturn(100);
     $terminal = $terminal->reveal();
     $exerciseRepo = $this->prophesize(ExerciseRepository::class);
     $exerciseRepo->count()->willReturn(2);
     $renderer = new ResultsRenderer('app', $color, $terminal, $exerciseRepo->reveal(), (new Factory())->__invoke(), $resultRendererFactory);
     $resultSet = new ResultAggregator();
     $resultSet->add(new Failure('Failure 1', 'Failure 1'));
     $resultSet->add(new Failure('Failure 2', 'Failure 2'));
     $this->expectOutputString($this->getExpectedOutput());
     $renderer->render($resultSet, $this->createMock(ExerciseInterface::class), new UserState(), new StdOutput($color, $terminal));
 }