Skip to content

Commit

Permalink
Update the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Jul 17, 2023
1 parent db55ac9 commit 6f51322
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 53 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"require-dev": {
"phpstan/phpstan": "^1.10.25",
"phpunit/phpunit": "^10.2.5"
"phpunit/phpunit": "^10.2.6"
},
"scripts": {
"test": ["@putenv XDEBUG_MODE=coverage", "phpunit --configuration=etc/phpunit.xml"]
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/FunctionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function __construct(public string $functionName = "", public int $lineNumber =
* @return string The string representation of this object.
*/
final function __toString(): string {
return $this->toString();
return implode(PHP_EOL, [$this->toString(true), $this->toString(false)]);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions test/BranchCoverageTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php namespace lcov;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\{Test, TestDox};
use function PHPUnit\Framework\{assertThat, countOf, equalTo, isEmpty, isInstanceOf};

/**
* Tests the features of the {@see BranchCoverage} class.
*/
#[TestDox('lcov\BranchCoverage')]
#[TestDox("BranchCoverage")]
final class BranchCoverageTest extends TestCase {

#[TestDox("::fromJson()")]
function testFromJson(): void {
#[Test]
#[TestDox("fromJson()")]
function fromJson(): void {
// It should return an instance with default values for an empty map.
$coverage = BranchCoverage::fromJson(new \stdClass);
assertThat($coverage->data, isEmpty());
Expand All @@ -29,7 +30,8 @@ function testFromJson(): void {
assertThat($data->lineNumber, equalTo(127));
}

#[TestDox("->__toString()")]
#[Test]
#[TestDox("__toString()")]
function testToString(): void {
// It should return a format like 'BRF:<found>\\nBRH:<hit>'.
assertThat((string) new BranchCoverage, equalTo(str_replace("{eol}", PHP_EOL, "BRF:0{eol}BRH:0")));
Expand Down
12 changes: 7 additions & 5 deletions test/BranchDataTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php namespace lcov;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\{Test, TestDox};
use function PHPUnit\Framework\{assertThat, equalTo};

/**
* Tests the features of the {@see BranchData} class.
*/
#[TestDox('lcov\BranchData')]
#[TestDox("BranchData")]
final class BranchDataTest extends TestCase {

#[TestDox("::fromJson()")]
function testFromJson(): void {
#[Test]
#[TestDox("fromJson()")]
function fromJson(): void {
// It should return an instance with default values for an empty map.
$data = BranchData::fromJson(new \stdClass);
assertThat($data->blockNumber, equalTo(0));
Expand All @@ -27,7 +28,8 @@ function testFromJson(): void {
assertThat($data->taken, equalTo(1));
}

#[TestDox("->__toString()")]
#[Test]
#[TestDox("__toString()")]
function testToString(): void {
// It should return a format like 'BRDA:<lineNumber>,<blockNumber>,<branchNumber>,<taken>'.
assertThat((string) new BranchData, equalTo("BRDA:0,0,0,-"));
Expand Down
15 changes: 9 additions & 6 deletions test/FunctionCoverageTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php namespace lcov;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\{Test, TestDox};
use function PHPUnit\Framework\{assertThat, countOf, equalTo, isEmpty, isInstanceOf};

/**
* Tests the features of the {@see FunctionCoverage} class.
*/
#[TestDox('lcov\FunctionCoverage')]
#[TestDox("FunctionCoverage")]
final class FunctionCoverageTest extends TestCase {

#[TestDox("::fromJson()")]
function testFromJson(): void {
#[Test]
#[TestDox("fromJson()")]
function fromJson(): void {
// It should return an instance with default values for an empty map.
$coverage = FunctionCoverage::fromJson(new \stdClass);
assertThat($coverage->data, isEmpty());
Expand All @@ -29,12 +30,14 @@ function testFromJson(): void {
assertThat($data->lineNumber, equalTo(127));
}

#[TestDox("->__toString()")]
#[Test]
#[TestDox("__toString()")]
function testToString(): void {
// It should return a format like 'FNF:<found>\\nFNH:<hit>'.
assertThat((string) new FunctionCoverage, equalTo(str_replace("{eol}", PHP_EOL, "FNF:0{eol}FNH:0")));

$coverage = new FunctionCoverage(data: [new FunctionData(executionCount: 3, functionName: "main", lineNumber: 127)], found: 23, hit: 11);
$data = new FunctionData(executionCount: 3, functionName: "main", lineNumber: 127);
$coverage = new FunctionCoverage(data: [$data], found: 23, hit: 11);
assertThat((string) $coverage, equalTo(str_replace("{eol}", PHP_EOL, "FN:127,main{eol}FNDA:3,main{eol}FNF:23{eol}FNH:11")));
}
}
12 changes: 7 additions & 5 deletions test/FunctionDataTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php namespace lcov;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\{Test, TestDox};
use function PHPUnit\Framework\{assertThat, equalTo, isEmpty};

/**
* Tests the features of the {@see FunctionData} class.
*/
#[TestDox('lcov\FunctionData')]
#[TestDox("FunctionData")]
final class FunctionDataTest extends TestCase {

#[TestDox("::fromJson()")]
function testFromJson(): void {
#[Test]
#[TestDox("fromJson()")]
function fromJson(): void {
// It should return an instance with default values for an empty map.
$data = FunctionData::fromJson(new \stdClass);
assertThat($data->executionCount, equalTo(0));
Expand All @@ -25,7 +26,8 @@ function testFromJson(): void {
assertThat($data->lineNumber, equalTo(127));
}

#[TestDox("->toString()")]
#[Test]
#[TestDox("toString()")]
function testToString(): void {
// It should return a format like 'FN:<lineNumber>,<functionName>' when used as definition.
assertThat((new FunctionData)->toString(true), equalTo("FN:0,"));
Expand Down
15 changes: 9 additions & 6 deletions test/LineCoverageTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php namespace lcov;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\{Test, TestDox};
use function PHPUnit\Framework\{assertThat, countOf, equalTo, isEmpty, isInstanceOf};

/**
* Tests the features of the {@see LineCoverage} class.
*/
#[TestDox('lcov\LineCoverage')]
#[TestDox("LineCoverage")]
final class LineCoverageTest extends TestCase {

#[TestDox("::fromJson()")]
function testFromJson(): void {
#[Test]
#[TestDox("fromJson()")]
function fromJson(): void {
// It should return an instance with default values for an empty map.
$coverage = LineCoverage::fromJson(new \stdClass);
assertThat($coverage->data, isEmpty());
Expand All @@ -29,12 +30,14 @@ function testFromJson(): void {
assertThat($data->lineNumber, equalTo(127));
}

#[TestDox("->__toString()")]
#[Test]
#[TestDox("__toString()")]
function testToString(): void {
// It should return a format like 'LF:<found>\\nLH:<hit>'.
assertThat((string) new LineCoverage, equalTo(str_replace("{eol}", PHP_EOL, "LF:0{eol}LH:0")));

$data = new LineData(executionCount: 3, lineNumber: 127);
assertThat((string) new LineCoverage(data: [$data], found: 23, hit: 11), equalTo(str_replace("{eol}", PHP_EOL, "$data{eol}LF:23{eol}LH:11")));
$coverage = new LineCoverage(data: [$data], found: 23, hit: 11);
assertThat((string) $coverage, equalTo(str_replace("{eol}", PHP_EOL, "$data{eol}LF:23{eol}LH:11")));
}
}
12 changes: 7 additions & 5 deletions test/LineDataTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php namespace lcov;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\{Test, TestDox};
use function PHPUnit\Framework\{assertThat, equalTo, isEmpty};

/**
* Tests the features of the {@see LineData} class.
*/
#[TestDox('lcov\LineData')]
#[TestDox("LineData")]
final class LineDataTest extends TestCase {

#[TestDox("::fromJson()")]
function testFromJson(): void {
#[Test]
#[TestDox("fromJson()")]
function fromJson(): void {
// It should return an instance with default values for an empty map.
$data = LineData::fromJson(new \stdClass);
assertThat($data->checksum, isEmpty());
Expand All @@ -25,7 +26,8 @@ function testFromJson(): void {
assertThat($data->lineNumber, equalTo(127));
}

#[TestDox("->__toString()")]
#[Test]
#[TestDox("__toString()")]
function testToString(): void {
// It should return a format like 'DA:<lineNumber>,<executionCount>[,<checksum>]'.
assertThat((string) new LineData, equalTo("DA:0,0"));
Expand Down
17 changes: 10 additions & 7 deletions test/ReportTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php namespace lcov;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\{Test, TestDox};
use function PHPUnit\Framework\{assertThat, countOf, equalTo, isEmpty, isInstanceOf};

/**
* Tests the features of the {@see Report} class.
*/
#[TestDox('lcov\Report')]
#[TestDox("Report")]
final class ReportTest extends TestCase {

#[TestDox("::fromJson()")]
function testFromJson(): void {
#[Test]
#[TestDox("fromJson()")]
function fromJson(): void {
// It should return an instance with default values for an empty map.
$report = Report::fromJson(new \stdClass);
assertThat($report->sourceFiles, isEmpty());
Expand All @@ -24,8 +25,9 @@ function testFromJson(): void {
assertThat($report->testName, equalTo("LcovTest"));
}

#[TestDox("::parse()")]
function testParse(): void {
#[Test]
#[TestDox("parse()")]
function parse(): void {
$report = Report::parse(file_get_contents("share/lcov.info") ?: "");

// It should have a test name.
Expand Down Expand Up @@ -76,7 +78,8 @@ function testParse(): void {
Report::parse("TN:Example");
}

#[TestDox("->__toString()")]
#[Test]
#[TestDox("__toString()")]
function testToString(): void {
// It should return a format like 'TN:<testName>'.
assertThat((string) new Report(""), isEmpty());
Expand Down
12 changes: 7 additions & 5 deletions test/SourceFileTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php namespace lcov;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\{Test, TestDox};
use function PHPUnit\Framework\{assertThat, equalTo, isEmpty, isNull, logicalNot};

/**
* Tests the features of the {@see SourceFile} class.
*/
#[TestDox('lcov\SourceFile')]
#[TestDox("SourceFile")]
final class SourceFileTest extends TestCase {

#[TestDox("::fromJson()")]
function testFromJson(): void {
#[Test]
#[TestDox("fromJson()")]
function fromJson(): void {
// It should return an instance with default values for an empty map.
$sourceFile = SourceFile::fromJson(new \stdClass);
assertThat($sourceFile->branches, isNull());
Expand All @@ -33,7 +34,8 @@ function testFromJson(): void {
assertThat($sourceFile->path, equalTo("/home/cedx/lcov.php"));
}

#[TestDox("->__toString()")]
#[Test]
#[TestDox("__toString()")]
function testToString(): void {
// It should return a format like 'SF:<path>\\nend_of_record'.
assertThat((string) new SourceFile(""), equalTo(str_replace("{eol}", PHP_EOL, "SF:{eol}end_of_record")));
Expand Down

0 comments on commit 6f51322

Please sign in to comment.