Skip to content

Commit

Permalink
🚨 Fixed Style-CI warnings (#3)
Browse files Browse the repository at this point in the history
* Apply fixes from StyleCI

* 🐛 fixed a bug introduced by style-ci
  • Loading branch information
carbontwelve authored Aug 1, 2017
1 parent dc4868c commit 8596ee1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
15 changes: 8 additions & 7 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public function register()
* Method will be invoked on registration of a service provider implementing
* this interface. Provides ability for eager loading of Service Providers.
*
* @return void
* @throws \Exception
*
* @return void
*/
public function boot()
{
Expand Down Expand Up @@ -79,7 +80,7 @@ public function boot()
// loops are generated.
//
$tapestry->getEventEmitter()->addListener('compile.after', function () use ($tapestry, $project) {
$cache = new Cache($project->currentWorkingDirectory . DIRECTORY_SEPARATOR . '.'. $project->environment .'_301_cache', 'permanent');
$cache = new Cache($project->currentWorkingDirectory.DIRECTORY_SEPARATOR.'.'.$project->environment.'_301_cache', 'permanent');
$cache->load();
$redirects = [];

Expand All @@ -95,28 +96,28 @@ public function boot()
$item['current'] = $currentPermalink;

// 2bi:
$item['history'] = array_filter($item['history'], function($v) use ($item) {
$item['history'] = array_filter($item['history'], function ($v) use ($item) {
return $v !== $item['current'];
});
}
} else {
// 1:
$item = [
'current' => $currentPermalink,
'history' => []
'history' => [],
];
}

if (count($item['history']) > 0) {
foreach ($item['history'] as $from) {
array_push($redirects, 'rewrite ^/'. $from .'$ '. url($item['current']) .' permanent;');
array_push($redirects, 'rewrite ^/'.$from.'$ '.url($item['current']).' permanent;');
}
}
$cache->setItem($fileIdentifier, $item);
}

$cache->save();
file_put_contents($project->currentWorkingDirectory . DIRECTORY_SEPARATOR . 'nginx_redirects.conf', implode("\n", $redirects));
file_put_contents($project->currentWorkingDirectory.DIRECTORY_SEPARATOR.'nginx_redirects.conf', implode("\n", $redirects));
});
}
}
}
27 changes: 14 additions & 13 deletions tests/CompileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CompileTest extends CommandTestBase
{
public static function setUpBeforeClass()
{
self::$tmpPath = __DIR__ . DIRECTORY_SEPARATOR . '_tmp';
self::$tmpPath = __DIR__.DIRECTORY_SEPARATOR.'_tmp';
$fileSystem = new Filesystem();
$fileSystem->mkdir(self::$tmpPath);
chdir(self::$tmpPath);
Expand All @@ -24,8 +24,8 @@ public static function setUpBeforeClass()

protected function copyDirectory($from, $to)
{
$from = __DIR__ . DIRECTORY_SEPARATOR . $from;
$to = __DIR__ . DIRECTORY_SEPARATOR . $to;
$from = __DIR__.DIRECTORY_SEPARATOR.$from;
$to = __DIR__.DIRECTORY_SEPARATOR.$to;
$directoryContent = new \RecursiveDirectoryIterator($from, \FilesystemIterator::SKIP_DOTS);
$files = new \RecursiveIteratorIterator($directoryContent, \RecursiveIteratorIterator::CHILD_FIRST);
/** @var \SplFileInfo $item */
Expand All @@ -44,32 +44,33 @@ private function bootstrapTapestry()
$definitions = new DefaultInputDefinition();

$tapestry = new Tapestry(new ArrayInput([
'--site-dir' => __DIR__ . DIRECTORY_SEPARATOR . '_tmp',
'--env' => 'testing'
'--site-dir' => __DIR__.DIRECTORY_SEPARATOR.'_tmp',
'--env' => 'testing',
], $definitions));
$generator = new Generator($tapestry->getContainer()->get('Compile.Steps'), $tapestry);

/** @var Project $project */
$project = $tapestry->getContainer()->get(Project::class);
$project->set('cmd_options', []);
$generator->generate($project, new NullOutput);
$generator->generate($project, new NullOutput());
// </Bootstrap Tapestry>
}

function testPlugin() {
public function testPlugin()
{
$this->copyDirectory('assets/build_test_1/src', '_tmp');
$this->bootstrapTapestry();
$this->assertFileEquals(__DIR__ . '/assets/build_test_1/check/nginx_redirects_first.conf', __DIR__ . '/_tmp/nginx_redirects.conf');
$this->assertFileEquals(__DIR__.'/assets/build_test_1/check/nginx_redirects_first.conf', __DIR__.'/_tmp/nginx_redirects.conf');

// Modify permalinks to prompt redirect mapping
self::$fileSystem->copy(__DIR__ . '/_tmp/config.php', __DIR__ . '/_tmp/config.old.php', true);
self::$fileSystem->copy(__DIR__ . '/_tmp/config.new.php', __DIR__ . '/_tmp/config.php', true);
self::$fileSystem->copy(__DIR__.'/_tmp/config.php', __DIR__.'/_tmp/config.old.php', true);
self::$fileSystem->copy(__DIR__.'/_tmp/config.new.php', __DIR__.'/_tmp/config.php', true);
$this->bootstrapTapestry();
$this->assertFileEquals(__DIR__ . '/assets/build_test_1/check/nginx_redirects_second.conf', __DIR__ . '/_tmp/nginx_redirects.conf');
$this->assertFileEquals(__DIR__.'/assets/build_test_1/check/nginx_redirects_second.conf', __DIR__.'/_tmp/nginx_redirects.conf');

// Modify permalinks once more to reset back to before, this tests the mapping works when changes are reverted
self::$fileSystem->copy(__DIR__ . '/_tmp/config.old.php', __DIR__ . '/_tmp/config.php', true);
self::$fileSystem->copy(__DIR__.'/_tmp/config.old.php', __DIR__.'/_tmp/config.php', true);
$this->bootstrapTapestry();
$this->assertFileEquals(__DIR__ . '/assets/build_test_1/check/nginx_redirects_third.conf', __DIR__ . '/_tmp/nginx_redirects.conf');
$this->assertFileEquals(__DIR__.'/assets/build_test_1/check/nginx_redirects_third.conf', __DIR__.'/_tmp/nginx_redirects.conf');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Tapestry\Modules\Kernel\KernelInterface;
use Tapestry\Tapestry;

class TestKernel implements KernelInterface
class Kernel implements KernelInterface
{
/**
* @var Tapestry
Expand Down
10 changes: 5 additions & 5 deletions tests/assets/build_test_1/src/config.new.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

return [
'debug' => false,
'kernel' => \SiteOne\TestKernel::class,
'site' => [
'debug' => false,
'kernel' => \SiteOne\Kernel::class,
'site' => [
'title' => 'redirect-plugin.',
'url' => 'http://localhost:3000',
],
'content_types' => [
'blog' => [
'permalink' => 'blog/test/{year}/{slug}.html',
]
]
],
],
];
8 changes: 4 additions & 4 deletions tests/assets/build_test_1/src/config.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

return [
'debug' => false,
'kernel' => \SiteOne\TestKernel::class,
'site' => [
'debug' => false,
'kernel' => \SiteOne\Kernel::class,
'site' => [
'title' => 'redirect-plugin.',
'url' => 'http://localhost:3000',
]
],
];

0 comments on commit 8596ee1

Please sign in to comment.