pho\Console\Console::getReporterClass PHP Method

getReporterClass() public method

Returns the namespaced name of the reporter class requested via the command line arguments, defaulting to DotReporter if not specified.
public getReporterClass ( ) : string
return string The namespaced class name of the reporter
    public function getReporterClass()
    {
        $reporter = $this->options['reporter'];
        if ($reporter === false) {
            return self::DEFAULT_REPORTER;
        }
        $reporterClass = ucfirst($reporter) . 'Reporter';
        $reporterClass = "pho\\Reporter\\{$reporterClass}";
        try {
            $reflection = new ReflectionClass($reporterClass);
        } catch (ReflectionException $exception) {
            throw new ReporterNotFoundException($exception);
        }
        return $reflection->getName();
    }

Usage Example

Beispiel #1
0
         $console->parseArguments();
         expect($console->getPaths())->toEqual(['./']);
     });
 });
 context('getReporterClass', function () {
     it('returns DotReporter by default', function () {
         $console = new Console([], 'php://output');
         $console->parseArguments();
         $expectedClass = 'pho\\Reporter\\DotReporter';
         expect($console->getReporterClass())->toEqual($expectedClass);
     });
     it('returns a valid reporter specified in the args', function () {
         $console = new Console(['-r', 'spec'], 'php://output');
         $console->parseArguments();
         $expectedClass = 'pho\\Reporter\\SpecReporter';
         expect($console->getReporterClass())->toEqual($expectedClass);
     });
     context('when reporter not found', function () {
         before(function () {
             $this->console = new Console(['-r', 'unkown'], 'php://output');
             $this->console->parseArguments();
         });
         it('throw pho\\Exception\\ReporterNotFoundException exception', function () {
             expect(function () {
                 $this->console->getReporterClass();
             })->toThrow('pho\\Exception\\ReporterNotFoundException');
         });
     });
 });
 context('write', function () {
     it('prints the text to the terminal', function () {