Best Atoum code snippet using colorizer.colorize
cli.php
Source:cli.php
1<?php2namespace mageekguy\atoum\report\fields\runner\tests\coverage;3use mageekguy\atoum\cli\colorizer;4use mageekguy\atoum\cli\prompt;5use mageekguy\atoum\report;6class cli extends report\fields\runner\tests\coverage7{8 protected $titlePrompt = null;9 protected $classPrompt = null;10 protected $methodPrompt = null;11 protected $titleColorizer = null;12 protected $coverageColorizer = null;13 protected $hideClassesCoverageDetails = false;14 protected $hideMethodsCoverageDetails = false;15 public function __construct()16 {17 parent::__construct();18 $this19 ->setTitlePrompt()20 ->setClassPrompt()21 ->setMethodPrompt()22 ->setTitleColorizer()23 ->setCoverageColorizer()24 ;25 }26 public function __toString()27 {28 $string = '';29 if ($this->coverage !== null && sizeof($this->coverage) > 0) {30 $string .= $this->titlePrompt .31 sprintf(32 $this->locale->_('%s: %s'),33 $this->titleColorizer->colorize($this->locale->_('Code coverage value')),34 $this->coverageColorizer->colorize(sprintf('%3.2f%%', $this->coverage->getValue() * 100.0))35 ) .36 PHP_EOL37 ;38 if (sizeof($this->coverage->getPaths()) > 0) {39 $string .= $this->titlePrompt .40 sprintf(41 $this->locale->_('%s: %s'),42 $this->titleColorizer->colorize($this->locale->_('Path coverage value')),43 $this->coverageColorizer->colorize(sprintf('%3.2f%%', $this->coverage->getPathsCoverageValue() * 100.0))44 ) .45 PHP_EOL46 ;47 }48 if (sizeof($this->coverage->getBranches()) > 0) {49 $string .= $this->titlePrompt .50 sprintf(51 $this->locale->_('%s: %s'),52 $this->titleColorizer->colorize($this->locale->_('Branch coverage value')),53 $this->coverageColorizer->colorize(sprintf('%3.2f%%', $this->coverage->getBranchesCoverageValue() * 100.0))54 ) .55 PHP_EOL56 ;57 }58 if ($this->hideClassesCoverageDetails === false) {59 foreach ($this->coverage->getMethods() as $class => $methods) {60 $classCoverage = $this->coverage->getValueForClass($class);61 $classPathsCoverage = $this->coverage->getPathsCoverageValueForClass($class);62 $classBranchesCoverage = $this->coverage->getBranchesCoverageValueForClass($class);63 if ($classCoverage < 1.0) {64 $string .= $this->classPrompt .65 sprintf(66 $this->locale->_('%s: %s%s%s'),67 $this->titleColorizer->colorize($this->locale->_('Class %s', $class)),68 $this->coverageColorizer->colorize(sprintf('%s%3.2f%%', ($classPathsCoverage !== null || $classBranchesCoverage !== null ? 'Line: ' : ''), $classCoverage * 100.0)),69 $classPathsCoverage !== null ? $this->coverageColorizer->colorize(sprintf(' Path: %3.2f%%', $classPathsCoverage * 100.0)) : '',70 $classBranchesCoverage !== null ? $this->coverageColorizer->colorize(sprintf(' Branch: %3.2f%%', $classBranchesCoverage * 100.0)) : ''71 ) .72 PHP_EOL73 ;74 if ($this->hideMethodsCoverageDetails === false) {75 foreach (array_keys($methods) as $method) {76 $methodCoverage = $this->coverage->getValueForMethod($class, $method);77 $methodPathsCoverage = $this->coverage->getPathsCoverageValueForMethod($class, $method);78 $methodBranchesCoverage = $this->coverage->getBranchesCoverageValueForMethod($class, $method);79 if ($methodCoverage < 1.0) {80 $string .= $this->methodPrompt .81 sprintf(82 $this->locale->_('%s: %s%s%s'),83 $this->titleColorizer->colorize($this->locale->_('%s::%s()', $class, $method)),84 $this->coverageColorizer->colorize(sprintf('%s%3.2f%%', ($methodPathsCoverage !== null || $methodBranchesCoverage !== null ? 'Line: ' : ''), $methodCoverage * 100.0)),85 $methodPathsCoverage !== null ? $this->coverageColorizer->colorize(sprintf(', Path: %3.2f%%', $methodPathsCoverage * 100.0)) : '',86 $methodBranchesCoverage !== null ? $this->coverageColorizer->colorize(sprintf(', Branch: %3.2f%%', $methodBranchesCoverage * 100.0)) : ''87 ) .88 PHP_EOL;89 }90 }91 }92 }93 }94 }95 }96 return $string;97 }98 public function setTitlePrompt(prompt $prompt = null)99 {100 $this->titlePrompt = $prompt ?: new prompt();101 return $this;102 }103 public function getTitlePrompt()104 {105 return $this->titlePrompt;106 }107 public function setClassPrompt(prompt $prompt = null)108 {109 $this->classPrompt = $prompt ?: new prompt();110 return $this;111 }112 public function getClassPrompt()113 {114 return $this->classPrompt;115 }116 public function setMethodPrompt(prompt $prompt = null)117 {118 $this->methodPrompt = $prompt ?: new prompt();119 return $this;120 }121 public function getMethodPrompt()122 {123 return $this->methodPrompt;124 }125 public function setTitleColorizer(colorizer $colorizer = null)126 {127 $this->titleColorizer = $colorizer ?: new colorizer();128 return $this;129 }130 public function getTitleColorizer()131 {132 return $this->titleColorizer;133 }134 public function setCoverageColorizer(colorizer $colorizer = null)135 {136 $this->coverageColorizer = $colorizer ?: new colorizer();137 return $this;138 }139 public function getCoverageColorizer()140 {141 return $this->coverageColorizer;142 }143 public function hideClassesCoverageDetails()144 {145 $this->hideClassesCoverageDetails = true;146 return $this;147 }148 public function hideMethodsCoverageDetails()149 {150 $this->hideMethodsCoverageDetails = true;...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with colorize on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!