Skip to content

Commit

Permalink
Move PHP_CodeCoverage_Util::getDirectory() to PHP_CodeCoverage_Report…
Browse files Browse the repository at this point in the history
…_HTML and make it non-static.
  • Loading branch information
sebastianbergmann committed Aug 12, 2012
1 parent 713eeaf commit 7662a78
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 87 deletions.
30 changes: 29 additions & 1 deletion PHP/CodeCoverage/Report/HTML.php
Expand Up @@ -129,7 +129,7 @@ public function __construct($title = '', $charset = 'UTF-8', $yui = TRUE, $highl
*/
public function process(PHP_CodeCoverage $coverage, $target)
{
$target = PHP_CodeCoverage_Util::getDirectory($target);
$target = $this->getDirectory($target);
$report = $coverage->getReport();
unset($coverage);

Expand Down Expand Up @@ -210,4 +210,32 @@ protected function copyFiles($target)
copy($this->templatePath . $file, $target . $file);
}
}

/**
* @param string $directory
* @return string
* @throws PHP_CodeCoverage_Exception
* @since Method available since Release 1.2.0
*/
protected function getDirectory($directory)
{
if (substr($directory, -1, 1) != DIRECTORY_SEPARATOR) {
$directory .= DIRECTORY_SEPARATOR;
}

if (is_dir($directory)) {
return $directory;
}

if (mkdir($directory, 0777, TRUE)) {
return $directory;
}

throw new PHP_CodeCoverage_Exception(
sprintf(
'Directory "%s" does not exist.',
$directory
)
);
}
}
27 changes: 0 additions & 27 deletions PHP/CodeCoverage/Util.php
Expand Up @@ -98,33 +98,6 @@ class PHP_CodeCoverage_Util
*/
protected static $ids = array();

/**
* @param string $directory
* @return string
* @throws PHP_CodeCoverage_Exception
*/
public static function getDirectory($directory)
{
if (substr($directory, -1, 1) != DIRECTORY_SEPARATOR) {
$directory .= DIRECTORY_SEPARATOR;
}

if (is_dir($directory)) {
return $directory;
}

if (mkdir($directory, 0777, TRUE)) {
return $directory;
}

throw new PHP_CodeCoverage_Exception(
sprintf(
'Directory "%s" does not exist.',
$directory
)
);
}

/**
* Returns the files and lines a test method wants to cover.
*
Expand Down
59 changes: 0 additions & 59 deletions Tests/PHP/CodeCoverage/UtilTest.php
Expand Up @@ -44,10 +44,6 @@
* @since File available since Release 1.0.0
*/

if (stream_resolve_include_path('vfsStream/vfsStream.php')) {
require_once 'vfsStream/vfsStream.php';
}

if (!defined('TEST_FILES_PATH')) {
define(
'TEST_FILES_PATH',
Expand Down Expand Up @@ -99,15 +95,6 @@
*/
class PHP_CodeCoverage_UtilTest extends PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('vfsStream')) {
$this->markTestSkipped('vfsStream is not available.');
}

vfsStream::setup('UtilTest');
}

/**
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
Expand Down Expand Up @@ -248,52 +235,6 @@ public function testGetLinesToBeIgnored2()
);
}

/**
* @covers PHP_CodeCoverage_Util::getDirectory
*/
public function testGetDirectory()
{
if (!class_exists('vfsStream')) {
$this->markTestSkipped('vfsStream is not installed');
}

$this->assertEquals(
vfsStream::url('UtilTest') . '/',
PHP_CodeCoverage_Util::getDirectory(vfsStream::url('UtilTest'))
);
}

/**
* @covers PHP_CodeCoverage_Util::getDirectory
*/
public function testGetDirectory2()
{
if (!class_exists('vfsStream')) {
$this->markTestSkipped('vfsStream is not installed');
}

PHP_CodeCoverage_Util::getDirectory(
vfsStream::url('UtilTest') . '/report'
);

$this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('report'));
}

/**
* @covers PHP_CodeCoverage_Util::getDirectory
* @expectedException PHP_CodeCoverage_Exception
*/
public function testGetDirectory3()
{
if (!class_exists('vfsStream')) {
$this->markTestSkipped('vfsStream is not installed');
}

PHP_CodeCoverage_Util::getDirectory(
vfsStream::url('/not/existing/path')
);
}

/**
* @covers PHP_CodeCoverage_Util::percent
*/
Expand Down

0 comments on commit 7662a78

Please sign in to comment.