/** * Test if the `indent` method doesn't indent an empty line. */ public function testNotIndentEmptyLine() { $config = new Config(); $config->indentEmptyLines(false); Generator::setConfig($config); /* @var Generator $generator */ $generator = $this->getMockForAbstractClass('\\com\\mohiva\\manitou\\Generator'); $value = $generator->indent(''); $this->assertSame('', $value); }
/** * Test if can generate a complex comment. */ public function testGenerateComplexComment() { $lineFeed = Generator::getConfig()->getNewline(); $license = 'This source file is subject to the new BSD license that is bundled' . $lineFeed; $license .= 'with this package in the file LICENSE.txt.' . $lineFeed; $license .= 'It is also available through the world-wide-web at this URL:' . $lineFeed; $license .= 'http://framework.mohiva.com/license' . $lineFeed; $license .= 'If you did not receive a copy of the license and are unable to' . $lineFeed; $license .= 'obtain it through the world-wide-web, please send an email' . $lineFeed; $license .= 'to license@framework.mohiva.com so we can send you a copy immediately.' . $lineFeed; $file = Bootstrap::$resourceDir . '/manitou/generators/php/docblock_complex.txt'; $expected = $this->getFileContent($file); $docBlock = new PHPDocBlock(); $docBlock->addSection('Unit test case for the Mohiva `PHPDocBlock` class.'); $docBlock->addSection('LICENSE'); $docBlock->addSection($license); $docBlock->addAnnotation('@category Mohiva'); $docBlock->addAnnotation('@package Mohiva/Test'); $docBlock->addAnnotation('@author Christian Kaps <*****@*****.**>'); $docBlock->addAnnotation('@copyright Copyright (c) 2007-2011 Christian Kaps (http://www.mohiva.com)'); $docBlock->addAnnotation('@license http://framework.mohiva.com/license New BSD License'); $docBlock->addAnnotation('@link http://framework.mohiva.com'); $this->assertEquals($expected, $docBlock->generate()); }
/** * Test if can add a new line to existing code. */ public function testAddLineToExistingCode() { $line1 = sha1(microtime(true)); $line2 = sha1(microtime(true)); $lineFeed = Generator::getConfig()->getNewline(); $expected = $line1 . $lineFeed; $expected .= $line2; $code = new PHPRawCode(); $code->setCode($line1); $code->addLine($line2); $this->assertSame($expected, $code->getCode()); }
/** * Get the content from the given file and replace all line endings with the * current `Generator::LINE_FEED` character. * * @param string $file The name of the file to load. * @return string The content of the file with the current line ending. */ protected function getFileContent($file) { $content = file_get_contents($file); $content = preg_replace('/\\r\\n|\\r|\\n/', Generator::getConfig()->getNewline(), $content); return $content; }