mheap / phpunit-matcher-action

Add annotations to your PHPUnit tests when running under Github Actions
32 stars 6 forks source link

Support errors that have no file #22

Open alnviana opened 5 months ago

alnviana commented 5 months ago

Sorry for that title, but I don't know how to explain better.

Take that messages as example:

##teamcity[testStarted name='testHandler with data set "mustNotPublishWhenProcessStartLessThanRequired"' locationHint='php_qn:///home/runner/work/repository/repository/tests/Unit/Console/Commands/Multi/MultiUnitTest.php::\Tests\Unit\Console\Commands\Multi\MultiUnitTest::testHandler with data set "mustNotPublishWhenProcessStartLessThanRequired"' flowId='6414']
##teamcity[testFailed name='testHandler with data set "mustNotPublishWhenProcessStartLessThanRequired"' message='Expectation failed for method name is "publish" when invoked 0 time(s).|nMethod was expected to be called 0 times, actually called 1 times.|n' details=' phpvfscomposer:///home/runner/work/repository/repository/vendor/phpunit/phpunit/phpunit:97|n ' duration='993' flowId='6414']
##teamcity[testFinished name='testHandler with data set "mustNotPublishWhenProcessStartLessThanRequired"' duration='993' flowId='6414']

I don't know in what cases this happen for sure. Was told me that maybe happens when a assert use a mock, so because that, it doesn't have a file to show.

To solve our problem I did this:

{
  "problemMatcher": [
    {
      "owner": "phpunit-locationHint",
      "severity": "error",
      "pattern": [
        {
          "regexp": "##teamcity\\[testStarted.+name='.+'.+locationHint='(?:php_qn://)?{{GITHUB_WORKSPACE}}/(.+)::.*::.*[^']+'",
          "file": 1
        },
        {
          "regexp": "##teamcity\\[testFailed.+(name='.+'.+message='.+').+details='.*'",
          "message": 1,
          "loop": false
        }
      ]
    }
  ]
}
steps:
  - uses: actions/checkout@v4
  - run: |
      sed -i 's@{{GITHUB_WORKSPACE}}@'$GITHUB_WORKSPACE'@g' .github/matchers/phpunit.json
      echo "::add-matcher::.github/matchers/phpunit.json"

Using that I have a annotation with the file that has error, with the asset name and the message, what would help to find the problem. I don't know if this make sense, or if could help in any way, but would be great if this Action could show that kind of error, instead of looking into teamcity logs. x.x

(ps: Thanks for your website post, that helped a lot. :D)

mheap commented 4 months ago

Hey @alnviana. I wanted to acknowledge your issue, but after spending a little time on it I'd like to hear from other users that are hitting this issue before updating the action. It looks as though you managed to get it working with a custom matcher for your use case.

alnviana commented 4 months ago

Okay, no problem at all. As you said, I already solved on my side, so this issue is just to help the others. :) Other examples would be great, because my custom matcher could be faulty or just doesn't work in some case. Thanks!