From b7fdabe97baa5659f584de7578fe0e6caf086501 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Fri, 31 Jul 2015 18:04:36 -0400 Subject: [PATCH] Applied fixes from StyleCI --- .../MarkdownBundle/MarkdownConverter.php | 5 +- .../MarkdownBundle/PhpMarkdownExtraParser.php | 1 - .../MarkdownBundle/PhpMarkdownParser.php | 1 - .../Command/SelfUpdateCommand.php | 1 - .../Sorter/MetaSorter.php | 1 - .../Taxonomy/PermalinkStrategyCollection.php | 2 - .../Core/Converter/ParserInterface.php | 1 - .../Core/Formatter/FormatterInterface.php | 2 +- src/Sculpin/Core/Output/SourceOutput.php | 1 - .../Map/CalculatedDateFromFilenameMap.php | 2 +- src/Sculpin/Core/Source/SourceInterface.php | 1 - .../Core/Tests/Source/FileSourceTest.php | 3 +- .../Tests/Functional/FunctionalTestCase.php | 377 +++++++++--------- .../Functional/GenerateFromMarkdownTest.php | 77 ++-- 14 files changed, 240 insertions(+), 235 deletions(-) diff --git a/src/Sculpin/Bundle/MarkdownBundle/MarkdownConverter.php b/src/Sculpin/Bundle/MarkdownBundle/MarkdownConverter.php index 8ebff973..0d8def0e 100644 --- a/src/Sculpin/Bundle/MarkdownBundle/MarkdownConverter.php +++ b/src/Sculpin/Bundle/MarkdownBundle/MarkdownConverter.php @@ -94,7 +94,8 @@ public function beforeRun(SourceSetEvent $sourceSetEvent) * @param string $headerText raw markdown input for the header name * @return string */ - public function generateHeaderId($headerText) { + public function generateHeaderId($headerText) + { // $headerText is completely raw markdown input. We need to strip it // from all markup, because we are only interested in the actual 'text' @@ -127,7 +128,5 @@ public function generateHeaderId($headerText) { return rawurlencode(strtolower( strtr($result, $map) )); - } - } diff --git a/src/Sculpin/Bundle/MarkdownBundle/PhpMarkdownExtraParser.php b/src/Sculpin/Bundle/MarkdownBundle/PhpMarkdownExtraParser.php index eb423870..f82db357 100644 --- a/src/Sculpin/Bundle/MarkdownBundle/PhpMarkdownExtraParser.php +++ b/src/Sculpin/Bundle/MarkdownBundle/PhpMarkdownExtraParser.php @@ -10,7 +10,6 @@ */ class PhpMarkdownExtraParser extends MarkdownExtra implements ParserInterface { - /** * {@inheritdoc} */ diff --git a/src/Sculpin/Bundle/MarkdownBundle/PhpMarkdownParser.php b/src/Sculpin/Bundle/MarkdownBundle/PhpMarkdownParser.php index ab5b8f06..a242c793 100644 --- a/src/Sculpin/Bundle/MarkdownBundle/PhpMarkdownParser.php +++ b/src/Sculpin/Bundle/MarkdownBundle/PhpMarkdownParser.php @@ -10,7 +10,6 @@ */ class PhpMarkdownParser extends Markdown implements ParserInterface { - /** * {@inheritdoc} */ diff --git a/src/Sculpin/Bundle/SculpinBundle/Command/SelfUpdateCommand.php b/src/Sculpin/Bundle/SculpinBundle/Command/SelfUpdateCommand.php index 4a367db7..377404e4 100644 --- a/src/Sculpin/Bundle/SculpinBundle/Command/SelfUpdateCommand.php +++ b/src/Sculpin/Bundle/SculpinBundle/Command/SelfUpdateCommand.php @@ -100,7 +100,6 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!file_put_contents($tempFilename, file_get_contents($remoteFilename, false, $this->getStreamContext()))) { $output->writeln('The download of the new Sculpin version failed for an unexpected reason'); - } if (!file_exists($tempFilename)) { diff --git a/src/Sculpin/Contrib/ProxySourceCollection/Sorter/MetaSorter.php b/src/Sculpin/Contrib/ProxySourceCollection/Sorter/MetaSorter.php index 9ed886ff..eb50a078 100644 --- a/src/Sculpin/Contrib/ProxySourceCollection/Sorter/MetaSorter.php +++ b/src/Sculpin/Contrib/ProxySourceCollection/Sorter/MetaSorter.php @@ -47,7 +47,6 @@ private function setReversed($direction) throw new \InvalidArgumentException('Invalid value passed for direction, must be one of: asc, ascending, desc, descending'); } - } public function sort(ProxySourceItem $a, ProxySourceItem $b) diff --git a/src/Sculpin/Contrib/Taxonomy/PermalinkStrategyCollection.php b/src/Sculpin/Contrib/Taxonomy/PermalinkStrategyCollection.php index fd55f86a..21d8a35b 100644 --- a/src/Sculpin/Contrib/Taxonomy/PermalinkStrategyCollection.php +++ b/src/Sculpin/Contrib/Taxonomy/PermalinkStrategyCollection.php @@ -15,7 +15,6 @@ class PermalinkStrategyCollection { - protected $strategies; public function __construct() @@ -36,5 +35,4 @@ public function process($str) return $str; } - } diff --git a/src/Sculpin/Core/Converter/ParserInterface.php b/src/Sculpin/Core/Converter/ParserInterface.php index 4be289e7..f5019ad5 100644 --- a/src/Sculpin/Core/Converter/ParserInterface.php +++ b/src/Sculpin/Core/Converter/ParserInterface.php @@ -7,7 +7,6 @@ */ interface ParserInterface { - /** * @param string $content * diff --git a/src/Sculpin/Core/Formatter/FormatterInterface.php b/src/Sculpin/Core/Formatter/FormatterInterface.php index 3930cb4f..4bdac54b 100644 --- a/src/Sculpin/Core/Formatter/FormatterInterface.php +++ b/src/Sculpin/Core/Formatter/FormatterInterface.php @@ -18,7 +18,7 @@ */ interface FormatterInterface { - /** + /** * Format the input blocks * * @param FormatContext $formatContext Format context diff --git a/src/Sculpin/Core/Output/SourceOutput.php b/src/Sculpin/Core/Output/SourceOutput.php index 4d88290e..66e30d5b 100644 --- a/src/Sculpin/Core/Output/SourceOutput.php +++ b/src/Sculpin/Core/Output/SourceOutput.php @@ -20,7 +20,6 @@ */ class SourceOutput implements OutputInterface { - /** * Source * diff --git a/src/Sculpin/Core/Source/Map/CalculatedDateFromFilenameMap.php b/src/Sculpin/Core/Source/Map/CalculatedDateFromFilenameMap.php index 1c8a1b72..51379924 100644 --- a/src/Sculpin/Core/Source/Map/CalculatedDateFromFilenameMap.php +++ b/src/Sculpin/Core/Source/Map/CalculatedDateFromFilenameMap.php @@ -19,7 +19,7 @@ public function process(SourceInterface $source) { if (!$source->data()->get('calculated_date')) { if (preg_match('/(\d{4})[\/\-]*(\d{2})[\/\-]*(\d{2})[\/\-]*(\d+|)/', $source->relativePathname(), $matches)) { - list ($dummy, $year, $month, $day, $time) = $matches; + list($dummy, $year, $month, $day, $time) = $matches; $parts = array(implode('-', array($year, $month, $day))); if ($time && false !== strtotime($time)) { $parts[] = $time; diff --git a/src/Sculpin/Core/Source/SourceInterface.php b/src/Sculpin/Core/Source/SourceInterface.php index 9b782282..d142d5a2 100644 --- a/src/Sculpin/Core/Source/SourceInterface.php +++ b/src/Sculpin/Core/Source/SourceInterface.php @@ -21,7 +21,6 @@ */ interface SourceInterface { - /** * Source ID * diff --git a/src/Sculpin/Core/Tests/Source/FileSourceTest.php b/src/Sculpin/Core/Tests/Source/FileSourceTest.php index 0609d559..5faf061d 100644 --- a/src/Sculpin/Core/Tests/Source/FileSourceTest.php +++ b/src/Sculpin/Core/Tests/Source/FileSourceTest.php @@ -9,7 +9,6 @@ class FileSourceTest extends \PHPUnit_Framework_TestCase { - /* * mock analyzer for detectFromFilename, should return text/html * @@ -104,7 +103,7 @@ public function provideTestParseYaml() public function getErrorMessage($filename, $msg) { - if ($msg == ''){ + if ($msg == '') { return ''; } return ' ! FileSource:FilesystemDataSource:test:' . $filename . ' ' . $msg . ' !' . PHP_EOL; diff --git a/src/Sculpin/Tests/Functional/FunctionalTestCase.php b/src/Sculpin/Tests/Functional/FunctionalTestCase.php index 321d5db1..cb26fb0d 100644 --- a/src/Sculpin/Tests/Functional/FunctionalTestCase.php +++ b/src/Sculpin/Tests/Functional/FunctionalTestCase.php @@ -11,193 +11,208 @@ * and run the sculpin binary against it. Test project files * will automatically be created and removed with every test. */ -class FunctionalTestCase extends \PHPUnit_Framework_TestCase { +class FunctionalTestCase extends \PHPUnit_Framework_TestCase +{ + const PROJECT_DIR = '/__SculpinTestProject__'; - const PROJECT_DIR = '/__SculpinTestProject__'; + /** @var Filesystem */ + protected static $fs; - /** @var Filesystem */ - protected static $fs; + public static function setUpBeforeClass() + { + self::$fs = new Filesystem(); + } - public static function setUpBeforeClass() { - self::$fs = new Filesystem(); - } + public function setUp() + { + parent::setUp(); - public function setUp() { - parent::setUp(); + $this->setUpTestProject(); + } - $this->setUpTestProject(); - } + protected function setUpTestProject() + { + $this->tearDownTestProject(); - protected function setUpTestProject() { - $this->tearDownTestProject(); - - $projectFiles = array( - '/config/sculpin_kernel.yml', - '/config/sculpin_site.yml', - '/source/_layouts/raw.html.twig', + $projectFiles = array( + '/config/sculpin_kernel.yml', + '/config/sculpin_site.yml', + '/source/_layouts/raw.html.twig', ); - foreach ($projectFiles as $file) { - $this->addProjectFile($file); - } - - $this->writeToProjectFile('/source/_layouts/raw.html.twig', '{% block content %}{% endblock content %}'); - } - - protected function tearDownTestProject() { - $projectDir = self::ProjectDir(); - if (self::$fs->exists($projectDir)) { - self::$fs->remove($projectDir); - } - } - - /** - * Execute a command against the sculpin binary - * @param string $command - */ - protected function executeSculpin($command) { - $binPath = __DIR__ . '/../../../../bin'; - $projectDir = self::ProjectDir(); - exec("$binPath/sculpin $command --project-dir $projectDir --env=test"); - } - - /** - * @param string $path - * @param bool $recursive - */ - protected function addProjectDirectory($path, $recursive = true) { - $pathParts = explode('/', $path); - // Remove leading slash - array_shift($pathParts); - - $projectDir = self::ProjectDir(); - - if (!$recursive) { - self::$fs->mkdir("$projectDir/$path"); - return; - } - - $currPath = "$projectDir/"; - foreach ($pathParts as $dir) { - $currPath .= "$dir/"; - if (!self::$fs->exists($currPath)) { - self::$fs->mkdir($currPath); - } - } - - } - - /** - * @param string $filePath - * @param string $content - */ - protected function addProjectFile($filePath, $content = null) { - $dirPathParts = explode('/', $filePath); - // Remove leading slash - array_shift($dirPathParts); - // Remove file name - array_pop($dirPathParts); - - // Add the file directories - $hasDirectoryPath = !empty($dirPathParts); - if ($hasDirectoryPath) { - $dirPath = '/' . join('/', $dirPathParts); - $this->addProjectDirectory($dirPath); - } - - // Create the file - self::$fs->touch(self::ProjectDir() . $filePath); - - // Add content to the file - if (!is_null($content)) { - $this->writeToProjectFile($filePath, $content); - } - } - - /** - * @param string $fixturePath - * @param string $projectPath - */ - protected function copyFixtureToProject($fixturePath, $projectPath) { - self::$fs->copy($fixturePath, self::ProjectDir() . $projectPath); - } - - /** - * @param string $filePath - * @param null $msg - */ - protected function assertProjectHasFile($filePath, $msg = null) { - $msg = $msg ?: "Expected project to contain file at path $filePath."; - - $this->assertTrue(self::$fs->exists(self::ProjectDir() . $filePath), $msg); - } - - /** - * @param string $filePath - * @param string $msg - */ - protected function assertProjectHasGeneratedFile($filePath, $msg = null) { - $outputDir = '/output_test'; - - $msg = $msg ?: "Expected project to have generated file at path $filePath."; - $this->assertProjectHasFile($outputDir . $filePath, $msg); - } - - /** - * @param string $filePath - * @param string $content - */ - protected function writeToProjectFile($filePath, $content) { - self::$fs->dumpFile(self::ProjectDir() . $filePath, $content); - } - - /** - * @param string $filePath - * @return Crawler - */ - protected function crawlGeneratedProjectFile($filePath) { - return $this->crawlProjectFile('/output_test' . $filePath); - } - - /** - * @param string $filePath - * @return Crawler - */ - protected function crawlProjectFile($filePath) { - return $this->crawlFile(self::ProjectDir() . $filePath); - } - - /** - * @param string $filePath - * @return Crawler - */ - private function crawlFile($filePath) { - $content = $this->readFile($filePath); - - return new Crawler($content); - } - - /** - * @param $filePath - * @return string - */ - private function readFile($filePath) { - if (!self::$fs->exists($filePath)) { - throw new \PHPUnit_Framework_Exception("Unable to read file at path $filePath: file does not exist"); - } - - $content = file_get_contents($filePath); - if ($content === false) { - throw new \PHPUnit_Framework_Exception("Unable to read file at path $filePath: failed to read file."); - } - - return $content; - } - - /** - * @return string - */ - protected static function ProjectDir() { - return __DIR__ . self::PROJECT_DIR; - } + foreach ($projectFiles as $file) { + $this->addProjectFile($file); + } + + $this->writeToProjectFile('/source/_layouts/raw.html.twig', '{% block content %}{% endblock content %}'); + } + + protected function tearDownTestProject() + { + $projectDir = self::ProjectDir(); + if (self::$fs->exists($projectDir)) { + self::$fs->remove($projectDir); + } + } + + /** + * Execute a command against the sculpin binary + * @param string $command + */ + protected function executeSculpin($command) + { + $binPath = __DIR__ . '/../../../../bin'; + $projectDir = self::ProjectDir(); + exec("$binPath/sculpin $command --project-dir $projectDir --env=test"); + } + + /** + * @param string $path + * @param bool $recursive + */ + protected function addProjectDirectory($path, $recursive = true) + { + $pathParts = explode('/', $path); + // Remove leading slash + array_shift($pathParts); + + $projectDir = self::ProjectDir(); + + if (!$recursive) { + self::$fs->mkdir("$projectDir/$path"); + return; + } + + $currPath = "$projectDir/"; + foreach ($pathParts as $dir) { + $currPath .= "$dir/"; + if (!self::$fs->exists($currPath)) { + self::$fs->mkdir($currPath); + } + } + } + + /** + * @param string $filePath + * @param string $content + */ + protected function addProjectFile($filePath, $content = null) + { + $dirPathParts = explode('/', $filePath); + // Remove leading slash + array_shift($dirPathParts); + // Remove file name + array_pop($dirPathParts); + + // Add the file directories + $hasDirectoryPath = !empty($dirPathParts); + if ($hasDirectoryPath) { + $dirPath = '/' . join('/', $dirPathParts); + $this->addProjectDirectory($dirPath); + } + + // Create the file + self::$fs->touch(self::ProjectDir() . $filePath); + + // Add content to the file + if (!is_null($content)) { + $this->writeToProjectFile($filePath, $content); + } + } + + /** + * @param string $fixturePath + * @param string $projectPath + */ + protected function copyFixtureToProject($fixturePath, $projectPath) + { + self::$fs->copy($fixturePath, self::ProjectDir() . $projectPath); + } + + /** + * @param string $filePath + * @param null $msg + */ + protected function assertProjectHasFile($filePath, $msg = null) + { + $msg = $msg ?: "Expected project to contain file at path $filePath."; + + $this->assertTrue(self::$fs->exists(self::ProjectDir() . $filePath), $msg); + } + + /** + * @param string $filePath + * @param string $msg + */ + protected function assertProjectHasGeneratedFile($filePath, $msg = null) + { + $outputDir = '/output_test'; + + $msg = $msg ?: "Expected project to have generated file at path $filePath."; + $this->assertProjectHasFile($outputDir . $filePath, $msg); + } + + /** + * @param string $filePath + * @param string $content + */ + protected function writeToProjectFile($filePath, $content) + { + self::$fs->dumpFile(self::ProjectDir() . $filePath, $content); + } + + /** + * @param string $filePath + * @return Crawler + */ + protected function crawlGeneratedProjectFile($filePath) + { + return $this->crawlProjectFile('/output_test' . $filePath); + } + + /** + * @param string $filePath + * @return Crawler + */ + protected function crawlProjectFile($filePath) + { + return $this->crawlFile(self::ProjectDir() . $filePath); + } + + /** + * @param string $filePath + * @return Crawler + */ + private function crawlFile($filePath) + { + $content = $this->readFile($filePath); + + return new Crawler($content); + } + + /** + * @param $filePath + * @return string + */ + private function readFile($filePath) + { + if (!self::$fs->exists($filePath)) { + throw new \PHPUnit_Framework_Exception("Unable to read file at path $filePath: file does not exist"); + } + + $content = file_get_contents($filePath); + if ($content === false) { + throw new \PHPUnit_Framework_Exception("Unable to read file at path $filePath: failed to read file."); + } + + return $content; + } + + /** + * @return string + */ + protected static function ProjectDir() + { + return __DIR__ . self::PROJECT_DIR; + } } diff --git a/src/Sculpin/Tests/Functional/GenerateFromMarkdownTest.php b/src/Sculpin/Tests/Functional/GenerateFromMarkdownTest.php index 23079cbf..341bc13c 100644 --- a/src/Sculpin/Tests/Functional/GenerateFromMarkdownTest.php +++ b/src/Sculpin/Tests/Functional/GenerateFromMarkdownTest.php @@ -2,64 +2,65 @@ namespace Sculpin\Tests\Functional; +class GenerateFromMarkdownTest extends FunctionalTestCase +{ + /** @test */ + public function shouldGenerateAnHtmlFileFromMarkdown() + { + $this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello_world.md'); -class GenerateFromMarkdownTest extends FunctionalTestCase { + $this->executeSculpin('generate'); - /** @test */ - public function shouldGenerateAnHtmlFileFromMarkdown() { - $this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello_world.md'); + $this->assertProjectHasGeneratedFile('/hello_world/index.html'); + } - $this->executeSculpin('generate'); + /** @test */ + public function shouldGenerateHtmlContentFromMarkdown() + { + $this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello_world.md'); - $this->assertProjectHasGeneratedFile('/hello_world/index.html'); - } + $this->executeSculpin('generate'); - /** @test */ - public function shouldGenerateHtmlContentFromMarkdown() { - $this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello_world.md'); + $crawler = $this->crawlGeneratedProjectFile('/hello_world/index.html'); - $this->executeSculpin('generate'); + $this->assertContains('Hello World', $crawler->filter('h1')->text()); + } - $crawler = $this->crawlGeneratedProjectFile('/hello_world/index.html'); + /** @test */ + public function shouldGenerateIntoNestedDirectories() + { + $this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello/world.md'); - $this->assertContains('Hello World', $crawler->filter('h1')->text()); - } + $this->executeSculpin('generate'); - /** @test */ - public function shouldGenerateIntoNestedDirectories() { - $this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello/world.md'); + $this->assertProjectHasGeneratedFile('/hello/world/index.html'); + } - $this->executeSculpin('generate'); - - $this->assertProjectHasGeneratedFile('/hello/world/index.html'); - } - - /** @test */ - public function shouldGenerateHtmlUsingALayout() { - $this->addProjectFile('/source/_layouts/my_layout.html.twig', <<addProjectFile('/source/_layouts/my_layout.html.twig', <<
{% block content %}{% endblock content %}
EOT - ); + ); - $this->addProjectFile('/source/my_page_with_layout.md', <<addProjectFile('/source/my_page_with_layout.md', <<executeSculpin('generate'); - - $crawler = $this->crawlGeneratedProjectFile('/my_page_with_layout/index.html'); + ); - $pageContentEl = $crawler->filter('.page-content'); - $this->assertEquals(1, $pageContentEl->count(), - "Expected generated file to have a single .page-content element."); - $this->assertContains('Hello World', $pageContentEl->text()); - } + $this->executeSculpin('generate'); + $crawler = $this->crawlGeneratedProjectFile('/my_page_with_layout/index.html'); -} \ No newline at end of file + $pageContentEl = $crawler->filter('.page-content'); + $this->assertEquals(1, $pageContentEl->count(), + "Expected generated file to have a single .page-content element."); + $this->assertContains('Hello World', $pageContentEl->text()); + } +}