Skip to content

Commit

Permalink
Make sure dg/bypass-finals works with Infection (#1728)
Browse files Browse the repository at this point in the history
* Add tests to make sure `bypass-finals` lib does not lead to escaped mutants

* Test dg/bypass-finals@7c08b98

* Tests different approaches

* Use the latest `master` of `db/bypass-finals`

* Update `db/bypass-finals` to the latest commit to check if the issue is fixed

* Update `conflict` section with new version of `dg/bypass-finals`

* Run `composer update --lock`

* Update `expected-output.txt` to fix e2e test

* Fix incorrect versions

* Run `composer update --lock`

* For some unknown reason, MSI has decreased with no changes in `src`
  • Loading branch information
maks-rafalko committed Sep 15, 2022
1 parent b66257a commit cac814f
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

env:
MIN_MSI: 71.35
MIN_COVERED_MSI: 86.54
MIN_COVERED_MSI: 86.50

jobs:
tests:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
"conflict": {
"phpunit/php-code-coverage": ">9 <9.1.4",
"dg/bypass-finals": "*"
"dg/bypass-finals": "<1.4.1"
},
"require-dev": {
"ext-simplexml": "*",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

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

10 changes: 10 additions & 0 deletions tests/e2e/Stream_Wrapper_Execution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ensures Infection works with `dg/bypass-finals`

* https://github.com/dg/bypass-finals/issues/9
* https://github.com/infection/infection/issues/1275

## Summary

`dg/bypass-finals` before version 1.4.1 overridden Infection's Stream Wrapper and Infection did not create any Mutants.

This tests ensures that starting from 1.4.1 `dg/bypass-finals` works good and do not "disables" Infection's Stream Wrapper.
16 changes: 16 additions & 0 deletions tests/e2e/Stream_Wrapper_Execution/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"require-dev": {
"phpunit/phpunit": "^9.5.5",
"dg/bypass-finals": "^1.4.1"
},
"autoload": {
"psr-4": {
"Stream_Wrapper_Execution\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Stream_Wrapper_Execution\\Test\\": "tests/"
}
}
}
10 changes: 10 additions & 0 deletions tests/e2e/Stream_Wrapper_Execution/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Total: 5

Killed: 5
Errored: 0
Syntax Errors: 0
Escaped: 0
Timed Out: 0
Skipped: 0
Ignored: 0
Not Covered: 0
15 changes: 15 additions & 0 deletions tests/e2e/Stream_Wrapper_Execution/infection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"timeout": 5,
"source": {
"directories": [
"src"
]
},
"logs": {
"summary": "infection.log"
},
"tmpDir": ".",
"mutators": {
"@default": true
}
}
18 changes: 18 additions & 0 deletions tests/e2e/Stream_Wrapper_Execution/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>./src/</directory>
</include>
</coverage>
</phpunit>
13 changes: 13 additions & 0 deletions tests/e2e/Stream_Wrapper_Execution/src/FinalClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Stream_Wrapper_Execution;

final class FinalClass
{
public function get(): int
{
return 1;
}
}
18 changes: 18 additions & 0 deletions tests/e2e/Stream_Wrapper_Execution/src/SourceClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Stream_Wrapper_Execution;

class SourceClass
{
private $finalClass;

public function __construct(FinalClass $finalClass)
{
$this->finalClass = $finalClass;
}

public function getOne(): int
{
return $this->finalClass->get();
}
}
37 changes: 37 additions & 0 deletions tests/e2e/Stream_Wrapper_Execution/tests/SourceClassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Stream_Wrapper_Execution\Test;

use Stream_Wrapper_Execution\FinalClass;
use Stream_Wrapper_Execution\SourceClass;
use PHPUnit\Framework\TestCase;
use DG\BypassFinals;

class SourceClassTest extends TestCase
{
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();

BypassFinals::enable();
}


public function test_returns_one()
{
$sourceClass = new SourceClass(new FinalClass());

$this->assertSame(1, $sourceClass->getOne());
}

public function test_final_class_can_be_mocked()
{
$mock = $this->createMock(FinalClass::class);

$mock->expects(self::once())->method('get')->willReturn(1);

$sourceClass = new SourceClass($mock);

self::assertSame(1, $sourceClass->getOne());
}
}

0 comments on commit cac814f

Please sign in to comment.