lirik44 / phpunit-teamcity-extended
Extended support teamcity testMetadata in php STDOUT output for phpunit
v1.0.3
2023-12-03 09:51 UTC
Requires
- php: ^7.1|^8.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-03 11:19:44 UTC
README
Extended support for testMetadata in PHPUnit STDOUT.
Added Description Trait for parse @description annotation in tests
Installation
composer require lirik44/phpunit-teamcity-extended
Using Descripton trait
Specify @description annotation before test function
class MyTest extends PHPUnit\Framework\TestCase { /** * @description This test check something on page */ public function testSomethingOnPage() { // test something ... }
Use DescriptionTrait in Selenium Helper:
class SeleniumHelper extends TestCase { protected $testHelper; public function setUp():void { $testName=$this->getName(); $this->testHelper->setupSeleniumSession($testName); date_default_timezone_set( 'Europe/Moscow' ); } use DescriptionTrait; public function tearDown():void { //If test fails get description from @description if ($this->hasFailed()) { //Get description text $this->description = $this->getTestDescription(); }
Other testMetadata features
Similar as a description you can specify different testMetadata in teadDown() section:
public function tearDown():void { //Take metaData if test has failed if ($this->hasFailed()) { //Get browser URL in the moment of test error occur $this->browserLink = $this->webDriver->getCurrentURL(); //Get browser screenshot in the moment of test error occur $this->screenshotErr = $this->testHelper->getErrorScreenshot($testName); //Get php_errors.log after test fails $this->errLog = $this->testHelper->getPhpErrorLog($testName); //Get mono.log after test fails $this->monoLog = $this->testHelper->getMonoLog($testName); } }
Also it is possible to get any information into setUp() section and publish that as a buildTag:
public function setUp():void { $testName=$this->getName(); $this->testHelper->setupSeleniumSession($testName); date_default_timezone_set( 'Europe/Moscow' ); //Get current application git branch $this->buildTag = $this->getUsedBranch(); }