src/Application/ConsoleApplication.php
/**
     * Runs the console application.
     *
     * @since 1.0.0
     *
     * @return int The result code.
     */
Runs the console application.

@return int The result code.
Runs the console application . @return int The result code .
public function run(): int
    {
        echo 'Webunit v' . self::WEBUNIT_VERSION . PHP_EOL;
        $parseContext = new ParseContext();
        if (!$this->parseCommandLineParameters($this->commandLineParameters, $parseContext, $testfilePath, $error)) {
            self::fail($error);
            echo 'Usage: webunit [options] testfile' . PHP_EOL;
            return self::RESULT_PARAMETER_ERROR;
        }
        $content = $this->tryReadContent($testfilePath);
        if ($content === null) {
            return self::RESULT_READ_TEST_FILE_ERROR;
        }
        $parser = new Parser();
        $parseResult = $parser->parse($testfilePath, $content, $parseContext);
        if (!$parseResult->isSuccess()) {
            foreach ($parseResult->getParseErrors() as $parseError) {
                echo $parseError . PHP_EOL;
            }
            self::fail('Parsing failed.');
            return self::RESULT_PARSE_TEST_FILE_ERROR;
        }
        $testSuite = $parseResult->getTestSuite();
        if (count($testSuite->getTestCases()) === 0) {
            self::warn('No tests found.');
            return self::RESULT_NO_TESTS_FOUND;
        }
        $currentProgressBarLength = 0;
        $showProgressBarFunction = function (AssertResultInterface $assertResult) use (&$currentProgressBarLength): void {
            if ($currentProgressBarLength === self::PROGRESS_BAR_MAX_LENGTH_PER_LINE) {
                echo PHP_EOL;
                $currentProgressBarLength = 0;
            }
            echo $assertResult->isSuccess() ? '.' : "\033[41m\033[1;37mF\033[0m";
            $currentProgressBarLength++;
        };
        $testResults = $testSuite->run($this->httpClient, $showProgressBarFunction);
        echo PHP_EOL;
        $this->printReport($testResults);
        return $testResults->isSuccess() ? self::RESULT_OK : self::RESULT_TESTS_FAILED;
    }
public function run ( ) : int { echo 'Webunit v' . self :: WEBUNIT_VERSION . PHP_EOL ; $ parseContext = new ParseContext ( ) ; if ( ! $ this -> parseCommandLineParameters ( $ this -> commandLineParameters , $ parseContext , $ testfilePath , $ error ) ) { self :: fail ( $ error ) ; echo 'Usage: webunit [options] testfile' . PHP_EOL ; return self :: RESULT_PARAMETER_ERROR ; } $ content = $ this -> tryReadContent ( $ testfilePath ) ; if ( $ content === null ) { return self :: RESULT_READ_TEST_FILE_ERROR ; } $ parser = new Parser ( ) ; $ parseResult = $ parser -> parse ( $ testfilePath , $ content , $ parseContext ) ; if ( ! $ parseResult -> isSuccess ( ) ) { foreach ( $ parseResult -> getParseErrors ( ) as $ parseError ) { echo $ parseError . PHP_EOL ; } self :: fail ( 'Parsing failed.' ) ; return self :: RESULT_PARSE_TEST_FILE_ERROR ; } $ testSuite = $ parseResult -> getTestSuite ( ) ; if ( count ( $ testSuite -> getTestCases ( ) ) === 0 ) { self :: warn ( 'No tests found.' ) ; return self :: RESULT_NO_TESTS_FOUND ; } $ currentProgressBarLength = 0 ; $ showProgressBarFunction = function ( AssertResultInterface $ assertResult ) use ( & $ currentProgressBarLength ) : void { if ( $ currentProgressBarLength === self :: PROGRESS_BAR_MAX_LENGTH_PER_LINE ) { echo PHP_EOL ; $ currentProgressBarLength = 0 ; } echo $ assertResult -> isSuccess ( ) ? '.' : " \033 [41m \033 [1;37mF \033 [0m " ; $ currentProgressBarLength ++ ; } ; $ testResults = $ testSuite -> run ( $ this -> httpClient , $ showProgressBarFunction ) ; echo PHP_EOL ; $ this -> printReport ( $ testResults ) ; return $ testResults -> isSuccess ( ) ? self :: RESULT_OK : self :: RESULT_TESTS_FAILED ; }
Runs the console application.
Runs the console application .