Skip to content

Commit

Permalink
Merge pull request #26 from ytake/develop5.1
Browse files Browse the repository at this point in the history
use env
  • Loading branch information
ytake committed Jul 25, 2015
2 parents 2fd0aa5 + 03d4abd commit c3ab2d4
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 16 deletions.
1 change: 1 addition & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
filter:
excluded_paths:
- tests/*
- src/config/*
checks:
php:
code_rating: true
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
sudo: false
language: php
php:
- 5.5
- 5.6
- hhvm
services:
- memcached
install:
- composer self-update
- composer install
before_script:
- composer self-update
- composer install --prefer-source
- chmod -R 755 tests/bin/memcached.sh
- tests/bin/memcached.sh
script:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"illuminate/config": "5.*",
"illuminate/console": "5.*",
"illuminate/events": "5.*",
"smarty/smarty": "3.*"
"smarty/smarty": "3.*",
"vlucas/phpdotenv": "~1.0"
},
"require-dev": {
"predis/predis": "~1.0",
Expand Down
10 changes: 10 additions & 0 deletions src/Smarty/Cache/Redis.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Ytake\LaravelSmarty\Cache;

use Predis\Client;
Expand Down
10 changes: 10 additions & 0 deletions src/Smarty/Cache/Storage.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Ytake\LaravelSmarty\Cache;

use Smarty;
Expand Down
12 changes: 11 additions & 1 deletion src/Smarty/Console/CacheClearCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Ytake\LaravelSmarty\Console;

use Smarty;
Expand All @@ -13,7 +23,7 @@
*/
class CacheClearCommand extends Command
{

/** @var Smarty */
protected $smarty;

Expand Down
10 changes: 10 additions & 0 deletions src/Smarty/Console/ClearCompiledCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Ytake\LaravelSmarty\Console;

use Smarty;
Expand Down
10 changes: 10 additions & 0 deletions src/Smarty/Console/OptimizeCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Ytake\LaravelSmarty\Console;

use Smarty;
Expand Down
10 changes: 10 additions & 0 deletions src/Smarty/Console/PackageInfoCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Ytake\LaravelSmarty\Console;

use Smarty;
Expand Down
10 changes: 10 additions & 0 deletions src/Smarty/Engines/SmartyEngine.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Ytake\LaravelSmarty\Engines;

use Smarty;
Expand Down
10 changes: 10 additions & 0 deletions src/Smarty/Exception/MethodNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Ytake\LaravelSmarty\Exception;

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Smarty/SmartyCompileServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Ytake\LaravelSmarty;

use Illuminate\Support\ServiceProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/Smarty/SmartyConsoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ protected function registerCommands()
);
}

}
}
16 changes: 10 additions & 6 deletions src/config/ytake-laravel-smarty.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
'extension' => 'tpl',

//
'debugging' => false,
'debugging' => env('SMARTY_DEBUG',false),

// use cache
'caching' => false,
'caching' => env('SMARTY_CACHING', false),

//
'cache_lifetime' => 120,
'cache_lifetime' => env('SMARTY_CACHE_LIFE', 120),

//
'compile_check' => false,
'compile_check' => env('SMARTY_COMPILE_CHECK', false),

// delimiters
// default "{$smarty}"
Expand All @@ -29,14 +29,18 @@
// path info
'template_path' => base_path() . '/resources/views',

// smarty cache directory
'cache_path' => storage_path() . '/framework/smarty/cache',

// smarty template compiler
'compile_path' => storage_path() . '/framework/smarty/compile',

// smarty plugins
'plugins_paths' => [
base_path() . '/resources/smarty/plugins',
],

// somarty configure
'config_paths' => [
base_path() . '/resources/smarty/config',
],
Expand All @@ -45,10 +49,10 @@
* for develop true
* for production false
*/
'force_compile' => true,
'force_compile' => env('SMARTY_FORCE_COMPILE', true),

// smarty cache driver "file", "memcached", "redis"
'cache_driver' => 'file',
'cache_driver' => env('SMARTY_CACHE_DRIVER', 'file'),

// memcached servers
'memcached' => [
Expand Down
2 changes: 1 addition & 1 deletion tests/ConfigureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protected function setUp()
parent::setUp();
$filesystem = new \Illuminate\Filesystem\Filesystem;

$items = $filesystem->getRequire(__DIR__ . '/../src/config/ytake-laravel-smarty.php');
$items = $filesystem->getRequire(__DIR__ . '/config/config.php');
$this->config->set('ytake-laravel-smarty', $items);
}

Expand Down
48 changes: 46 additions & 2 deletions tests/Console/CacheClearCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,59 @@ public function testInstance()
{
$this->assertInstanceOf("Ytake\LaravelSmarty\Console\CacheClearCommand", $this->command);
}

public function testCommand()
{
$this->command->run(new \Symfony\Component\Console\Input\ArrayInput([]), new \Symfony\Component\Console\Output\NullOutput);
$smarty = $this->factory->getSmarty();
$smarty->caching = true;
ob_start();
$smarty->display('test.tpl');
ob_get_clean();
$output = new \Symfony\Component\Console\Output\BufferedOutput();
$this->command->run(
new \Symfony\Component\Console\Input\ArrayInput([]),
$output
);
$this->assertSame('ytake:smarty-clear-cache', $this->command->getName());
$this->assertSame("Flush the smarty cache", $this->command->getDescription());
$this->assertSame('smarty cache cleared!', trim($output->fetch()));
}

public function testCommandFile()
{
$this->command->run(new \Symfony\Component\Console\Input\ArrayInput(['--file' => 'test']), new \Symfony\Component\Console\Output\NullOutput);
$smarty = $this->factory->getSmarty();
$smarty->caching = true;
ob_start();
$smarty->display('test.tpl');
ob_get_clean();
$dir = new DirectoryIterator($smarty->getCacheDir());
$fileCount = 0;
$pathName = null;
foreach ($dir as $file) {
if(!$file->isDot()) {
if($file->getFilename() != '.gitignore') {
$pathName = $file->getPathname();
$fileCount++;
}
}
}
$this->assertSame(1, $fileCount);
$output = new \Symfony\Component\Console\Output\BufferedOutput();
$this->command->run(
new \Symfony\Component\Console\Input\ArrayInput(['--file' => 'test.tpl']),
$output
);
$this->assertFileNotExists($pathName);
$this->assertSame('specified file was cache cleared!', trim($output->fetch()));
}

public function testNoCacheFile()
{
$output = new \Symfony\Component\Console\Output\BufferedOutput();
$this->command->run(
new \Symfony\Component\Console\Input\ArrayInput(['--file' => 'test.tpl']),
$output
);
$this->assertSame('specified file not be found', trim($output->fetch()));
}
}
43 changes: 42 additions & 1 deletion tests/Console/CompiledClearCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,49 @@ public function testInstance()
}
public function testCommand()
{
$this->command->run(new \Symfony\Component\Console\Input\ArrayInput([]), new \Symfony\Component\Console\Output\NullOutput);
$this->command->run(
new \Symfony\Component\Console\Input\ArrayInput([]),
new \Symfony\Component\Console\Output\NullOutput
);
$this->assertSame("Remove the compiled smarty file", $this->command->getDescription());
$this->assertNotNull($this->command->getSynopsis());
}

public function testCleaCompile()
{
$smarty = $this->factory->getSmarty();
$smarty->force_compile = true;
ob_start();
$smarty->display('test.tpl');
ob_get_clean();
$dir = new DirectoryIterator($smarty->getCompileDir());
$fileCount = 0;
$pathName = null;
foreach ($dir as $file) {
if(!$file->isDot()) {
if($file->getFilename() != '.gitignore') {
$pathName = $file->getPathname();
$fileCount++;
}
}
}
$this->assertSame(1, $fileCount);
$output = new \Symfony\Component\Console\Output\BufferedOutput();
$this->command->run(
new \Symfony\Component\Console\Input\ArrayInput([]),
$output
);
$this->assertFileNotExists($pathName);
$this->assertSame('done.', trim($output->fetch()));
}

public function testNotExistsFiles()
{
$output = new \Symfony\Component\Console\Output\BufferedOutput();
$this->command->run(
new \Symfony\Component\Console\Input\ArrayInput(['--file' => 'testing']),
$output
);
$this->assertEmpty(trim($output->fetch()));
}
}

0 comments on commit c3ab2d4

Please sign in to comment.