├── .editorconfig ├── .github ├── FUNDING.yml └── workflows │ ├── continuous-deployment.yml │ ├── continuous-integration.yml │ ├── csfix.yml │ └── php-linter.yml ├── .gitignore ├── .php_cs ├── LICENSE ├── README.md ├── composer.json ├── cs2pr └── tests ├── errors ├── errors-as-warnings.expect ├── minimal.expect ├── minimal.xml ├── mixed-case.expect ├── mixed-case.xml ├── mixed-colors.expect ├── mixed-source-attributes.expect ├── mixed-source-attributes.xml ├── mixed.expect ├── mixed.xml ├── notices-as-warnings.expect ├── notices.expect ├── notices.xml ├── prepend-filename.expect ├── prepend-filename.xml ├── warning-only.expect └── warning-only.xml ├── fail ├── empty.xml ├── invalid.xml └── multiple-suites.xml ├── noerrors ├── only-header-php-cs-fixer.expect ├── only-header-php-cs-fixer.xml ├── only-header.expect └── only-header.xml └── tests.php /.editorconfig: -------------------------------------------------------------------------------- 1 | ; top-most EditorConfig file 2 | root = true 3 | 4 | ; Unix-style newlines 5 | [*] 6 | charset = utf-8 7 | end_of_line = LF 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | indent_style = space 11 | indent_size = 4 12 | 13 | [*.expect] 14 | insert_final_newline = false; 15 | 16 | [*.md] 17 | max_line_length = 80 18 | 19 | [COMMIT_EDITMSG] 20 | max_line_length = 0 21 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [staabm] 2 | -------------------------------------------------------------------------------- /.github/workflows/continuous-deployment.yml: -------------------------------------------------------------------------------- 1 | # https://help.github.com/en/categories/automating-your-workflow-with-github-actions 2 | 3 | name: "Continuous Deployment" 4 | 5 | on: 6 | release: 7 | types: 8 | - published 9 | 10 | jobs: 11 | release: 12 | name: "Release" 13 | 14 | runs-on: "ubuntu-latest" 15 | 16 | steps: 17 | - name: "Checkout" 18 | uses: "actions/checkout@v2" 19 | 20 | - name: "Get upload_url" 21 | run: echo "::set-output name=upload_url::https://uploads.github.com/repos/$GITHUB_REPOSITORY/releases/$(jq --raw-output '.release.id' $GITHUB_EVENT_PATH)/assets{?name,label}" 22 | id: release 23 | 24 | - name: "Upload cs2pr" 25 | uses: "actions/upload-release-asset@v1" 26 | env: 27 | GITHUB_TOKEN: ${{ secrets.STAABM_TOKEN }} 28 | with: 29 | asset_content_type: "text/plain" 30 | asset_name: "cs2pr" 31 | asset_path: "cs2pr" 32 | upload_url: ${{ steps.release.outputs.upload_url }} 33 | -------------------------------------------------------------------------------- /.github/workflows/continuous-integration.yml: -------------------------------------------------------------------------------- 1 | # https://help.github.com/en/categories/automating-your-workflow-with-github-actions 2 | 3 | name: "Continuous Integration" 4 | 5 | on: 6 | pull_request: 7 | push: 8 | branches: 9 | - "master" 10 | 11 | jobs: 12 | coding-standards: 13 | name: "Coding Standards" 14 | 15 | runs-on: "ubuntu-latest" 16 | 17 | steps: 18 | - name: "Checkout" 19 | uses: "actions/checkout@v2" 20 | 21 | - name: "Install PHP with extensions" 22 | uses: "shivammathur/setup-php@v2" 23 | with: 24 | coverage: "none" 25 | extensions: "simplexml" 26 | php-version: "7.0" 27 | tools: "cs2pr" 28 | 29 | - name: "Install dependencies with composer" 30 | run: "composer install --no-interaction --no-progress --no-suggest" 31 | 32 | - name: "Run friendsofphp/php-cs-fixer" 33 | run: "vendor/bin/php-cs-fixer fix --config=.php_cs --diff --dry-run --format=checkstyle | cs2pr" 34 | 35 | tests: 36 | name: "Tests" 37 | 38 | runs-on: "ubuntu-latest" 39 | 40 | strategy: 41 | matrix: 42 | php-version: 43 | - "5.3" 44 | - "7.0" 45 | - "7.1" 46 | - "7.2" 47 | - "7.3" 48 | - "7.4" 49 | - "8.0" 50 | - "8.1" 51 | - "8.2" 52 | - "8.3" 53 | - "8.4" 54 | 55 | steps: 56 | - name: "Checkout" 57 | uses: "actions/checkout@v2" 58 | 59 | - name: "Install PHP with extensions" 60 | uses: "shivammathur/setup-php@v2" 61 | with: 62 | coverage: "none" 63 | extensions: "simplexml" 64 | php-version: "${{ matrix.php-version }}" 65 | 66 | - run: php tests/tests.php 67 | -------------------------------------------------------------------------------- /.github/workflows/csfix.yml: -------------------------------------------------------------------------------- 1 | name: Auto Format PHP 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '**.php' 7 | - 'cs2pr' 8 | 9 | jobs: 10 | php-cs-fixer: 11 | runs-on: ubuntu-latest 12 | # dont run on forks. requires commit access 13 | if: github.event.pull_request.head.repo.full_name == github.repository 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | with: 18 | ref: ${{ github.head_ref }} 19 | 20 | - name: Setup PHP 21 | uses: shivammathur/setup-php@v2 22 | with: 23 | php-version: 7.0 24 | coverage: none # disable xdebug, pcov 25 | tools: cs2pr 26 | 27 | - name: "Install dependencies with composer" 28 | run: "composer install --no-interaction --no-progress --no-suggest" 29 | 30 | - name: "Run friendsofphp/php-cs-fixer" 31 | run: "vendor/bin/php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --verbose" 32 | 33 | - uses: stefanzweifel/git-auto-commit-action@v2.5.0 34 | with: 35 | commit_message: Apply php-cs-fixer changes 36 | branch: ${{ github.head_ref }} 37 | env: 38 | GITHUB_TOKEN: ${{ secrets.STAABM_TOKEN }} 39 | 40 | - run: vendor/bin/php-cs-fixer fix --diff --dry-run --format=checkstyle | cs2pr # check whether there are still errors left 41 | -------------------------------------------------------------------------------- /.github/workflows/php-linter.yml: -------------------------------------------------------------------------------- 1 | name: PHP Linter 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | types: [opened, synchronize, reopened, ready_for_review] 9 | 10 | jobs: 11 | php-linter: 12 | runs-on: ubuntu-latest 13 | if: github.event.pull_request.draft == false 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | with: 18 | repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} 19 | ref: ${{ github.event.client_payload.pull_request.head.ref }} 20 | 21 | - name: Setup PHP 22 | uses: shivammathur/setup-php@v2 23 | with: 24 | php-version: 7.4 25 | coverage: none # disable xdebug, pcov 26 | 27 | - run: composer require --dev php-parallel-lint/php-parallel-lint 28 | 29 | - name: Lint PHP 30 | run: vendor/bin/parallel-lint cs2pr tests/ 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | .php_cs.cache 3 | composer.lock 4 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | 9 | 10 | For the full copyright and license information, please view the LICENSE 11 | file that was distributed with this source code. 12 | 13 | https://github.com/staabm/annotate-pull-request-from-checkstyle 14 | EOF; 15 | 16 | $finder = PhpCsFixer\Finder::create() 17 | ->files() 18 | ->in(__DIR__) 19 | ->name('cs2pr'); 20 | 21 | return PhpCsFixer\Config::create() 22 | ->setFinder($finder) 23 | ->setRules([ 24 | '@PSR2' => true, 25 | 'header_comment' => [ 26 | 'commentType' => 'comment', 27 | 'header' => $header, 28 | 'location' => 'after_declare_strict', 29 | 'separate' => 'both', 30 | ] 31 | ]); 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Markus Staab 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Annotate a Pull Request based on a Checkstyle XML-report 2 | 3 | [![Continuous Integration](https://github.com/staabm/annotate-pull-request-from-checkstyle/workflows/Continuous%20Integration/badge.svg)](https://github.com/staabm/annotate-pull-request-from-checkstyle/actions) 4 | [![Continuous Deployment](https://github.com/staabm/annotate-pull-request-from-checkstyle/workflows/Continuous%20Deployment/badge.svg)](https://github.com/staabm/annotate-pull-request-from-checkstyle/actions) 5 | 6 | Turns [checkstyle based XML-Reports](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.0.2/doc/schemas/fix/checkstyle.xsd) into GitHub Pull Request [Annotations via the Checks API](https://docs.github.com/en/free-pro-team@latest/rest/reference/checks). 7 | This script is meant for use within your GitHub Action. 8 | 9 | That means you no longer search thru your GitHub Action logfiles. 10 | No need to interpret messages which are formatted differently with every tool. 11 | Instead you can focus on your Pull Request, and you don't need to leave the Pull Request area. 12 | 13 | ![Logs Example](https://github.com/mheap/phpunit-github-actions-printer/blob/master/phpunit-printer-logs.png?raw=true) 14 | 15 | ![Context Example](https://github.com/mheap/phpunit-github-actions-printer/blob/master/phpunit-printer-context.png?raw=true) 16 | _Images from https://github.com/mheap/phpunit-github-actions-printer_ 17 | 18 | [DEMO - See how Pull Request warnings/errors are rendered in action](https://github.com/staabm/gh-annotation-example/pull/1/files) 19 | 20 | # Installation 21 | 22 | Install the binary via composer 23 | ```bash 24 | composer require staabm/annotate-pull-request-from-checkstyle --dev 25 | ``` 26 | 27 | ## 💌 Give back some love 28 | 29 | [Consider supporting the project](https://github.com/sponsors/staabm), so we can make this tool even better even faster for everyone. 30 | 31 | 32 | # Example Usage 33 | 34 | `cs2pr` can be used on a already existing checkstyle-report xml-file. Alternatively you might use it in the unix-pipe notation to chain it into your existing cli command. 35 | 36 | Run one of the following commands within your GitHub Action workflow: 37 | 38 | ## Process a checkstyle formatted file 39 | 40 | ```bash 41 | cs2pr /path/to/checkstyle-report.xml 42 | ``` 43 | 44 | ### Available Options 45 | 46 | - `--graceful-warnings`: Don't exit with error codes if there are only warnings 47 | - `--colorize`: Colorize the output. Useful if the same lint script should be used locally on the command line and remote on GitHub Actions. With this option, errors and warnings are better distinguishable on the command line and the output is still compatible with GitHub Annotations 48 | - `--notices-as-warnings` Converts notices to warnings. This can be useful because GitHub does not annotate notices. 49 | - `--prepend-filename` Prepend the filename to the output message 50 | - `--prepend-source` When the checkstyle generating tool provides a `source` attribute, prepend the source to the output message. 51 | 52 | 53 | ## Pipe the output of another commmand 54 | 55 | ... works for __any__ command which produces a checkstyle-formatted report. 56 | 57 | Examples can bee seen below: 58 | 59 | ### Using [PHPStan](https://github.com/phpstan/phpstan) 60 | 61 | ```bash 62 | phpstan analyse --error-format=checkstyle | cs2pr 63 | ``` 64 | 65 | _Phpstan 0.12.32 introduced native github actions support, therefore you might use this instead:_ 66 | 67 | ```bash 68 | phpstan analyse 69 | ``` 70 | 71 | ### Using [Psalm](https://github.com/vimeo/psalm) 72 | 73 | ```bash 74 | psalm --output-format=checkstyle | cs2pr 75 | ``` 76 | 77 | _Psalm even supports the required format natively, therefore you might use this instead:_ 78 | 79 | ```bash 80 | psalm --output-format=github 81 | ``` 82 | 83 | ### Using [PHP Coding Standards Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) 84 | 85 | ```bash 86 | php-cs-fixer fix --dry-run --format=checkstyle | cs2pr 87 | ``` 88 | 89 | ### Using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) 90 | 91 | ```bash 92 | phpcs --report=checkstyle -q /path/to/code | cs2pr 93 | ``` 94 | 95 | 96 | Note: the `-q` option means that no output will be shown in the action logs anymore. 97 | To see the output both in the PR as well as in the action logs, use two steps, like so: 98 | 99 | ```yaml 100 | - name: Check PHP code style 101 | id: phpcs 102 | run: phpcs --report-full --report-checkstyle=./phpcs-report.xml 103 | 104 | - name: Show PHPCS results in PR 105 | if: ${{ always() && steps.phpcs.outcome == 'failure' }} 106 | run: cs2pr ./phpcs-report.xml 107 | ``` 108 | 109 | ### Using [PHP Parallel Lint](https://github.com/php-parallel-lint/PHP-Parallel-Lint/) 110 | 111 | ```bash 112 | vendor/bin/parallel-lint . --exclude vendor --checkstyle | cs2pr 113 | ``` 114 | 115 | ### Using [Laravel Pint](https://github.com/laravel/pint) 116 | 117 | ```yaml 118 | - name: Show Pint results in PR 119 | run: pint --test --format=checkstyle | cs2pr 120 | ``` 121 | 122 | Note: if you want to have both logs and annotations you need to run `pint` twice: 123 | 124 | ```yaml 125 | - name: Check PHP code style 126 | id: cs-check 127 | run: pint --test 128 | 129 | - name: Generate Annotations on CS errors 130 | if: failure() && steps.cs-check.outcome != 'success' 131 | run: pint --test --format=checkstyle | cs2pr 132 | ``` 133 | 134 | ## phpunit support? 135 | 136 | PHPUnit does not support checkstyle, therefore `cs2pr` will not work for you. 137 | 138 | you might instead try 139 | - a [phpunit problem matcher](https://github.com/shivammathur/setup-php#problem-matchers) 140 | - a [phpunit-github-actions-printer](https://github.com/mheap/phpunit-github-actions-printer) 141 | 142 | ## Example GithubAction workflow 143 | 144 | 145 | If you're using `shivammathur/setup-php` to setup PHP, `cs2pr` binary is shipped within: 146 | 147 | ```yml 148 | # ... 149 | jobs: 150 | phpstan-analysis: 151 | name: phpstan static code analysis 152 | runs-on: ubuntu-latest 153 | steps: 154 | - uses: actions/checkout@v2 155 | - name: Setup PHP 156 | uses: shivammathur/setup-php@v1 157 | with: 158 | php-version: 7.3 159 | coverage: none # disable xdebug, pcov 160 | tools: cs2pr 161 | - run: | 162 | composer install # install your apps dependencies 163 | vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr 164 | ``` 165 | 166 | If you use a custom PHP installation, then your project needs to require `staabm/annotate-pull-request-from-checkstyle` 167 | 168 | ```yml 169 | # ... 170 | jobs: 171 | phpstan-analysis: 172 | name: phpstan static code analysis 173 | runs-on: ubuntu-latest 174 | steps: 175 | - uses: actions/checkout@v2 176 | - name: Setup PHP 177 | run: # custom PHP installation 178 | - run: | 179 | composer install # install your apps dependencies 180 | composer require staabm/annotate-pull-request-from-checkstyle # install cs2pr 181 | vendor/bin/phpstan analyse --error-format=checkstyle | vendor/bin/cs2pr 182 | ``` 183 | 184 | ## Using cs2pr as a GitHub Action 185 | 186 | You can also use [`cs2pr` itself as a GitHub Action](https://github.com/staabm/annotate-pull-request-from-checkstyle-action). This is useful if you want to for instance use it for a project that does not use PHP or if you want to use it with a custom PHP installation. 187 | 188 | See the example at the [cs2pr GitHub Action repositiory](https://github.com/staabm/annotate-pull-request-from-checkstyle-action#readme). 189 | 190 | 191 | 192 | # Resources 193 | 194 | [GithubAction Problem Matchers](https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md) 195 | 196 | # Idea 197 | 198 | This script is based on a suggestion of [Benjamin Eberlei](https://twitter.com/beberlei/status/1218970454557372416) 199 | 200 | The Code is inspired by https://github.com/mheap/phpunit-github-actions-printer 201 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "staabm/annotate-pull-request-from-checkstyle", 3 | "license" : "MIT", 4 | "keywords": ["dev", "continous integration", "github actions"], 5 | "require" : { 6 | "php" : "^5.3 || ^7.0 || ^8.0", 7 | "ext-libxml" : "*", 8 | "ext-simplexml" : "*" 9 | }, 10 | "require-dev" : { 11 | "friendsofphp/php-cs-fixer": "^2.16.1" 12 | }, 13 | "authors" : [ 14 | { 15 | "name" : "Markus Staab" 16 | } 17 | ], 18 | "bin" : ["cs2pr"], 19 | "scripts": { 20 | "cs": "php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --verbose" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cs2pr: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | * 12 | * https://github.com/staabm/annotate-pull-request-from-checkstyle 13 | */ 14 | 15 | error_reporting(E_ALL); 16 | ini_set('display_errors', 'stderr'); 17 | gc_disable(); 18 | 19 | $version = '1.8.6-dev'; 20 | 21 | // options 22 | $colorize = false; 23 | $gracefulWarnings = false; 24 | $noticeAsWarning = false; 25 | $prependFilename = false; 26 | $prependSource = false; 27 | $errorsAsWarnings = false; 28 | 29 | // parameters 30 | $params = array(); 31 | foreach ($argv as $arg) { 32 | if (substr($arg, 0, 2) === '--') { 33 | $option = substr($arg, 2); 34 | switch ($option) { 35 | case 'graceful-warnings': 36 | $gracefulWarnings = true; 37 | break; 38 | case 'colorize': 39 | $colorize = true; 40 | break; 41 | case 'prepend-filename': 42 | $prependFilename = true; 43 | break; 44 | case 'prepend-source': 45 | $prependSource = true; 46 | break; 47 | case 'notices-as-warnings': 48 | $noticeAsWarning = true; 49 | break; 50 | case 'errors-as-warnings': 51 | $errorsAsWarnings = true; 52 | break; 53 | default: 54 | echo "Unknown option ".$option."\n"; 55 | exit(9); 56 | } 57 | } else { 58 | $params[] = $arg; 59 | } 60 | } 61 | 62 | if (count($params) === 1) { 63 | $xml = stream_get_contents(STDIN); 64 | } elseif (count($params) === 2 && file_exists($params[1])) { 65 | $xml = file_get_contents($params[1]); 66 | } else { 67 | echo "cs2pr $version\n"; 68 | echo "Annotate a Github Pull Request based on a Checkstyle XML-report.\n"; 69 | echo "https://github.com/staabm/annotate-pull-request-from-checkstyle\n\n"; 70 | echo "Usage: ". $params[0] ." [OPTION]... \n"; 71 | echo "\n"; 72 | echo "Supported options:\n"; 73 | echo " --graceful-warnings Don't exit with error codes if there are only warnings.\n"; 74 | echo " --colorize Colorize the output (still compatible with Github Annotations)\n"; 75 | echo " --notices-as-warnings Convert notices to warnings (Github does not annotate notices otherwise).\n"; 76 | echo " --errors-as-warnings Downgrade errors to warnings.\n"; 77 | echo " --prepend-filename Prepend error 'filename' attribute to the message.\n"; 78 | echo " --prepend-source Prepend error 'source' attribute to the message.\n"; 79 | exit(9); 80 | } 81 | 82 | // enable user error handling 83 | libxml_use_internal_errors(true); 84 | 85 | $root = @simplexml_load_string($xml); 86 | 87 | if ($root === false) { 88 | $errors = libxml_get_errors(); 89 | if ($errors) { 90 | fwrite(STDERR, 'Error: '. rtrim($errors[0]->message).' on line '.$errors[0]->line.', column '.$errors[0]->column ."\n\n"); 91 | } elseif (stripos($xml, ' 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/errors/mixed-case.expect: -------------------------------------------------------------------------------- 1 | ::error file=redaxo\src\addons\2factor_auth\boot.php,line=6::Call to static method getInstance() on an unknown class rex_one_time_password. 2 | ::error file=redaxo\src\addons\2factor_auth\boot.php,line=9::Call to static method getInstance() on an unknown class rex_minibar. 3 | ::error file=redaxo\src\addons\2factor_auth\lib\one_time_password.php,line=0::Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly. -------------------------------------------------------------------------------- /tests/errors/mixed-case.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/errors/mixed-colors.expect: -------------------------------------------------------------------------------- 1 |  2 | ::error file=redaxo\src\addons\2factor_auth\boot.php,line=6::Call to static method getInstance() on an unknown class rex_one_time_password. 3 |  4 | ::warning file=redaxo\src\addons\2factor_auth\boot.php,line=9::Call to static method getInstance() on an unknown class rex_minibar. 5 |  6 | ::error file=redaxo\src\addons\2factor_auth\lib\one_time_password.php,line=0::Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly. 7 |  -------------------------------------------------------------------------------- /tests/errors/mixed-source-attributes.expect: -------------------------------------------------------------------------------- 1 | ::error file=test/phpunit/Traits/BuildingPermissionIdAwareTraitTest.php,line=13::PhanUndeclaredMethod: Call to undeclared method \PHPUnit\Framework\MockObject\MockObject::getPermissionIds 2 | ::warning file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=12::PhanUndeclaredClassReference: Reference to undeclared class \CIDRmatch\CIDRmatch 3 | ::warning file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=21::PhanTypeMismatchArgument: Argument 2 ($CIDRmatch) is $cidr of type \PHPUnit\Framework\MockObject\MockObject|\PHPUnit_Framework_MockObject_MockObject but \Utils\Cidr\MultiCidrMatch::__construct() takes \CIDRmatch\CIDRmatch defined at application/classes/Utils/Cidr/MultiCidrMatch.php:20 4 | ::warning file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=28::PhanUndeclaredClassReference: Reference to undeclared class \CIDRmatch\CIDRmatch 5 | ::warning file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=38::PhanTypeMismatchArgument: Argument 2 ($CIDRmatch) is $cidr of type \PHPUnit\Framework\MockObject\MockObject|\PHPUnit_Framework_MockObject_MockObject but \Utils\Cidr\MultiCidrMatch::__construct() takes \CIDRmatch\CIDRmatch defined at application/classes/Utils/Cidr/MultiCidrMatch.php:20 6 | ::error file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=54::Call to undeclared method \PHPUnit\Framework\MockObject\MockObject::matchAny 7 | ::error file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=69::Call to undeclared method \PHPUnit\Framework\MockObject\MockObject::matchAny -------------------------------------------------------------------------------- /tests/errors/mixed-source-attributes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/errors/mixed.expect: -------------------------------------------------------------------------------- 1 | ::error file=redaxo\src\addons\2factor_auth\boot.php,line=6::Call to static method getInstance() on an unknown class rex_one_time_password. 2 | ::warning file=redaxo\src\addons\2factor_auth\boot.php,line=9::Call to static method getInstance() on an unknown class rex_minibar. 3 | ::error file=redaxo\src\addons\2factor_auth\lib\one_time_password.php,line=0::Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly. -------------------------------------------------------------------------------- /tests/errors/mixed.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/errors/notices-as-warnings.expect: -------------------------------------------------------------------------------- 1 | ::warning file=redaxo\src\addons\2factor_auth\boot.php,line=6::Call to static method getInstance() on an unknown class rex_one_time_password. 2 | ::warning file=redaxo\src\addons\2factor_auth\boot.php,line=9::Call to static method getInstance() on an unknown class rex_minibar. 3 | ::warning file=redaxo\src\addons\2factor_auth\lib\one_time_password.php,line=0::Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly. -------------------------------------------------------------------------------- /tests/errors/notices.expect: -------------------------------------------------------------------------------- 1 | ::notice file=redaxo\src\addons\2factor_auth\boot.php,line=6::Call to static method getInstance() on an unknown class rex_one_time_password. 2 | ::notice file=redaxo\src\addons\2factor_auth\boot.php,line=9::Call to static method getInstance() on an unknown class rex_minibar. 3 | ::notice file=redaxo\src\addons\2factor_auth\lib\one_time_password.php,line=0::Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly. -------------------------------------------------------------------------------- /tests/errors/notices.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/errors/prepend-filename.expect: -------------------------------------------------------------------------------- 1 | ::error file=redaxo\src\addons\2factor_auth\boot.php,line=6::boot.php: Call to static method getInstance() on an unknown class rex_one_time_password. 2 | ::error file=redaxo\src\addons\2factor_auth\boot.php,line=9::boot.php: Call to static method getInstance() on an unknown class rex_minibar. 3 | ::error file=redaxo\src\addons\2factor_auth\lib\one_time_password.php,line=0::one_time_password.php: Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly. 4 | ::error file=redaxo/src/addons/2factor_auth/lib/linux_filepath.php,line=0::linux_filepath.php: Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly. -------------------------------------------------------------------------------- /tests/errors/prepend-filename.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/errors/warning-only.expect: -------------------------------------------------------------------------------- 1 | ::warning file=redaxo/src/addons/2factor_auth/boot.php,line=6::Call to static method getInstance() on an unknown class rex_one_time_password. 2 | ::warning file=redaxo/src/addons/2factor_auth/boot.php,line=9::Call to static method getInstance() on an unknown class rex_minibar. 3 | ::warning file=redaxo/src/addons/2factor_auth/lib/one_time_password.php,line=0::Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly. -------------------------------------------------------------------------------- /tests/errors/warning-only.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/fail/empty.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staabm/annotate-pull-request-from-checkstyle/609c91940ed6b0dacfae6011291867c32c36e30a/tests/fail/empty.xml -------------------------------------------------------------------------------- /tests/fail/invalid.xml: -------------------------------------------------------------------------------- 1 | hello world -------------------------------------------------------------------------------- /tests/fail/multiple-suites.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/noerrors/only-header-php-cs-fixer.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staabm/annotate-pull-request-from-checkstyle/609c91940ed6b0dacfae6011291867c32c36e30a/tests/noerrors/only-header-php-cs-fixer.expect -------------------------------------------------------------------------------- /tests/noerrors/only-header-php-cs-fixer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/noerrors/only-header.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staabm/annotate-pull-request-from-checkstyle/609c91940ed6b0dacfae6011291867c32c36e30a/tests/noerrors/only-header.expect -------------------------------------------------------------------------------- /tests/noerrors/only-header.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/tests.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | * 11 | * https://github.com/staabm/annotate-pull-request-from-checkstyle 12 | */ 13 | 14 | function testXml($xmlPath, $expectedExit, $expectedOutput = null, $options = '') 15 | { 16 | exec('cat '.$xmlPath .' | php '. __DIR__ .'/../cs2pr '.$options.' 2>&1', $output, $exit); 17 | $output = implode("\n", $output); 18 | 19 | if ($exit != $expectedExit) { 20 | var_dump($output); 21 | 22 | throw new Exception('Test with ' . $xmlPath . ' failed, expected exit-code ' . $expectedExit . ' got ' . $exit); 23 | } elseif ($expectedOutput && $expectedOutput != $output) { 24 | echo "EXPECTED:\n"; 25 | var_dump($expectedOutput); 26 | echo "\n"; 27 | 28 | echo "GOT:\n"; 29 | var_dump($output); 30 | echo "\n"; 31 | 32 | throw new Exception('Test with ' . $xmlPath . ' failed, output mismatch'); 33 | } else { 34 | echo "success: $xmlPath\n\n"; 35 | } 36 | } 37 | 38 | 39 | testXml(__DIR__.'/fail/empty.xml', 2, "Error: Expecting xml stream starting with a xml opening tag.\n"); 40 | testXml(__DIR__.'/fail/invalid.xml', 2, "Error: Start tag expected, '<' not found on line 1, column 1\n\n" .file_get_contents(__DIR__.'/fail/invalid.xml')); 41 | 42 | testXml(__DIR__.'/fail/multiple-suites.xml', 2, "Error: Extra content at the end of the document on line 8, column 1\n\n" .file_get_contents(__DIR__.'/fail/multiple-suites.xml')); 43 | 44 | testXml(__DIR__.'/errors/minimal.xml', 1, file_get_contents(__DIR__.'/errors/minimal.expect')); 45 | testXml(__DIR__.'/errors/mixed.xml', 1, file_get_contents(__DIR__.'/errors/mixed.expect')); 46 | testXml(__DIR__.'/errors/warning-only.xml', 1, file_get_contents(__DIR__.'/errors/warning-only.expect')); 47 | 48 | testXml(__DIR__.'/errors/minimal.xml', 1, file_get_contents(__DIR__.'/errors/minimal.expect'), '--graceful-warnings'); 49 | testXml(__DIR__.'/errors/mixed.xml', 1, file_get_contents(__DIR__.'/errors/mixed.expect'), '--graceful-warnings'); 50 | testXml(__DIR__.'/errors/warning-only.xml', 0, file_get_contents(__DIR__.'/errors/warning-only.expect'), '--graceful-warnings'); 51 | 52 | testXml(__DIR__.'/errors/notices.xml', 1, file_get_contents(__DIR__.'/errors/notices.expect')); 53 | testXml(__DIR__.'/errors/notices.xml', 1, file_get_contents(__DIR__.'/errors/notices-as-warnings.expect'), '--notices-as-warnings'); 54 | 55 | testXml(__DIR__.'/errors/prepend-filename.xml', 1, file_get_contents(__DIR__.'/errors/prepend-filename.expect'), '--prepend-filename'); 56 | testXml(__DIR__.'/errors/mixed-source-attributes.xml', 1, file_get_contents(__DIR__.'/errors/mixed-source-attributes.expect'), '--prepend-source'); 57 | 58 | testXml(__DIR__.'/errors/mixed.xml', 1, file_get_contents(__DIR__.'/errors/mixed-colors.expect'), '--colorize'); 59 | 60 | testXml(__DIR__.'/noerrors/only-header.xml', 0, file_get_contents(__DIR__.'/noerrors/only-header.expect')); 61 | testXml(__DIR__.'/noerrors/only-header-php-cs-fixer.xml', 0, file_get_contents(__DIR__.'/noerrors/only-header-php-cs-fixer.expect')); 62 | 63 | testXml(__DIR__.'/errors/mixed-case.xml', 1, file_get_contents(__DIR__.'/errors/mixed-case.expect')); 64 | 65 | testXml(__DIR__.'/errors/mixed.xml', 1, file_get_contents(__DIR__.'/errors/errors-as-warnings.expect'), '--errors-as-warnings'); 66 | --------------------------------------------------------------------------------