Skip to content

Commit

Permalink
php 8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeerickson committed Jul 28, 2021
1 parent a361009 commit b04ebbc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codedungeon/phpunit-result-printer",
"version": "0.30.1",
"version": "0.31.0",
"description": "PHPUnit Pretty Result Printer",
"keywords": [
"phpunit",
Expand Down Expand Up @@ -35,7 +35,7 @@
}
},
"scripts": {
"post-package-install": [
"post-install-cmd": [
"php ./vendor/codedungeon/phpunit-result-printer/src/init.php"
],
"coverage-report": "open ./coverage/index.html",
Expand All @@ -50,4 +50,4 @@
"test-watch": "vendor/bin/phpunit-watcher watch --testsuite Unit < /dev/tty",
"watch-tickets": "vendor/bin/phpunit-watcher watch --testsuite Tickets < /dev/tty"
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phpunit-pretty-result-printer",
"version": "0.30.1",
"version": "0.31.0",
"description": "Extend the default PHPUnit Result Printer with a modern, pretty printer!",
"main": "index.js",
"directories": {
Expand Down Expand Up @@ -28,4 +28,4 @@
"@codedungeon/messenger": "0.7.0",
"prettier": "2.1.2"
}
}
}
27 changes: 14 additions & 13 deletions src/PrinterInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@ public function init(string $use_colors = 'never', array $options = []): int
if (!file_exists($phpunit_xml_file)) {
$phpunit_xml_file = './phpunit.xml.dist';
}
echo self::CYAN."\n==> Configuring phpunit-pretty-result-printer\n".self::RESET;
echo "\n ".self::LWHITE.'[• ]'.self::GREEN." Gathering installation details\n".self::RESET;
echo self::CYAN . "\n==> Configuring phpunit-pretty-result-printer\n" . self::RESET;
echo "\n " . self::LWHITE . '[• ]' . self::GREEN . " Gathering installation details\n" . self::RESET;
$result = $this->add_printer_class_to_phpunit_xml($phpunit_xml_file);
if ($useCollision) {
if (is_dir('vendor/nunomaduro/collision')) {
$result = $this->add_collision_to_phpunit_xml($phpunit_xml_file);
if ($result === 0) {
echo self::GREEN." ✔ Collision listener activated\n".self::RESET;
echo self::GREEN . " ✔ Collision listener activated\n" . self::RESET;
} else {
echo self::MAGENTA." ⇢ Collision already installed\n".self::RESET;
echo self::MAGENTA . " ⇢ Collision already installed\n" . self::RESET;
}
} else {
echo self::RED." ✖ Collision package not installed\n".self::RESET;
echo self::RED . " ✖ Collision package not installed\n" . self::RESET;
}
}
$this->copy_default_settings('phpunit-printer.yml');
echo self::CYAN."\n==> Configuration Complete\n".self::RESET;
echo self::CYAN . "\n==> Configuration Complete\n" . self::RESET;
echo "\n";

return $result;
}
Expand All @@ -54,19 +55,19 @@ private function add_printer_class_to_phpunit_xml(string $file = './phpunit.xml'
$data = file_get_contents($PHPUNIT_FILE);
$result = (int) strpos($data, 'printerClass=');
if ($result > 0) {
echo self::LWHITE.' [•• ]'.self::LYELLOW.' Printer class already configured in '.self::CYAN."{$PHPUNIT_FILE} \n".self::RESET;
echo self::LWHITE . ' [•• ]' . self::LYELLOW . ' Printer class already configured in ' . self::CYAN . "{$PHPUNIT_FILE} \n" . self::RESET;

return 0;
} else {
$xml = simplexml_load_file($PHPUNIT_FILE);
$xml->addAttribute('printerClass', 'Codedungeon\PHPUnitPrettyResultPrinter\Printer');
file_put_contents($PHPUNIT_FILE, $xml->asXML());
echo self::LWHITE.' [•• ]'.self::GREEN.' Printer class successfully added to '.self::CYAN.$PHPUNIT_FILE.self::GREEN." file\n".self::RESET;
echo self::LWHITE . ' [•• ]' . self::GREEN . ' Printer class successfully added to ' . self::CYAN . $PHPUNIT_FILE . self::GREEN . " file\n" . self::RESET;

return 1;
}
} else {
echo self::RED.' [•• ] Unable to locate valid '.self::YELLOW.$PHPUNIT_FILE.self::RED.' file, you will need to set '.self::CYAN.'printerClass '.self::RED."manually\n".self::RESET;
echo self::RED . ' [•• ] Unable to locate valid ' . self::YELLOW . $PHPUNIT_FILE . self::RED . ' file, you will need to set ' . self::CYAN . 'printerClass ' . self::RED . "manually\n" . self::RESET;

return -43;
}
Expand Down Expand Up @@ -98,18 +99,18 @@ private function add_collision_to_phpunit_xml(string $file = './phpunit.xml'): i
private function copy_default_settings(string $file = 'phpunit-printer.yml')
{
$CONFIG_FILE = $file;
$packageDefaultSettingFile = dirname(__FILE__, 2).DIRECTORY_SEPARATOR.'src/'.$CONFIG_FILE;
$packageDefaultSettingFile = dirname(__FILE__, 2) . DIRECTORY_SEPARATOR . 'src/' . $CONFIG_FILE;

$copySettingFile = $CONFIG_FILE;
if (file_exists($packageDefaultSettingFile)) {
if (!file_exists($copySettingFile)) {
copy($packageDefaultSettingFile, $copySettingFile);
echo self::LWHITE.' [•••]'.self::GREEN.' Configuration '.self::CYAN.'./'.$CONFIG_FILE.self::GREEN." copied to project root\n".self::RESET;
echo self::LWHITE . ' [•••]' . self::GREEN . ' Configuration ' . self::CYAN . './' . $CONFIG_FILE . self::GREEN . " copied to project root\n" . self::RESET;
} else {
echo self::LWHITE.' [•••]'.self::LYELLOW.' Configuration '.self::CYAN.'./'.$CONFIG_FILE.self::LYELLOW." already exists\n".self::RESET;
echo self::LWHITE . ' [•••]' . self::LYELLOW . ' Configuration ' . self::CYAN . './' . $CONFIG_FILE . self::LYELLOW . " already exists\n" . self::RESET;
}
} else {
echo self::LWHITE.' [••E]'.self::RED." An error occurred preparing configuration file\n".self::RESET;
echo self::LWHITE . ' [••E]' . self::RED . " An error occurred preparing configuration file\n" . self::RESET;
}
}
}

0 comments on commit b04ebbc

Please sign in to comment.