Cleaned up old code and wrote more tests
Log class is fully tested, Dynamic class is nearly complete but I wanted to see what Travis would bark about regarding LESS and SASS
This commit is contained in:
parent
3fee938c2a
commit
bfa35794b5
4 changed files with 191 additions and 33 deletions
|
@ -150,17 +150,7 @@ class Dynamic extends Object
|
||||||
{
|
{
|
||||||
$reference = $original_reference;
|
$reference = $original_reference;
|
||||||
|
|
||||||
/**
|
// @todo LESS and SASS compiling should happen regardless of minification
|
||||||
* Disabled the sanity checks because I'm using LESS's @import for
|
|
||||||
* some hackery and it's not validating as true due to the imported
|
|
||||||
* file not being interrogated. Should be okay as minifying is now
|
|
||||||
* a subjective action that's turned on in the config due to the
|
|
||||||
* issues I had in production with it.
|
|
||||||
*
|
|
||||||
* if (is_writable($path)
|
|
||||||
* && (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename))
|
|
||||||
* && $this->config->pickles['minify'] === true)
|
|
||||||
*/
|
|
||||||
if ($this->config->pickles['minify'] === true)
|
if ($this->config->pickles['minify'] === true)
|
||||||
{
|
{
|
||||||
// Compiles LESS & SASS to CSS before minifying
|
// Compiles LESS & SASS to CSS before minifying
|
||||||
|
@ -203,10 +193,6 @@ class Dynamic extends Object
|
||||||
{
|
{
|
||||||
$reference = $minified_reference;
|
$reference = $minified_reference;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Log::warning('Unable to minify ' . $original_reference . ' and a minified copy does not already exist');
|
|
||||||
}
|
|
||||||
|
|
||||||
$reference = $this->reference($reference);
|
$reference = $this->reference($reference);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
Dynamic
|
|
||||||
Log
|
|
||||||
|
|
||||||
Cache
|
Cache
|
||||||
Config
|
Config
|
||||||
Database
|
Database
|
||||||
|
|
|
@ -2,54 +2,176 @@
|
||||||
|
|
||||||
class DynamicTest extends PHPUnit_Framework_TestCase
|
class DynamicTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testReferenceWithoutFailover()
|
private $dynamic;
|
||||||
|
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
// Using actual filesystem because you can't chdir with vfs://
|
||||||
|
$public_path = '/tmp/pickles-fs/public/';
|
||||||
|
|
||||||
|
foreach (['css', 'images', 'js'] as $directory)
|
||||||
|
{
|
||||||
|
mkdir($public_path . $directory, 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
touch($public_path . 'images/image.png');
|
||||||
|
touch($public_path . 'images/invalid');
|
||||||
|
|
||||||
|
$css = <<<CSS
|
||||||
|
body
|
||||||
|
{
|
||||||
|
color: #ffcc00;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
CSS;
|
||||||
|
|
||||||
|
foreach (['css', 'less', 'scss'] as $extension)
|
||||||
|
{
|
||||||
|
file_put_contents($public_path . 'css/stylesheet.' . $extension, $css);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents($public_path . 'css/alternate.css', $css);
|
||||||
|
|
||||||
|
chdir($public_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->dynamic = new Dynamic();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
$minified_file = '/tmp/pickles-fs/public/css/stylesheet.min.css';
|
||||||
|
|
||||||
|
if (file_exists($minified_file))
|
||||||
|
{
|
||||||
|
unlink($minified_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
File::removeDirectory('/tmp/pickles-fs');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReference()
|
||||||
|
{
|
||||||
|
$this->assertRegExp('/^\/images\/image\.\d{10}\.png$/', $this->dynamic->reference('/images/image.png'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage Supplied reference does not exist (/images/missing.png)
|
||||||
|
*/
|
||||||
|
public function testReferenceMissingFileWithoutFailover()
|
||||||
|
{
|
||||||
|
$this->dynamic->reference('/images/missing.png');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReferenceMissingFileWithFailover()
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
'/images/failover.png',
|
||||||
|
$this->dynamic->reference('/images/missing.png', '/images/failover.png')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.png)
|
||||||
|
*/
|
||||||
|
public function testReferenceInvalidFilename()
|
||||||
|
{
|
||||||
|
$this->dynamic->reference('/images/invalid');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage Reference value must be absolute (e.g. /path/to/file.png)
|
||||||
|
*/
|
||||||
|
public function testReferenceNotAbsolute()
|
||||||
|
{
|
||||||
|
$this->dynamic->reference('../images/relative.png');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.css)
|
||||||
|
*/
|
||||||
|
public function testCSSMissingExtension()
|
||||||
|
{
|
||||||
|
$this->dynamic->css('/css/invalid');
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO May not be able to do these two as it would require lessc and sass to not be installed
|
||||||
|
// TODO Good chance will also fail on Travis due to missing dependencies, will need to work through that
|
||||||
|
// TODO will probably want to move to the composer available versions of these
|
||||||
|
public function testCSSCommandErrorLESS()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferenceWithFailover()
|
public function testCSSCommandErrorSASS()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCSSWrongExtension()
|
public function testCSSWithoutMinify()
|
||||||
{
|
{
|
||||||
|
$config = Config::getInstance();
|
||||||
|
$config->data['pickles']['minify'] = false;
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCSSErrorLESS()
|
public function testCSSWithMinify()
|
||||||
{
|
{
|
||||||
|
$config = Config::getInstance();
|
||||||
|
$config->data['pickles']['minify'] = true;
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCSSErrorSASS()
|
/**
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage Supplied reference does not exist
|
||||||
|
*/
|
||||||
|
public function testCSSReferenceDoesNotExist()
|
||||||
{
|
{
|
||||||
|
$this->dynamic->css('/css/missing.css');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCSS()
|
public function testLESSWithoutMinify()
|
||||||
{
|
{
|
||||||
|
$config = Config::getInstance();
|
||||||
|
$config->data['pickles']['minify'] = false;
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.less$/', $this->dynamic->css('/css/stylesheet.less'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCSSWithLESS()
|
public function testLESSWithMinify()
|
||||||
{
|
{
|
||||||
|
$config = Config::getInstance();
|
||||||
|
$config->data['pickles']['minify'] = true;
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.less'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCSSWithSASS()
|
public function testSCSSWithoutMinify()
|
||||||
{
|
{
|
||||||
|
$config = Config::getInstance();
|
||||||
|
$config->data['pickles']['minify'] = false;
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.scss$/', $this->dynamic->css('/css/stylesheet.scss'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCSSUnableToMinify()
|
public function testSCSSWithMinify()
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCSSDoesNotExist()
|
|
||||||
{
|
{
|
||||||
|
$config = Config::getInstance();
|
||||||
|
$config->data['pickles']['minify'] = true;
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.scss'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testJSWrongExtension()
|
public function testJSWrongExtension()
|
||||||
|
|
|
@ -2,39 +2,92 @@
|
||||||
|
|
||||||
class LogTest extends PHPUnit_Framework_TestCase
|
class LogTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
$config = Config::getInstance();
|
||||||
|
$config->data['pickles']['logging'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
File::removeDirectory(LOG_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
public function testInformation()
|
public function testInformation()
|
||||||
{
|
{
|
||||||
|
Log::information('information');
|
||||||
|
|
||||||
|
$file = LOG_PATH . date('Y/m/d/') . 'information.log';
|
||||||
|
$data = file($file);
|
||||||
|
$line = $data[count($data) - 1];
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ information$/', $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWarning()
|
public function testWarning()
|
||||||
{
|
{
|
||||||
|
Log::warning('warning');
|
||||||
|
|
||||||
|
$file = LOG_PATH . date('Y/m/d/') . 'warning.log';
|
||||||
|
$data = file($file);
|
||||||
|
$line = $data[count($data) - 1];
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ warning$/', $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testError()
|
public function testError()
|
||||||
{
|
{
|
||||||
|
Log::error('error');
|
||||||
|
|
||||||
|
$file = LOG_PATH . date('Y/m/d/') . 'error.log';
|
||||||
|
$data = file($file);
|
||||||
|
$line = $data[count($data) - 1];
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ error$/', $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSlowQuery()
|
public function testSlowQuery()
|
||||||
{
|
{
|
||||||
|
Log::slowQuery('slow query');
|
||||||
|
|
||||||
|
$file = LOG_PATH . date('Y/m/d/') . 'slow_query.log';
|
||||||
|
$data = file($file);
|
||||||
|
$line = $data[count($data) - 1];
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ slow query$/', $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransaction()
|
public function testTransaction()
|
||||||
{
|
{
|
||||||
|
Log::transaction('transaction');
|
||||||
|
|
||||||
|
$file = LOG_PATH . date('Y/m/d/') . 'transaction.log';
|
||||||
|
$data = file($file);
|
||||||
|
$line = $data[count($data) - 1];
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ transaction$/', $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPHPError()
|
public function testPHPError()
|
||||||
{
|
{
|
||||||
|
Log::phperror('php error');
|
||||||
|
|
||||||
|
$file = LOG_PATH . date('Y/m/d/') . 'php_error.log';
|
||||||
|
$data = file($file);
|
||||||
|
$line = $data[count($data) - 1];
|
||||||
|
|
||||||
|
$this->assertRegExp('/^php error$/', $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQuery()
|
public function testQuery()
|
||||||
{
|
{
|
||||||
|
Log::query('query');
|
||||||
|
|
||||||
|
$file = LOG_PATH . date('Y/m/d/') . 'query.log';
|
||||||
|
$data = file($file);
|
||||||
|
$line = $data[count($data) - 1];
|
||||||
|
|
||||||
|
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ query$/', $line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue