Skip to content

Commit 28dd4f5

Browse files
committed
Update dependencies
1 parent 003e066 commit 28dd4f5

8 files changed

Lines changed: 87 additions & 57 deletions

File tree

composer.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,19 @@
2525
"source": "https://github.com/phug-php/dev-tool",
2626
"docs": "http://phug-lang.com/docs"
2727
},
28-
"minimum-stability": "stable",
28+
"minimum-stability": "dev",
29+
"prefer-stable": true,
2930
"require": {
3031
"php": ">=5.5.0",
31-
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0 || ^7.0",
32-
"phpunit/php-code-coverage": "^2.2 || ^4.0 || ^5.2 || ^6.0",
33-
"squizlabs/php_codesniffer": "^2.8",
34-
"symfony/console": "^3.2",
35-
"codeclimate/php-test-reporter": "^0.4.0"
32+
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0 || ^7.0 || ^8.0",
33+
"phpunit/php-code-coverage": "^2.2 || ^4.0 || ^5.2 || ^6.0 || ^7.0",
34+
"squizlabs/php_codesniffer": "^2.8 || ^3.0",
35+
"symfony/console": "^3.2 || ^4.0 || ^5.0@dev"
3636
},
3737
"autoload": {
3838
"psr-4": {
3939
"": "./src"
4040
}
4141
},
42-
"bin": ["bin/phug-dev"],
43-
"suggest": {}
42+
"bin": ["bin/phug-dev"]
4443
}

src/Phug/DevTool/Application.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Phug\DevTool\Command\CodeStyleFixCommand;
88
use Phug\DevTool\Command\CoverageCheckCommand;
99
use Phug\DevTool\Command\CoverageReportCommand;
10+
use Phug\DevTool\Command\CoverageReportPrepareCommand;
1011
use Phug\DevTool\Command\InstallCommand;
1112
use Phug\DevTool\Command\UnitTestsRunCommand;
1213
use RuntimeException;
@@ -31,6 +32,7 @@ protected function configure()
3132
$this->add(new CodeStyleFixCommand());
3233
$this->add(new CoverageCheckCommand());
3334
$this->add(new CoverageReportCommand());
35+
$this->add(new CoverageReportPrepareCommand());
3436
$this->add(new InstallCommand());
3537
$this->add(new UnitTestsRunCommand());
3638
}
@@ -142,9 +144,36 @@ public function runCodeStyleFixer(array $arguments = null)
142144
return $this->runVendorCommand('phpcbf', $arguments);
143145
}
144146

145-
public function runCoverageReporter(array $arguments = null)
147+
public function runCoverageReporterPreparation()
146148
{
147-
return $this->runVendorCommand('test-reporter', $arguments);
149+
$url = 'https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64';
150+
151+
return $this->runShellCommand(implode(' && ', [
152+
"curl -L $url > ./cc-test-reporter",
153+
'chmod +x ./cc-test-reporter',
154+
'./cc-test-reporter before-build',
155+
]));
156+
}
157+
158+
public function runCoverageReporter()
159+
{
160+
$clover = file_exists('clover.xml');
161+
$coverage = file_exists('coverage.xml');
162+
163+
if (!$clover && !$coverage) {
164+
return 0; // No report to send
165+
} elseif (!$clover && $coverage) {
166+
copy('coverage.xml', 'clover.xml');
167+
} elseif (!$coverage && $clover) {
168+
copy('clover.xml', 'coverage.xml');
169+
}
170+
171+
return $this->runShellCommand(implode(' && ', [
172+
'bash <(curl -s https://codecov.io/bash)',
173+
'./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT',
174+
'composer require codacy/coverage',
175+
'vendor/bin/codacycoverage clover coverage.xml',
176+
]));
148177
}
149178

150179
public function run(InputInterface $input = null, OutputInterface $output = null)

src/Phug/DevTool/Command/CoverageReportCommand.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ protected function configure()
3030

3131
protected function execute(InputInterface $input, OutputInterface $output)
3232
{
33-
$xmlFile = realpath($input->getArgument('input-file'));
34-
3533
$phpVersion = $input->getOption('php-version');
3634

3735
if (!empty($phpVersion)) {
@@ -49,10 +47,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
4947
);
5048
}
5149

52-
$this->getApplication()->runVendorCommand('test-reporter', [
53-
'--coverage-report' => $xmlFile,
54-
]);
55-
56-
return 0;
50+
return $this->getApplication()->runCoverageReporter();
5751
}
5852
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Phug\DevTool\Command;
4+
5+
use Phug\DevTool\AbstractCommand;
6+
use Symfony\Component\Console\Input\InputArgument;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Input\InputOption;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
class CoverageReportPrepareCommand extends AbstractCommand
12+
{
13+
protected function configure()
14+
{
15+
$this->setName('coverage:report:prepare')
16+
->setHelp('This command install the coverage report utils.');
17+
}
18+
19+
protected function execute(InputInterface $input, OutputInterface $output)
20+
{
21+
$phpVersion = $input->getOption('php-version');
22+
23+
if (!empty($phpVersion)) {
24+
if (!preg_match('/^'.preg_quote($phpVersion).'(\D.*)?$/', PHP_VERSION)) {
25+
$output->writeln(
26+
'Test report ignored since PHP version ('.PHP_VERSION.')'.
27+
' does not match '.$phpVersion.'.'
28+
);
29+
30+
return 0;
31+
}
32+
$output->writeln(
33+
'<fg=green>Proceed test report since PHP version ('.PHP_VERSION.') '.
34+
'matches '.$phpVersion.'.</>'
35+
);
36+
}
37+
38+
return $this->getApplication()->runCoverageReporterPreparation();
39+
}
40+
}

tests/Phug/DevTool/ApplicationTest.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Phug\DevTool\Application;
7+
use RuntimeException;
78
use Symfony\Component\Console\Application as ConsoleApplication;
89
use Symfony\Component\Console\Input\StringInput;
910
use Symfony\Component\Console\Output\BufferedOutput;
@@ -105,12 +106,12 @@ public function testRunVendorCommand()
105106
}
106107

107108
/**
108-
* @covers ::getShellCommandPath
109-
* @expectedException \RuntimeException
110-
* @expectedExceptionMessage The given command [vendor/bin/doNotExists] was not found
109+
* @covers ::getShellCommandPath
111110
*/
112111
public function testGetShellCommandPathException()
113112
{
113+
self::expectException(RuntimeException::class);
114+
self::expectExceptionMessage('The given command [vendor/bin/doNotExists] was not found');
114115
$app = new Application();
115116
$app->runVendorCommand('doNotExists');
116117
}
@@ -167,17 +168,6 @@ public function testRunCodeStyleFixer()
167168
self::assertSame(0, $app->runCodeStyleFixer(['--version']));
168169
}
169170

170-
/**
171-
* @covers ::runCoverageReporter
172-
*/
173-
public function testRunCoverageReporter()
174-
{
175-
$app = new Application();
176-
177-
self::expectOutputRegex('/Code Climate PHP Test Reporter/');
178-
self::assertSame(0, $app->runCoverageReporter(['--version']));
179-
}
180-
181171
/**
182172
* @covers ::run
183173
*/

tests/Phug/DevTool/Command/CheckCommandTest.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,18 @@ public function testExecute()
3636
foreach (glob(__DIR__.'/../../../app/vendor/bin/*') as $file) {
3737
chmod($file, 0777);
3838
}
39-
file_put_contents('coverage.xml', '<?xml version="1.0" encoding="UTF-8"?>
40-
<coverage generated="1482856255">
41-
<project timestamp="1482856255">
42-
<package name="Phug\DevTool">
43-
<file name="src/Phug/DevTool/Application.php">
44-
<class name="Application" namespace="Phug\DevTool">
45-
<metrics complexity="26" methods="17" coveredmethods="17" conditionals="0" coveredconditionals="0" statements="49" coveredstatements="49" elements="66" coveredelements="66"/>
46-
</class>
47-
<line num="20" type="method" name="__construct" visibility="public" complexity="1" crap="1" count="1"/>
48-
<line num="22" type="stmt" count="1"/>
49-
<line num="24" type="stmt" count="1"/>
50-
<line num="25" type="stmt" count="1"/>
51-
</file>
52-
</package>
53-
</project>
54-
</coverage>');
5539
$input = new StringInput('check');
5640
$buffer = new BufferedOutput();
5741
$app = new Application();
5842
$app->setAutoExit(false);
59-
$code = $app->run($input, $buffer);
43+
ob_start();
44+
$app->run($input, $buffer);
45+
ob_end_clean();
6046
if (file_exists('coverage.xml')) {
6147
unlink('coverage.xml');
6248
}
6349
chdir($cwd);
6450

65-
self::assertSame(0, $code);
66-
$checkStyle = version_compare(PHP_VERSION, '5.6.0') >= 0;
67-
$expectedPattern = $checkStyle ? '/Code looks great\. Go on!/' : '/Code Coverage/';
68-
self::assertRegExp($expectedPattern, $buffer->fetch());
51+
self::assertStringContainsString('Error: Code coverage files not found. Please run `unit-tests:run`', $buffer->fetch());
6952
}
7053
}

tests/app/vendor/bin/test-reporter

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/app/vendor/bin/test-reporter.bat

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)