Skip to content

Commit

Permalink
[core] Code cleanup on test files (#1570)
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 authored Apr 1, 2021
1 parent edb315f commit b4ea7c0
Show file tree
Hide file tree
Showing 81 changed files with 250 additions and 267 deletions.
9 changes: 5 additions & 4 deletions tests/Phing/IntrospectionHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
use Phing\Test\Support\IHCreatorFail3;
use Phing\Test\Support\IHProjectComponent;
use Phing\Type\FileSet;
use PHPUnit\Framework\TestCase;

/**
* testcases for phing.IntrospectionHelper.
*
* @author Hans Lellelid <hans@xmpl.org> (Phing)
* @author Stefan Bodewig <stefan.bodewig@epost.de> (Ant)
*/
class IntrospectionHelperTest extends \PHPUnit\Framework\TestCase
class IntrospectionHelperTest extends TestCase
{
/** @var Project */
private $p;
Expand Down Expand Up @@ -78,19 +79,19 @@ public function testSupportsCharactersAdders()
public function testElementCreators()
{
try {
$ihtmp = IntrospectionHelper::getHelper(IHCreatorFail1::class);
IntrospectionHelper::getHelper(IHCreatorFail1::class);
$this->fail('create cannot take param');
} catch (BuildException $be) {
}

try {
$ihtmp = IntrospectionHelper::getHelper(IHCreatorFail2::class);
IntrospectionHelper::getHelper(IHCreatorFail2::class);
$this->fail('no class hint for add');
} catch (BuildException $be) {
}

try {
$ihtmp = IntrospectionHelper::getHelper(IHCreatorFail3::class);
IntrospectionHelper::getHelper(IHCreatorFail3::class);
$this->fail('no class hint for addconfigured');
} catch (BuildException $be) {
}
Expand Down
33 changes: 17 additions & 16 deletions tests/Phing/Io/AbstractWinFileSystemTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

use Phing\Io\File;
use Phing\Io\FileSystem;
use PHPUnit\Framework\TestCase;

/**
* @author Daniel Holmes
*/
abstract class AbstractWinFileSystemTestCase extends \PHPUnit\Framework\TestCase
abstract class AbstractWinFileSystemTestCase extends TestCase
{
/**
* @var FileSystem
Expand Down Expand Up @@ -54,14 +55,14 @@ public function testGetPathSeparatorReturnsCorrect()
* @param string $expected
* @param string $path
*/
public function testNormalise($expected, $path)
public function testNormalise(string $expected, string $path)
{
$normalisedPath = $this->fs->normalize($path);

$this->assertSame($expected, $normalisedPath);
}

public function normaliseDataProvider()
public function normaliseDataProvider(): array
{
return [
'alreadyNormal' => ['C:\\My Files\\file.txt', 'C:\\My Files\\file.txt'],
Expand All @@ -79,17 +80,17 @@ public function normaliseDataProvider()
/**
* @dataProvider prefixLengthDataPRovider
*
* @param int $expected
* @param int $expected
* @param string $pathname
*/
public function testPrefixLength($expected, $pathname)
public function testPrefixLength(int $expected, string $pathname)
{
$length = $this->fs->prefixLength($pathname);

$this->assertSame($expected, $length);
}

public function prefixLengthDataProvider()
public function prefixLengthDataProvider(): array
{
return [
'absoluteLocal' => [3, 'D:\\My Files\\file.txt'],
Expand All @@ -110,14 +111,14 @@ public function prefixLengthDataProvider()
* @param string $parent
* @param string $child
*/
public function testResolve($expected, $parent, $child)
public function testResolve(string $expected, string $parent, string $child)
{
$resolved = $this->fs->resolve($parent, $child);

$this->assertSame($expected, $resolved);
}

public function resolveDataProvider()
public function resolveDataProvider(): array
{
return [
'emptyParent' => ['My Files\\file.txt', '', 'My Files\\file.txt'],
Expand All @@ -136,7 +137,7 @@ public function resolveDataProvider()
* @param string $path
* @param string $prefix
*/
public function testResolveFile($expected, $path, $prefix)
public function testResolveFile(string $expected, string $path, string $prefix)
{
$file = $this->getMockBuilder(File::class)->disableOriginalConstructor()->getMock();
$file->expects($this->any())->method('getPath')->will($this->returnValue($path));
Expand All @@ -147,7 +148,7 @@ public function testResolveFile($expected, $path, $prefix)
$this->assertSame($expected, $resolved);
}

public function resolveFileDataProvider()
public function resolveFileDataProvider(): array
{
$cwd = getcwd();
$driveLetter = '';
Expand Down Expand Up @@ -195,14 +196,14 @@ public function testGetDefaultParent()
* @param string $expected
* @param string $path
*/
public function testFromURIPath($expected, $path)
public function testFromURIPath(string $expected, string $path)
{
$resultPath = $this->fs->fromURIPath($path);

$this->assertSame($expected, $resultPath);
}

public function fromURIPathDataProvider()
public function fromURIPathDataProvider(): array
{
return [
'singleLetter' => ['f', 'f'],
Expand All @@ -216,11 +217,11 @@ public function fromURIPathDataProvider()
/**
* @dataProvider isAbsoluteDataProvider
*
* @param bool $expected
* @param bool $expected
* @param string $path
* @param int $prefix
* @param int $prefix
*/
public function testIsAbsolute($expected, $path, $prefix)
public function testIsAbsolute(bool $expected, string $path, int $prefix)
{
$file = $this->getMockBuilder(File::class)->disableOriginalConstructor()->getMock();
$file->expects($this->any())->method('getPath')->will($this->returnValue($path));
Expand All @@ -231,7 +232,7 @@ public function testIsAbsolute($expected, $path, $prefix)
$this->assertSame($expected, $is);
}

public function isAbsoluteDataProvider()
public function isAbsoluteDataProvider(): array
{
return [
// Doesn't work for my current version of phpunit
Expand Down
3 changes: 2 additions & 1 deletion tests/Phing/Io/FileOutputStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
use Phing\Io\FileOutputStream;
use Phing\Io\FileSystem;
use Phing\Io\IOException;
use PHPUnit\Framework\TestCase;

/**
* Unit test for FileOutputStream.
*
* @author Hans Lellelid <hans@xmpl.org>
*/
class FileOutputStreamTest extends \PHPUnit\Framework\TestCase
class FileOutputStreamTest extends TestCase
{
/**
* @var FileOutputStream
Expand Down
7 changes: 1 addition & 6 deletions tests/Phing/Io/FileParserFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class FileParserFactoryTest extends TestCase
*/
private $objectToTest;

/**
* @var string
*/
private $iniFileStub;

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -73,7 +68,7 @@ public function testCreateParser($parserName, $expectedType)
/**
* @return array
*/
public function parserTypeProvider()
public function parserTypeProvider(): array
{
return [
['properties', IniFileParser::class],
Expand Down
12 changes: 7 additions & 5 deletions tests/Phing/Io/FileSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
use Phing\Io\UnixFileSystem;
use Phing\Io\WindowsFileSystem;
use Phing\Phing;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
* Unit test for FileSystem.
*/
class FileSystemTest extends \PHPUnit\Framework\TestCase
class FileSystemTest extends TestCase
{
private $oldFsType = '';

Expand Down Expand Up @@ -62,6 +63,7 @@ public function testGetFileSystemWithUnknownTypeKeyThrowsException()
*
* @param mixed $expectedFileSystemClass
* @param mixed $fsTypeKey
* @throws IOException
*/
public function testGetFileSystemReturnsCorrect($expectedFileSystemClass, $fsTypeKey)
{
Expand All @@ -74,7 +76,7 @@ public function testGetFileSystemReturnsCorrect($expectedFileSystemClass, $fsTyp
$this->assertInstanceOf($expectedFileSystemClass, $system);
}

public function fileSystemMappingsDataProvider()
public function fileSystemMappingsDataProvider(): array
{
return [
[UnixFileSystem::class, 'UNIX'],
Expand All @@ -86,21 +88,21 @@ public function testWhichFailsNonStringExecutable()
{
$fs = FileSystem::getFileSystem();
$path = $fs->which(42);
$this->assertEquals($path, false);
$this->assertEquals(false, $path);
}

public function testWhichFailsDueToUnusualExecutableName()
{
$fs = FileSystem::getFileSystem();
$path = $fs->which('tasword.bin');
$this->assertEquals($path, false);
$this->assertEquals(false, $path);
}

public function testWhichHinkyExecutableNameWithSeparator()
{
$fs = FileSystem::getFileSystem();
$path = $fs->which('zx:\tasword.bin');
$this->assertEquals($path, false);
$this->assertEquals(false, $path);
}

public function testListContentsWithNumericName()
Expand Down
7 changes: 5 additions & 2 deletions tests/Phing/Io/IniFileParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
use Phing\Io\File;
use Phing\Io\IniFileParser;
use Phing\Io\IOException;
use PHPUnit\Framework\TestCase;

/**
* @author Fabian Grutschus <fabian.grutschus@unister.de>
* @requires OS ^(?:(?!Win).)*$
*/
class IniFileParserTest extends \PHPUnit\Framework\TestCase
class IniFileParserTest extends TestCase
{
private $parser;
private $root;
Expand All @@ -47,6 +48,8 @@ protected function setUp(): void
*
* @param mixed $data
* @param mixed $expected
* @throws IOException
* @throws IOException
*/
public function testParseFile($data, $expected)
{
Expand All @@ -72,7 +75,7 @@ public function testParseFileCouldntOpenFile()
/**
* @return array
*/
public function provideIniFiles()
public function provideIniFiles(): array
{
return [
[
Expand Down
3 changes: 2 additions & 1 deletion tests/Phing/Io/PhingFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Phing\Test\Io;

use Phing\Io\File;
use PHPUnit\Framework\TestCase;

/**
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Expand All @@ -21,7 +22,7 @@
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
class PhingFileTest extends \PHPUnit\Framework\TestCase
class PhingFileTest extends TestCase
{
/**
* @var File
Expand Down
11 changes: 6 additions & 5 deletions tests/Phing/Io/UnixFileSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
use Phing\Io\File;
use Phing\Io\FileSystem;
use Phing\Io\UnixFileSystem;
use PHPUnit\Framework\TestCase;

/**
* Unit test for UnixFileSystem.
*
* @author Michiel Rook <mrook@php.net>
*/
class UnixFileSystemTest extends \PHPUnit\Framework\TestCase
class UnixFileSystemTest extends TestCase
{
/**
* @var FileSystem
Expand All @@ -50,21 +51,21 @@ public function testCompare()
$f1 = new File(__FILE__);
$f2 = new File(__FILE__);

$this->assertEquals($this->fs->compare($f1, $f2), 0);
$this->assertEquals(0, $this->fs->compare($f1, $f2));
}

public function testHomeDirectory1()
{
$this->assertEquals($this->fs->normalize('~/test'), '~/test');
$this->assertEquals('~/test', $this->fs->normalize('~/test'));
}

public function testHomeDirectory2()
{
$this->assertEquals($this->fs->normalize('/var/~test'), '/var/~test');
$this->assertEquals('/var/~test', $this->fs->normalize('/var/~test'));
}

public function testHomeDirectory3()
{
$this->assertEquals($this->fs->normalize('~test'), '~test');
$this->assertEquals('~test', $this->fs->normalize('~test'));
}
}
2 changes: 1 addition & 1 deletion tests/Phing/Io/WindowsFileSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
class WindowsFileSystemTest extends AbstractWinFileSystemTestCase
{
protected function createFileSystem()
protected function createFileSystem(): WindowsFileSystem
{
return new WindowsFileSystem();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Phing/Io/YamlFileParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
use Phing\Io\FileUtils;
use Phing\Io\IOException;
use Phing\Io\YamlFileParser;
use PHPUnit\Framework\TestCase;

/**
* Unit test for YamlFileParser.
*
* @author Mike Lohmann <mike.lohmann@deck36.de>
*/
class YamlFileParserTest extends \PHPUnit\Framework\TestCase
class YamlFileParserTest extends TestCase
{
/**
* @var FileParserInterface
Expand Down
2 changes: 1 addition & 1 deletion tests/Phing/Listener/DefaultLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testFormatTime($seconds, string $expectedText)
$this->assertSame($formattedText, $expectedText);
}

public function formatTimeProvider()
public function formatTimeProvider(): array
{
return [
[0.0005, '0.0005 seconds'],
Expand Down
Loading

0 comments on commit b4ea7c0

Please sign in to comment.