Skip to content

Commit

Permalink
Fixed E2ETest::test_it_runs_an_e2e_test_with_success() for win (#607)
Browse files Browse the repository at this point in the history
* Fixed test execution of E2ETest::test_it_runs_an_e2e_test_with_success() under windows.

* Fixed test execution of logging tests

* Wrong branch

* Fixed ci

* Fixed test execution of some more logger

* Fixed behavior for checked in fixture files

* Switched to nowdoc

* Used str_replace also

* Fixed ci

* pretty fix
  • Loading branch information
siad007 authored and maks-rafalko committed Jan 14, 2019
1 parent e35a823 commit 153cd57
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/Logger/DebugFileLogger.php
Expand Up @@ -85,7 +85,7 @@ private function convertProcess(array $processes, string $headlinePrefix): strin
$logParts[] = 'Line ' . $mutantProcess->getOriginalStartingLine();
}

return implode("\n", $logParts) . "\n";
return implode(PHP_EOL, $logParts) . PHP_EOL;
}

private function getHeadlineParts(string $headlinePrefix): array
Expand Down
2 changes: 1 addition & 1 deletion src/Logger/FileLogger.php
Expand Up @@ -95,7 +95,7 @@ public function __construct(
public function log(): void
{
try {
$this->fs->dumpFile($this->logFilePath, implode("\n", $this->getLogLines()));
$this->fs->dumpFile($this->logFilePath, implode(PHP_EOL, $this->getLogLines()));
} catch (IOException $e) {
$this->output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Logger/PerMutatorLogger.php
Expand Up @@ -53,7 +53,7 @@ protected function getLogLines(): array

$logs = [];

$logs[] = "# Effects per Mutator\n";
$logs[] = '# Effects per Mutator' . PHP_EOL;

$logs[] = '| Mutator | Mutations | Killed | Escaped | Errors | Timed Out | MSI | Covered MSI |';
$logs[] = '| ------- | --------- | ------ | ------- |------- | --------- | --- | ----------- |';
Expand Down
2 changes: 1 addition & 1 deletion src/Logger/TextFileLogger.php
Expand Up @@ -80,7 +80,7 @@ private function getLogParts(array $processes, string $headlinePrefix): string
}
}

return implode("\n", $logParts);
return implode(PHP_EOL, $logParts);
}

private function getHeadlineParts(string $headlinePrefix): array
Expand Down
2 changes: 1 addition & 1 deletion src/StreamWrapper/IncludeInterceptor.php
Expand Up @@ -102,7 +102,7 @@ public function stream_open($path, $mode, $options)

if ($including) {
if ($path === self::$intercept || realpath($path) === self::$intercept) {
$this->fp = fopen(self::$replacement, 'rb');
$this->fp = fopen(self::$replacement, 'r');
self::enable();

return true;
Expand Down
2 changes: 1 addition & 1 deletion tests/Config/InfectionConfigTest.php
Expand Up @@ -37,9 +37,9 @@

use Infection\Config\InfectionConfig;
use Infection\Tests\Fixtures\StubMutator;
use function Infection\Tests\normalizePath as p;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use function Infection\Tests\normalizePath as p;

/**
* @internal
Expand Down
4 changes: 2 additions & 2 deletions tests/Config/ValueProvider/AbstractBaseProviderTest.php
Expand Up @@ -54,7 +54,7 @@ protected function getQuestionHelper(): QuestionHelper

protected function getInputStream(string $input)
{
$stream = fopen('php://memory', 'r+b', false);
$stream = fopen('php://memory', 'r+', false);
fwrite($stream, $input);
rewind($stream);

Expand All @@ -63,7 +63,7 @@ protected function getInputStream(string $input)

protected function createOutputInterface(): StreamOutput
{
return new StreamOutput(fopen('php://memory', 'r+b', false));
return new StreamOutput(fopen('php://memory', 'r+', false));
}

protected function createStreamableInputInterfaceMock($stream = null, $interactive = true)
Expand Down
Expand Up @@ -39,9 +39,9 @@
use Infection\Config\ValueProvider\PhpUnitCustomExecutablePathProvider;
use Infection\Finder\Exception\FinderException;
use Infection\Finder\TestFrameworkFinder;
use function Infection\Tests\normalizePath as p;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Exception\RuntimeException as SymfonyRuntimeException;
use function Infection\Tests\normalizePath as p;

/**
* @internal
Expand Down
5 changes: 4 additions & 1 deletion tests/Console/E2ETest.php
Expand Up @@ -172,7 +172,10 @@ private function runOnE2EFixture($path): string
$this->markTestSkipped('Saved golden output');
}

$this->assertFileEquals('expected-output.txt', 'infection.log', sprintf('%s/expected-output.txt is not same as infection.log (if that is OK, run GOLDEN=1 vendor/bin/phpunit)', getcwd()));
$expected = file_get_contents('expected-output.txt');
$expected = str_replace("\n", PHP_EOL, $expected);

$this->assertStringEqualsFile('infection.log', $expected, sprintf('%s/expected-output.txt is not same as infection.log (if that is OK, run GOLDEN=1 vendor/bin/phpunit)', getcwd()));

return $output;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Finder/LocatorTest.php
Expand Up @@ -37,9 +37,9 @@

use Infection\Finder\Exception\LocatorException;
use Infection\Finder\Locator;
use function Infection\Tests\normalizePath as p;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use function Infection\Tests\normalizePath as p;

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion tests/Finder/TestFrameworkFinderTest.php
Expand Up @@ -38,10 +38,10 @@
use Infection\Finder\Exception\FinderException;
use Infection\Finder\TestFrameworkFinder;
use Infection\TestFramework\TestFrameworkTypes;
use function Infection\Tests\normalizePath;
use Infection\Utils\TmpDirectoryCreator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use function Infection\Tests\normalizePath;

/**
* @internal
Expand Down
26 changes: 16 additions & 10 deletions tests/Logger/DebugFileLoggerTest.php
Expand Up @@ -56,10 +56,7 @@ public function test_it_logs_correctly_with_no_mutations(): void
$logFilePath = sys_get_temp_dir() . '/foo.txt';
$calculator = new MetricsCalculator();
$output = $this->createMock(OutputInterface::class);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
<<<'TXT'
$content = <<<'TXT'
Total: 0
Killed mutants:
===============
Expand All @@ -81,7 +78,13 @@ public function test_it_logs_correctly_with_no_mutations(): void
====================
TXT
TXT;
$content = str_replace("\n", PHP_EOL, $content);

$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
$content
);

$debugFileLogger = new DebugFileLogger($output, $logFilePath, $calculator, $fs, false, false);
Expand All @@ -93,10 +96,7 @@ public function test_it_log_correctly_with_mutations(): void
$logFilePath = sys_get_temp_dir() . '/foo.txt';
$calculator = $this->createFilledMetricsCalculator();
$output = $this->createMock(OutputInterface::class);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
<<<'TXT'
$content = <<<'TXT'
Total: 12
Killed mutants:
===============
Expand Down Expand Up @@ -154,7 +154,13 @@ public function test_it_log_correctly_with_mutations(): void
====================
TXT
TXT;
$content = str_replace("\n", PHP_EOL, $content);

$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
$content
);

$debugFileLogger = new DebugFileLogger($output, $logFilePath, $calculator, $fs, false, false);
Expand Down
17 changes: 11 additions & 6 deletions tests/Logger/PerMutatorLoggerTest.php
Expand Up @@ -53,18 +53,23 @@ final class PerMutatorLoggerTest extends TestCase
{
public function test_it_correctly_build_log_lines(): void
{
$content = <<<'TXT'
# Effects per Mutator
| Mutator | Mutations | Killed | Escaped | Errors | Timed Out | MSI | Covered MSI |
| ------- | --------- | ------ | ------- |------- | --------- | --- | ----------- |
| For_ | 15 | 10 | 0 | 0 | 0 | 66| 100|
| PregQuote | 5 | 0 | 0 | 0 | 0 | 0| 0|
TXT;
$content = str_replace("\n", PHP_EOL, $content);

$output = $this->createMock(OutputInterface::class);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())
->method('dumpFile')
->with(
sys_get_temp_dir() . '/fake-file.md',
"# Effects per Mutator\n" .
"\n" .
"| Mutator | Mutations | Killed | Escaped | Errors | Timed Out | MSI | Covered MSI |\n" .
"| ------- | --------- | ------ | ------- |------- | --------- | --- | ----------- |\n" .
"| For_ | 15 | 10 | 0 | 0 | 0 | 66| 100|\n" .
'| PregQuote | 5 | 0 | 0 | 0 | 0 | 0| 0|'
$content
);

$perMutatorLogger = new PerMutatorLogger(
Expand Down
26 changes: 16 additions & 10 deletions tests/Logger/SummaryFileLoggerTest.php
Expand Up @@ -85,17 +85,20 @@ public function test_it_logs_the_correct_lines_with_no_mutations(): void
$logFilePath = $this->tmpDir . '/foo.txt';
$calculator = new MetricsCalculator();
$output = $this->createMock(OutputInterface::class);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
<<<'TXT'
$content = <<<'TXT'
Total: 0
Killed: 0
Errored: 0
Escaped: 0
Timed Out: 0
Not Covered: 0
TXT
TXT;
$content = str_replace("\n", PHP_EOL, $content);

$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
$content
);

$debugFileLogger = new SummaryFileLogger($output, $logFilePath, $calculator, $fs, false, false);
Expand All @@ -113,17 +116,20 @@ public function test_it_logs_the_correct_lines_with_mutations(): void
$calculator->expects($this->once())->method('getTimedOutCount')->willReturn(2);
$calculator->expects($this->once())->method('getNotCoveredByTestsCount')->willReturn(0);
$output = $this->createMock(OutputInterface::class);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
<<<'TXT'
$content = <<<'TXT'
Total: 6
Killed: 8
Errored: 7
Escaped: 30216
Timed Out: 2
Not Covered: 0
TXT
TXT;
$content = str_replace("\n", PHP_EOL, $content);

$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
$content
);

$debugFileLogger = new SummaryFileLogger($output, $logFilePath, $calculator, $fs, false, false);
Expand Down
50 changes: 31 additions & 19 deletions tests/Logger/TextFileLoggerTest.php
Expand Up @@ -58,10 +58,8 @@ public function test_it_logs_correctly_with_no_mutations_and_no_debug_verbosity(
$logFilePath = sys_get_temp_dir() . '/foo.txt';
$calculator = new MetricsCalculator();
$output = $this->createMock(OutputInterface::class);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
<<<'TXT'

$content = <<<'TXT'
Escaped mutants:
================
Expand All @@ -71,7 +69,13 @@ public function test_it_logs_correctly_with_no_mutations_and_no_debug_verbosity(
Not Covered mutants:
====================
TXT
TXT;
$content = str_replace("\n", PHP_EOL, $content);

$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
$content
);

$debugFileLogger = new TextFileLogger($output, $logFilePath, $calculator, $fs, false, false);
Expand All @@ -83,10 +87,7 @@ public function test_it_logs_correctly_with_no_mutations_and_debug_verbosity():
$logFilePath = sys_get_temp_dir() . '/foo.txt';
$calculator = new MetricsCalculator();
$output = $this->createMock(OutputInterface::class);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
<<<'TXT'
$content = <<<'TXT'
Escaped mutants:
================
Expand All @@ -102,7 +103,13 @@ public function test_it_logs_correctly_with_no_mutations_and_debug_verbosity():
Not Covered mutants:
====================
TXT
TXT;
$content = str_replace("\n", PHP_EOL, $content);

$fs = $this->createMock(Filesystem::class);
$fs->expects($this->once())->method('dumpFile')->with(
$logFilePath,
$content
);

$debugFileLogger = new TextFileLogger($output, $logFilePath, $calculator, $fs, true, false);
Expand All @@ -114,10 +121,7 @@ public function test_it_logs_correctly_with_mutations_and_no_debug_verbosity_and
$logFilePath = sys_get_temp_dir() . '/foo.txt';
$calculator = $this->createFilledMetricsCalculator();
$output = $this->createMock(OutputInterface::class);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->atMost(10))->method('dumpFile')->with(
$logFilePath,
<<<'TXT'
$content = <<<'TXT'
Escaped mutants:
================
Expand Down Expand Up @@ -175,7 +179,12 @@ public function test_it_logs_correctly_with_mutations_and_no_debug_verbosity_and
2) foo/bar:10 [M] For_
bin/foo/bar -c conf
Diff Diff
TXT
TXT;
$content = str_replace("\n", PHP_EOL, $content);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->atMost(10))->method('dumpFile')->with(
$logFilePath,
$content
);

$debugFileLogger = new TextFileLogger($output, $logFilePath, $calculator, $fs, false, true);
Expand All @@ -188,9 +197,7 @@ public function test_it_logs_correctly_with_mutations_and_debug_verbosity_and_no
$calculator = $this->createFilledMetricsCalculator();
$output = $this->createMock(OutputInterface::class);
$fs = $this->createMock(Filesystem::class);
$fs->expects($this->atMost(10))->method('dumpFile')->with(
$logFilePath,
<<<'TXT'
$content = <<<'TXT'
Escaped mutants:
================
Expand Down Expand Up @@ -276,7 +283,12 @@ public function test_it_logs_correctly_with_mutations_and_debug_verbosity_and_no
Diff Diff
TXT
TXT;

$content = str_replace("\n", PHP_EOL, $content);
$fs->expects($this->atMost(10))->method('dumpFile')->with(
$logFilePath,
$content
);

$debugFileLogger = new TextFileLogger($output, $logFilePath, $calculator, $fs, true, false);
Expand Down
2 changes: 1 addition & 1 deletion tests/StreamWrapper/IncludeInterceptorTest.php
Expand Up @@ -167,7 +167,7 @@ public function test_passthrough_file_methods_pass(): void

$tempnam = tempnam('', basename(__FILE__, 'php'));

$fp = fopen($tempnam, 'w+b');
$fp = fopen($tempnam, 'w+');
flock($fp, LOCK_EX);
fwrite($fp, 'test');
fseek($fp, 0);
Expand Down
Expand Up @@ -38,10 +38,10 @@
use Infection\TestFramework\PhpUnit\Config\Builder\InitialConfigBuilder;
use Infection\TestFramework\PhpUnit\Config\Path\PathReplacer;
use Infection\TestFramework\PhpUnit\Config\XmlConfigurationHelper;
use function Infection\Tests\normalizePath as p;
use Infection\Utils\TmpDirectoryCreator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use function Infection\Tests\normalizePath as p;

/**
* @internal
Expand Down
Expand Up @@ -40,10 +40,10 @@
use Infection\TestFramework\PhpUnit\Config\Builder\MutationConfigBuilder;
use Infection\TestFramework\PhpUnit\Config\Path\PathReplacer;
use Infection\TestFramework\PhpUnit\Config\XmlConfigurationHelper;
use function Infection\Tests\normalizePath as p;
use Infection\Utils\TmpDirectoryCreator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use function Infection\Tests\normalizePath as p;

/**
* @internal
Expand Down

0 comments on commit 153cd57

Please sign in to comment.