public function testReaderInvalidSourceCodeThrowsException() { $r = $this->getMock('cfhCompile_CodeReader_ReadStrategy_Null'); $r->expects($this->any())->method('getSourceCode')->will($this->returnValue(FALSE)); $c = new cfhCompile_Class_Reflection($this); $cr = new cfhCompile_CodeReader(); $cr->setReadStrategy($r); try { $cr->getSourceCode($c); } catch (cfhCompile_CodeReader_Exception $e) { return; } $this->fail('Expecting to catch cfhCompile_CodeReader_Exception.'); }
public function testCodeWriterCalledIfSourceNotNull() { $class = new cfhCompile_Class_Reflection($this); $cr = new cfhCompile_ClassRegistry(); $w = $this->getMock('cfhCompile_CodeWriter_WriteStrategy_Interface'); $w->expects($this->once())->method('begin'); $w->expects($this->once())->method('write')->with($this->equalTo($class), $this->equalTo('/* source code */'), $this->equalTo($cr)); $w->expects($this->once())->method('commit'); $rs = $this->getMock('cfhCompile_CodeReader_ReadStrategy_Interface'); $rs->expects($this->once())->method('getSourceCode')->will($this->returnValue('/* source code */')); $r = new cfhCompile_CodeReader(); $r->setReadStrategy($rs); $i = new cfhCompile_ClassIterator_Manual(); $i->attach($class); $c = new cfhCompile_Compiler(); $c->setCodeReader($r); $c->setCodeWriter($w); $c->setClassIterator($i); $c->setClassRegistry($cr); $c->compile(); }
* Compiles the cfhCompile library and places the compiled file into the * tests directory. The unit test should pick up this file so we can then * run the unis tests to make sure that the compiled file is OK. * * @category cfh * @package cfhCompile * @subpackage Examples * @copyright Copyright (c) 2007 - 2008 William Bailey <*****@*****.**>. * @license http://www.gnu.org/licenses/lgpl.html Lesser GPL * @version $Id$ */ $base = realpath(dirname(__FILE__)) . '/'; require_once $base . '../library/cfhCompile/Loader.php'; cfhCompile_Loader::registerAutoload(); $classIterator = new cfhCompile_ClassIterator_FileInfo(); $classIterator->attach(new RecursiveDirectoryIterator($base . '../library/cfhCompile')); $classIterator->attachFilter(new cfhCompile_ClassIterator_FileInfo_Filter_FileExtension('.php')); $codeReader = new cfhCompile_CodeReader(); $codeReader->setReadStrategy(new cfhCompile_CodeReader_ReadStrategy_Tokenizer()); $codeWriter = new cfhCompile_CodeWriter(); $codeWriter->setWriteStrategy(new cfhCompile_CodeWriter_WriteStrategy_AtomicStream($base . '../tests/cfhCompile.compiled.php')); $codeWriter->attachPlugin(new cfhCompile_CodeWriter_Plugin_FileConstantSubstitute()); $codeWriter->attachPlugin(new cfhCompile_CodeWriter_Plugin_StripComments()); $codeWriter->attachPlugin(new cfhCompile_CodeWriter_Plugin_StripWhiteSpace()); $codeWriter->attachPlugin(new cfhCompile_CodeWriter_Plugin_Padding()); $c = new cfhCompile_Compiler(); $c->setClassIterator($classIterator); $c->setCodeReader($codeReader); $c->setCodeWriter($codeWriter); $c->attachObserver(new cfhCompile_Compiler_Observer_SimpleLogger(fopen('php://output', 'r'))); $c->compile();