Skip to content

Commit

Permalink
Add coverage for changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdekker committed Jul 17, 2021
1 parent c8d6ba3 commit aa723b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 63 deletions.
35 changes: 27 additions & 8 deletions src/test/php/PHPMD/Baseline/ViolationBaselineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,42 @@ class ViolationBaselineTest extends TestCase
* @covers ::__construct
* @covers ::getRuleName
* @covers ::getFileName
* @covers ::getMethodName
*/
public function testAccessorsWithoutMethod()
public function testGetRuleName()
{
$violation = new ViolationBaseline('rule', 'foobar', null);
static::assertSame('rule', $violation->getRuleName());
static::assertSame('foobar', $violation->getFileName());
static::assertNull($violation->getMethodName());
}

/**
* Test the give file matches the baseline correctly
*
* @covers ::__construct
* @covers ::getMethodName
* @covers ::matches
* @return void
*/
public function testAccessorsWithMethod()
public function testMatchesWithMethod()
{
$violation = new ViolationBaseline('rule', 'foobar', 'method');
static::assertSame('method', $violation->getMethodName());
$violation = new ViolationBaseline('sniff', 'foobar.txt', 'method');
static::assertTrue($violation->matches('foobar.txt', 'method'));
static::assertTrue($violation->matches('/test/foobar.txt', 'method'));
static::assertFalse($violation->matches('foo.txt', 'method'));
static::assertFalse($violation->matches('foobar.txt', 'unknown'));
}

/**
* Test the give file matches the baseline correctly
*
* @covers ::__construct
* @covers ::matches
* @return void
*/
public function testMatchesWithoutMethod()
{
$violation = new ViolationBaseline('sniff', 'foobar.txt', null);
static::assertTrue($violation->matches('foobar.txt', null));
static::assertTrue($violation->matches('/test/foobar.txt', null));
static::assertFalse($violation->matches('foobar.txt', 'method'));
static::assertFalse($violation->matches('/test/unknown.txt', null));
}
}
12 changes: 0 additions & 12 deletions src/test/php/PHPMD/Renderer/RendererFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPMD\AbstractTest;
use PHPMD\Writer\StreamWriter;
use RuntimeException;

/**
* @coversDefaultClass \PHPMD\Renderer\RendererFactory
Expand All @@ -21,15 +20,4 @@ public function testCreateBaselineRendererSuccessfully()

static::assertSame($writer, $renderer->getWriter());
}

/**
* @covers ::createBaselineRenderer
* @expectedException RuntimeException
* @expectedExceptionMessage Unable to determine the realpath for
*/
public function testCreateBaselineRendererThrowsExceptionForInvalidStream()
{
$writer = new StreamWriter(STDOUT);
RendererFactory::createBaselineRenderer($writer);
}
}
6 changes: 5 additions & 1 deletion src/test/php/PHPMD/TextUI/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace PHPMD\TextUI;

use PHPMD\AbstractTest;
use PHPMD\Utility\Paths;

/**
* Test case for the {@link \PHPMD\TextUI\Command} class.
Expand Down Expand Up @@ -246,7 +247,7 @@ public function testMainGenerateBaseline()

static::assertSame(Command::EXIT_SUCCESS, $exitCode);
static::assertFileExists($temp);
static::assertContains($uri, file_get_contents($temp));
static::assertContains(Paths::getRelativePath(getcwd(), $uri), file_get_contents($temp));
}

/**
Expand All @@ -262,6 +263,9 @@ public function testMainUpdateBaseline()
{
$sourceTemp = self::createTempFileUri('ClassWithMultipleViolations.php');
$baselineTemp = self::createTempFileUri();
// set work directory to the temp dir
self::changeWorkingDirectory(dirname($baselineTemp));

copy(static::createResourceUriForTest('UpdateBaseline/ClassWithMultipleViolations.php'), $sourceTemp);
copy(static::createResourceUriForTest('UpdateBaseline/phpmd.baseline.xml'), $baselineTemp);

Expand Down
42 changes: 0 additions & 42 deletions src/test/php/PHPMD/Utility/PathsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,6 @@
*/
class PathsTest extends AbstractTest
{
/**
* @covers ::concat
*/
public function testConcatShouldConcatTwoPaths()
{
static::assertSame('/foo/bar', Paths::concat('/foo', '/bar'));
}

/**
* @covers ::concat
*/
public function testConcatShouldDeduplicateSlashes()
{
static::assertSame('/foo/bar', Paths::concat('/foo/', '/bar'));
}

/**
* @covers ::concat
*/
public function testConcatShouldForwardAllSlashes()
{
static::assertSame('/foo/bar/text.txt', Paths::concat('/foo\\', '/bar\\text.txt'));
}

/**
* @covers ::getRelativePath
*/
Expand All @@ -58,24 +34,6 @@ public function testGetRelativePathShouldNotSubtractOnInfixPath()
static::assertSame('/foo/bar/text.txt', Paths::getRelativePath('/bar', '/foo/bar/text.txt'));
}

/**
* @covers ::getAbsolutePath
* @expectedException RuntimeException
*/
public function testGetAbsolutePathShouldReturnNullForIrregularStream()
{
Paths::getAbsolutePath(fopen('php://stdout', 'wb'));
}

/**
* @covers ::getAbsolutePath
*/
public function testGetAbsolutePathShouldReturnPath()
{
$path = static::createResourceUriForTest('resource.txt');
static::assertSame(realpath($path), Paths::getAbsolutePath(fopen($path, 'rb')));
}

/**
* @covers ::getRealPath
*/
Expand Down

0 comments on commit aa723b7

Please sign in to comment.