/** * @dataProvider getReplaceSpacesDataProvider * @param string $input * @param string $expect */ public function testReplaceInvalidLines($input, $expect) { $map = ['\\r' => "\r", '\\n' => "\n"]; $input = str_replace("\n", '', $input); $expect = str_replace("\n", '', $expect); $input = strtr($input, $map); $expect = strtr($expect, $map); \Tests\Funivan\Cs\BaseTestCase::assertFixer(new LineEndingFixer(), $input, $expect); }
/** * @param FileTool $tool * @param string $input * @param string $expect */ public static function assertFixer(FileTool $tool, $input, $expect) { $path = BaseTestCase::createTempFile($input); $file = new File($path, File::STATUS_UNKNOWN); self::assertNotEmpty($file->getContent()->get()); # content is loaded, we can delete source file unlink($path); $tool->process($file, new Report()); $output = $file->getContent()->get(); static::assertEquals($expect, $output); }
/** * @dataProvider getReturnTypeDataProvider * @param $input * @param $expect * @param array $delimiters */ public function testReturn($input, $expect, array $delimiters = []) { if (self::$isAvailable === false) { static::markTestSkipped('Tests can only be run on php 7.0 or greater'); return; } $fixer = new ReturnTypeFormatFixer(); if (isset($delimiters[0])) { $fixer->setBefore($delimiters[0]); } if (isset($delimiters[1])) { $fixer->setAfter($delimiters[1]); } BaseTestCase::assertFixer($fixer, $input, $expect); }
/** * @param string $code * @param string $tool */ protected static function assertValidPhpCode($code, $tool) { $path = BaseTestCase::createTempFile($code); $result = shell_exec('php -l ' . $path); $exitCode = trim(shell_exec('php ' . $path . ' > /dev/null 2>&1 && echo $?')); unlink($path); $isValid = strpos($result, 'No syntax errors detected') === 0; static::assertTrue($isValid, 'Invalid code syntax:' . $code); static::assertEquals(0, $exitCode, 'Invalid code. Exit status ' . $exitCode . '. Tool: ' . $tool . ' Code:' . $code); }
/** * @dataProvider getReplaceSpacesDataProvider * @param string $input * @param string $expect */ public function testReplaceSpaces($input, $expect) { $input = str_replace('.', ' ', $input); $expect = str_replace('.', ' ', $expect); BaseTestCase::assertFixer(new SpacesInEmptyLinesFixer(), $input, $expect); }