Skip to content

Commit

Permalink
Fix compat issues
Browse files Browse the repository at this point in the history
  • Loading branch information
exussum12 committed Jun 25, 2024
1 parent 57c2aa2 commit 185cea9
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 109 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"bin": ["bin/diffFilter"],
"require": {
"php": ">=7.0",
"php": ">=8.0",
"ext-xmlreader": "*",
"ext-json": "*",
"nikic/php-parser": "^3.1||^4.0||^5.0"
Expand Down
23 changes: 14 additions & 9 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function handleOutput(array $lines, float $minimumPercentCovered, Output $output

if ($coveredLines + $uncoveredLines == 0) {
error_log('No lines found!');

$output->output(
$lines['uncoveredLines'],
100,
Expand Down Expand Up @@ -126,14 +126,19 @@ function calculateLines(array $lines)

function addExceptionHandler()
{
set_exception_handler(
function ($exception) {
// @codeCoverageIgnoreStart
error_log($exception->getMessage());
exit($exception->getCode());
// @codeCoverageIgnoreEnd
}
);
if (
!defined('PHPUNIT_COMPOSER_INSTALL') &&
!defined('__PHPUNIT_PHAR__')
) {
set_exception_handler(
function ($exception) {
// @codeCoverageIgnoreStart
error_log($exception->getMessage());
exit($exception->getCode());
// @codeCoverageIgnoreEnd
}
);
}
}

function getFileChecker(
Expand Down
5 changes: 2 additions & 3 deletions tests/ArgParserTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace exussum12\CoverageChecker\tests;

use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\TestCase;
use exussum12\CoverageChecker\ArgParser;
use exussum12\CoverageChecker\Exceptions\ArgumentNotFound;
Expand All @@ -9,9 +10,7 @@ class ArgParserTest extends TestCase
{
protected $parser;

/**
* @before
*/
#[Before]
public function setUpTest()
{
$args = [
Expand Down
90 changes: 40 additions & 50 deletions tests/CoverageCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@ public function testCoverage()
]);

$xmlReport->method('getErrorsOnLine')
->will(
$this->returnCallback(
function () {
$file = func_get_arg(0);
$line = func_get_arg(1);
->willReturnCallback(
function () {
$file = func_get_arg(0);
$line = func_get_arg(1);

if ($file == '/full/path/to/testFile1.php' && $line == 2) {
return $this->errorMessage;
}
if ($file == '/full/path/to/testFile2.php' && $line == 4) {
return $this->errorMessage;
}

return [];
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
return $this->errorMessage;
}
if ($file == '/full/path/to/testFile2.php' && $line == 4) {
return $this->errorMessage;
}
)

return [];
}
);

$matcher = new FileMatchers\EndsWith;
Expand Down Expand Up @@ -87,19 +85,17 @@ public function testCoverageFailed()
->willReturn(null);

$xmlReport->method('getErrorsOnLine')
->will(
$this->returnCallback(
function () {
$file = func_get_arg(0);
$line = func_get_arg(1);
->willReturnCallback(
function () {
$file = func_get_arg(0);
$line = func_get_arg(1);

if ($file == '/full/path/to/testFile1.php' && $line == 2) {
return $this->errorMessage;
}

return [];
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
return $this->errorMessage;
}
)

return [];
}
);

$matcher = new FileMatchers\EndsWith;
Expand Down Expand Up @@ -141,19 +137,17 @@ public function testAddingAllUnknownsCovered()
->willReturn(true);

$xmlReport->method('getErrorsOnLine')
->will(
$this->returnCallback(
function () {
$file = func_get_arg(0);
$line = func_get_arg(1);
->willReturnCallback(
function () {
$file = func_get_arg(0);
$line = func_get_arg(1);

if ($file == '/full/path/to/testFile1.php' && $line == 2) {
return $this->errorMessage;
}

return [];
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
return $this->errorMessage;
}
)

return [];
}
);

$matcher = new FileMatchers\EndsWith;
Expand Down Expand Up @@ -196,19 +190,17 @@ public function testAddingAllUnknownsUnCovered()
->willReturn(false);

$xmlReport->method('getErrorsOnLine')
->will(
$this->returnCallback(
function () {
$file = func_get_arg(0);
$line = func_get_arg(1);

if ($file == '/full/path/to/testFile1.php' && $line == 2) {
return $this->errorMessage;
}
->willReturnCallback(
function () {
$file = func_get_arg(0);
$line = func_get_arg(1);

return [];
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
return $this->errorMessage;
}
)

return [];
}
);

$matcher = new FileMatchers\EndsWith;
Expand Down Expand Up @@ -254,8 +246,7 @@ public function testCoverageForContextLines()
->willReturn(false);

$xmlReport->method('getErrorsOnLine')
->will(
$this->returnCallback(
->willReturnCallback(
function () {
$file = func_get_arg(0);
$line = func_get_arg(1);
Expand All @@ -266,7 +257,6 @@ function () {

return [];
}
)
);

$matcher = new FileMatchers\EndsWith;
Expand Down
8 changes: 4 additions & 4 deletions tests/DiffFileLoadOldVersionTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
namespace exussum12\CoverageChecker\tests;

use exussum12\CoverageChecker\DiffFileLoaderOldVersion;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use exussum12\CoverageChecker\DiffFileLoaderOldVersion;


class DiffFileLoadOldVersionTest extends TestCase
{
/**
* @dataProvider getResults
*/
#[DataProvider('getResults')]
public function testDiffResultsMatch($file, $expected)
{
$changed = $this->getChangedLines($file);
Expand Down
5 changes: 2 additions & 3 deletions tests/DiffFileLoadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
namespace exussum12\CoverageChecker\tests;

use InvalidArgumentException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use exussum12\CoverageChecker\DiffFileLoader;
use exussum12\CoverageChecker\DiffFileState;
use exussum12\CoverageChecker\DiffLineHandle\ContextLine;

class DiffFileLoadTest extends TestCase
{
/**
* @dataProvider getResults
*/
#[DataProvider('getResults')]
public function testDiffResultsMatch($file, $expected)
{
$changed = $this->getChangedLines($file);
Expand Down
5 changes: 2 additions & 3 deletions tests/Loaders/CheckstyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
namespace exussum12\CoverageChecker\tests\Loaders;

use exussum12\CoverageChecker\Loaders\Checkstyle;
use PHPUnit\Framework\Attributes\Before;

class CheckstyleTest extends PhanTextTest
{
/** @var Checkstyle */
protected $phan;
protected $prefix = '';

/**
* @before
*/
#[Before]
protected function setUpTest()
{
$this->phan = new Checkstyle(__DIR__ . '/../fixtures/checkstyle.xml');
Expand Down
5 changes: 2 additions & 3 deletions tests/Loaders/CodeClimateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
namespace exussum12\CoverageChecker\tests\Loaders;

use exussum12\CoverageChecker\Loaders\CodeClimate;
use PHPUnit\Framework\Attributes\Before;

class CodeClimateTest extends PhanTextTest
{
/** @var CodeClimate */
protected $phan;
protected $prefix = '';

/**
* @before
*/
#[Before]
protected function setUpTest()
{
$this->phan = new CodeClimate(__DIR__ . '/../fixtures/codeclimate.json');
Expand Down
5 changes: 2 additions & 3 deletions tests/Loaders/PhanJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
namespace exussum12\CoverageChecker\tests\Loaders;

use exussum12\CoverageChecker\Loaders\PhanJson;
use PHPUnit\Framework\Attributes\Before;

class PhanJsonTest extends PhanTextTest
{
/** @var PhanJsonTest */
protected $phan;

/**
* @before
*/
#[Before]
protected function setUpTest()
{
$this->phan = new PhanJson(__DIR__ . '/../fixtures/phan.json');
Expand Down
5 changes: 2 additions & 3 deletions tests/Loaders/PhanTextTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace exussum12\CoverageChecker\tests\Loaders;

use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\TestCase;
use exussum12\CoverageChecker\Loaders\PhanText;
use exussum12\CoverageChecker\tests\TestShim;
Expand All @@ -11,9 +12,7 @@ class PhanTextTest extends TestCase
/** @var PhanText */
protected $phan;

/**
* @before
*/
#[Before]
protected function setUpTest()
{
$this->phan = new PhanText(__DIR__ . '/../fixtures/phan.txt');
Expand Down
12 changes: 5 additions & 7 deletions tests/Loaders/PhpMndTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
namespace exussum12\CoverageChecker\tests;

use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use exussum12\CoverageChecker\Loaders\PhpMnd;

class PhpMndTest extends TestCase
{
private $mnd;

/**
* @before
*/
#[Before]
public function setUpTest()
{
$file = __DIR__ . '/../fixtures/phpmnd.txt';
Expand All @@ -29,9 +29,7 @@ public function testGetOutput()
$this->assertSame($expected, $this->mnd->parseLines());
}

/**
* @dataProvider fileInputs
*/
#[DataProvider('fileInputs')]
public function testLinesReturnCorrect($filename, $lineNo, $expected)
{
$this->mnd->parseLines();
Expand All @@ -44,7 +42,7 @@ public function testInvalidFile()
$this->assertTrue($this->mnd->handleNotFoundFile());
}

public function fileInputs()
public static function fileInputs()
{
return [
'found file, valid line' => ['test.php', 2, []],
Expand Down
5 changes: 2 additions & 3 deletions tests/Loaders/PhpStanTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace exussum12\CoverageChecker\tests;

use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\TestCase;
use exussum12\CoverageChecker\Loaders\PhpStan;

Expand All @@ -9,9 +10,7 @@ class PhpStanTest extends TestCase
/** @var PhpStan */
protected $stan;

/**
* @before
*/
#[Before]
public function setUpTest()
{
$file = __DIR__ . '/../fixtures/phpstan.txt';
Expand Down
7 changes: 3 additions & 4 deletions tests/Loaders/PhpcpdTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace exussum12\CoverageChecker\tests\Loaders;

use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\TestCase;
use exussum12\CoverageChecker\Loaders\Phpcpd;

Expand All @@ -9,10 +10,8 @@ class PhpcpdTest extends TestCase
/** @var Phpcpd */
protected $cpd;

/**
* @before
*/
protected function setUpTest()
#[Before]
protected function setUpTest(): void
{
$this->cpd = new Phpcpd(__DIR__ . '/../fixtures/phpcpd.txt');

Expand Down
Loading

0 comments on commit 185cea9

Please sign in to comment.