diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index 48ce4b5..6c4d938 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -2,7 +2,7 @@ name: PHP Tests
on:
push:
- branches:
+ branches:
- master
jobs:
@@ -10,21 +10,34 @@ jobs:
runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ php-versions: ['7.2', '7.3', '7.4']
+
steps:
- - uses: actions/checkout@v1
+ - uses: actions/checkout@v2
- - name: setup PHP
- uses: shivammathur/setup-php@master
- with:
- php-version: '7.2'
- extension-csv: intl, json, mbstring, mysqlnd. xdebug, xml
+ - name: Setup PHP, with composer and extensions
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php-versions }}
+ tools: composer
coverage: xdebug
- - name: Validate composer.json and composer.lock
- run: composer validate
+ - name: Get composer cache directory
+ id: composercache
+ run: echo "::set-output name=dir::$(composer config cache-files-dir)"
+
+ - name: Cache dependencies
+ uses: actions/cache@v2
+ with:
+ path: ${{ steps.composercache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+ restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
- run: composer install --prefer-dist --no-progress --no-suggest
+ run: composer install --ansi --no-interaction
- - name: Run test suite
- run: composer run-script test
+ - name: Test with PHPUnit
+ run: script -e -c "vendor/bin/phpunit -v"
diff --git a/src/Minifier.php b/src/Minifier.php
index e0417de..f63a73c 100644
--- a/src/Minifier.php
+++ b/src/Minifier.php
@@ -67,13 +67,6 @@ public function load(string $filename)
throw MinifierException::forWrongFileExtension($ext);
}
- $versions = $this->getVersion($this->config->dirVersion);
-
- if (empty($versions))
- {
- throw MinifierException::forNoVersioningFile();
- }
-
if (! in_array($this->config->returnType, ['html', 'array', 'json']))
{
throw MinifierException::forWrongReturnType($this->config->returnType);
@@ -84,6 +77,9 @@ public function load(string $filename)
$this->autoDeployCheck($filename, $ext);
}
+ // load versions
+ $versions = $this->getVersion($this->config->dirVersion);
+
$filenames = [];
// do we use combined+minified+versioned assets?
diff --git a/tests/unit/MinifierTest.php b/tests/unit/MinifierTest.php
index 72b9f0c..c6b36b5 100644
--- a/tests/unit/MinifierTest.php
+++ b/tests/unit/MinifierTest.php
@@ -9,6 +9,11 @@ class MinifierTest extends \CodeIgniter\Test\CIUnitTestCase
protected $minifier;
+ protected $ver = [
+ 'js' => '9ef881911da8d7c4a1c2f19c4878d122',
+ 'css' => '95cb11cf55b3f1164e80ae9393644ae3'
+ ];
+
public function setUp(): void
{
parent::setUp();
@@ -22,6 +27,15 @@ public function setUp(): void
$this->config->js = ['all.min.js' => ['bootstrap.js', 'jquery-3.4.1.js', 'main.js']];
$this->config->css = ['all.min.css' => ['bootstrap.css', 'font-awesome.css', 'main.css']];
+ if (file_exists($this->config->dirJs . '/new.js'))
+ {
+ unlink($this->config->dirJs . '/new.js');
+ }
+
+ if (file_exists($this->config->dirCss . '/new.css'))
+ {
+ unlink($this->config->dirCss . '/new.css');
+ }
/*
if (file_exists($this->config->dirJs . '/all.min.js'))
@@ -120,7 +134,7 @@ public function testLoadJs()
$result = $this->minifier->load('all.min.js');
- $this->assertEquals('' . PHP_EOL, $result);
+ $this->assertEquals('' . PHP_EOL, $result);
}
public function testLoadCss()
@@ -129,7 +143,8 @@ public function testLoadCss()
$result = $this->minifier->load('all.min.css');
- $this->assertEquals('' . PHP_EOL, $result);
+ $this->assertEquals('' . PHP_EOL, $result);
+
}
public function testLoadJsWithBaseJsUrl()
@@ -140,7 +155,7 @@ public function testLoadJsWithBaseJsUrl()
$result = $this->minifier->load('all.min.js');
- $this->assertEquals('' . PHP_EOL, $result);
+ $this->assertEquals('' . PHP_EOL, $result);
}
public function testLoadCssWithBaseCssUrl()
@@ -151,7 +166,7 @@ public function testLoadCssWithBaseCssUrl()
$result = $this->minifier->load('all.min.css');
- $this->assertEquals('' . PHP_EOL, $result);
+ $this->assertEquals('' . PHP_EOL, $result);
}
public function testJsonReturnTypeWithLoadJs()
@@ -161,7 +176,7 @@ public function testJsonReturnTypeWithLoadJs()
$result = $this->minifier->load('all.min.js');
- $this->assertEquals(json_encode(['http://localhost' . SUPPORTPATH . 'assets/js/all.min.js?v=9ef881911da8d7c4a1c2f19c4878d122']), $result);
+ $this->assertEquals(json_encode(['http://localhost' . SUPPORTPATH . 'assets/js/all.min.js?v=' . $this->ver['js']]), $result);
}
public function testJsonReturnTypeWithLoadCss()
@@ -171,7 +186,7 @@ public function testJsonReturnTypeWithLoadCss()
$result = $this->minifier->load('all.min.css');
- $this->assertEquals(json_encode(['http://localhost' . SUPPORTPATH . 'assets/css/all.min.css?v=50a35b0b1d1c3798aa556b8245314930']), $result);
+ $this->assertEquals(json_encode(['http://localhost' . SUPPORTPATH . 'assets/css/all.min.css?v=' . $this->ver['css']]), $result);
}
public function testArrayReturnTypeWithLoadJs()
@@ -181,7 +196,7 @@ public function testArrayReturnTypeWithLoadJs()
$result = $this->minifier->load('all.min.js');
- $this->assertEquals(['http://localhost' . SUPPORTPATH . 'assets/js/all.min.js?v=9ef881911da8d7c4a1c2f19c4878d122'], $result);
+ $this->assertEquals(['http://localhost' . SUPPORTPATH . 'assets/js/all.min.js?v=' . $this->ver['js']], $result);
}
public function testArrayReturnTypeWithLoadCss()
@@ -191,7 +206,7 @@ public function testArrayReturnTypeWithLoadCss()
$result = $this->minifier->load('all.min.css');
- $this->assertEquals(['http://localhost' . SUPPORTPATH . 'assets/css/all.min.css?v=50a35b0b1d1c3798aa556b8245314930'], $result);
+ $this->assertEquals(['http://localhost' . SUPPORTPATH . 'assets/css/all.min.css?v=' . $this->ver['css']], $result);
}
public function testLoadExceptionForWrongReturnType()
@@ -222,11 +237,12 @@ public function testAutoDeployOnChangeJsTrue()
$this->config->js = ['all.min.js' => ['bootstrap.js', 'jquery-3.4.1.js', 'main.js', 'new.js']];
$this->minifier = new Minifier($this->config);
+ sleep(1);
+ file_put_contents($this->config->dirJs . '/new.js', '//data;');
+
$method = $this->getPrivateMethodInvoker($this->minifier, 'autoDeployCheckJs');
- file_put_contents($this->config->dirJs . '/new.js', '//data;');
$this->assertTrue($method('all.min.js'));
- unlink($this->config->dirJs . '/new.js');
}
public function testAutoDeployOnChangeCssFalse()
@@ -246,11 +262,12 @@ public function testAutoDeployOnChangeCssTrue()
$this->config->css = ['all.min.css' => ['bootstrap.css', 'font-awesome.css', 'main.css', 'new.css']];
$this->minifier = new Minifier($this->config);
+ sleep(1);
+ file_put_contents($this->config->dirCss . '/new.css', '//data;');
+
$method = $this->getPrivateMethodInvoker($this->minifier, 'autoDeployCheckCss');
- file_put_contents($this->config->dirCss . '/new.css', '//data;');
$this->assertTrue($method('all.min.css'));
- unlink($this->config->dirCss . '/new.css');
}
}