Permalink
Browse files

Started providing tests, added Travis and Cache

Started basic support for cache #13
Added Travis CI support
Started adding some basic testing
  • Loading branch information...
1 parent 70c0cfb commit 0d496f0318816cd135f06d7aec4cc13e9b0e7c28 @simensen simensen committed Feb 8, 2012
View
@@ -0,0 +1,15 @@
+language: php
+
+php:
+ - 5.3.2
+ - 5.3
+ - 5.4
+
+before_script:
+ - pyrus channel-discover pear.php-tools.net
+ - pyrus install http://pear.php-tools.net/get/vfsStream-0.11.1.tgz
+ - phpenv rehash
+ - wget -nc http://getcomposer.org/composer.phar
+ - php composer.phar install
+
+script: phpunit --coverage-text
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit colors="true" bootstrap="tests/bootstrap.php">
+ <testsuites>
+ <testsuite name="Sculpin Test Suite">
+ <directory>./tests/sculpin/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./src/sculpin/</directory>
+ <exclude>
+ <directory>./src/sculpin/*/resources</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>
View
@@ -156,6 +156,7 @@ public function __construct(Configuration $configuration, EventDispatcher $event
if ($this->sourceIsProjectRoot()) {
$this->exclude('sculpin.yml*');
$this->exclude($this->configuration->get('destination').'/**');
+ $this->exclude($this->configuration->get('cache').'/**');
}
}
@@ -586,7 +587,7 @@ public function deriveSourceFileFormatter(SourceFile $sourceFile)
}
return $this->defaultFormatter;
}
-
+
/**
* Finder
* @return \Symfony\Component\Finder\Finder
@@ -597,6 +598,52 @@ public function finder()
}
/**
+ * Path to where cache should be stored
+ * @return string
+ */
+ protected function cachePath()
+ {
+ return $this->configuration->getPath('cache');
+ }
+
+ /**
+ * Path to where cache should be stored for a specificy directory
+ * @return string
+ */
+ protected function cachePathFor($directory)
+ {
+ return $this->cachePath().'/'.$directory;
+ }
+
+ /**
+ * Prepare cache for directory
+ * @return string
+ */
+ public function prepareCacheFor($directory)
+ {
+ $cacheDirectory = $this->cachePathFor($directory);
+ Util::RECURSIVE_MKDIR($cacheDirectory);
+ return $cacheDirectory;
+ }
+
+ /**
+ * Clear cache for directory
+ */
+ public function clearCacheFor($directory)
+ {
+ $cacheDirectory = $this->cachePathFor($directory);
+ Util::RECURSIVE_UNLINK($cacheDirectory, true);
+ }
+
+ /**
+ * Clear cache
+ */
+ public function clearCache()
+ {
+ Util::RECURSIVE_UNLINK($this->cachePath(), true);
+ }
+
+ /**
* Is the source folder the project root?
*
* Useful for determining whether or not certain files should be
View
@@ -66,4 +66,27 @@ static public function RECURSIVE_MKDIR($path)
}
return true;
}
+
+ /**
+ * Recursively remove files and directories from a path
+ * @param string $path
+ * @param boolean $onlyRemoveChildren
+ */
+ static public function RECURSIVE_UNLINK($path, $onlyRemoveChildren = false)
+ {
+ if (is_link($path) or is_file($path)) {
+ unlink($path);
+ return;
+ }
+ if (is_dir($path)) {
+ foreach (scandir($path) as $leaf) {
+ if ($leaf != "." && $leaf != "..") {
+ self::RECURSIVE_UNLINK($path.'/'.$leaf);
+ }
+ }
+ if (!$onlyRemoveChildren) {
+ rmdir($path);
+ }
+ }
+ }
}
@@ -35,6 +35,7 @@ disabled_core_bundles: []
source: source
destination: public
+cache: cache
# Fallack permalink strategy
permalink: pretty
@@ -18,3 +18,6 @@ source: .
# Location of the generated output.
destination: ./_site
+
+# Location of cached content.
+cache: ./.cache
View
@@ -0,0 +1,12 @@
+<?php
+/*
+ * This file is a part of GitHub Gist Twig Extension.
+ *
+ * (c) Dragonfly Development Inc.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+$loader = require dirname(__DIR__).'/vendor/.composer/autoload.php';
+$loader->add('sculpin\\tests\\sculpin', 'tests');
@@ -0,0 +1,67 @@
+<?php
+
+/*
+ * This file is a part of Sculpin.
+ *
+ * (c) Dragonfly Development Inc.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace sculpin\tests\core;
+
+/**
+ * These tests require the vfsStream mock filesystem driver
+ * from https://github.com/mikey179/vfsStream/
+ */
+require_once 'vfsStream/vfsStream.php';
+
+use sculpin\Sculpin;
+
+class CacheTest extends \PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ $this->root = \vfsStream::setup('cacheRoot', null, array('bar' => array('a' => 'A', 'b' => 'B', 'c' => 'C')));
+ $configuration = $this->getMock('sculpin\configuration\Configuration', array('get', 'getPath'), array(array()));
+ $configuration
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnValueMap(array(
+ array('exclude', array()),
+ array('core_exclude', array()),
+ array('source_is_project_root', false),
+ )));
+ $configuration
+ ->expects($this->once())
+ ->method('getPath')
+ ->with('cache')
+ ->will($this->returnValue(\vfsStream::url('cacheRoot')));
+ $this->sculpin = new Sculpin($configuration);
+ }
+
+ public function testPrepareCacheFor()
+ {
+ $this->assertFalse($this->root->hasChild('foo'), 'The "foo" child should not exist yet');
+ $this->sculpin->prepareCacheFor('foo');
+ $this->assertTrue($this->root->hasChild('foo'), 'The "foo" child should now exist');
+ }
+
+ public function testClearCacheFor()
+ {
+ $this->assertTrue($this->root->hasChild('bar'), 'The "bar" child should exist');
+ $this->assertTrue($this->root->getChild('bar')->hasChild('a'), 'The "a" child of "bar" should exist');
+ $this->sculpin->clearCacheFor('bar');
+ $this->assertTrue($this->root->hasChild('bar'), 'The "bar" child should still existing');
+ $this->assertFalse($this->root->getChild('bar')->hasChild('a'), 'The "a" child of "bar" should no longer exist');
+ }
+
+ public function testClearCache()
+ {
+ $this->assertTrue($this->root->hasChild('bar'), 'The "bar" child should exist');
+ $this->assertTrue($this->root->getChild('bar')->hasChild('a'), 'The "a" child of "bar" should exist');
+ $this->sculpin->clearCache();
+ $this->assertFalse($this->root->hasChild('bar'), 'The "bar" child should no longer exist');
+ }
+}

0 comments on commit 0d496f0

Please sign in to comment.