/** * Test already exists * * @expectedException Naneau\FileGen\Generator\Exception\NodeExists * * @return void **/ public function testAlreadyExists() { $structure = new Structure(); $structure->file('foo', 'foo'); $generator = $this->createGenerator(); // dir exists already... oh noes. file_put_contents($generator->getRoot() . '/foo', 'foo'); $generator->generate($structure); }
/** * Test simple creation * * @return void **/ public function testCreation() { $generator = $this->createGenerator(); $structure = new Structure(); $structure->file('foo', 'foo contents')->link($generator->getRoot() . '/foo', 'bar'); $generator->generate($structure); // See if structure was generated $this->assertEquals(file_get_contents($generator->getRoot() . '/bar'), 'foo contents'); }
/** * Parameters * * @return void **/ public function testMissingParameters() { $generator = $this->createGenerator(); $structure = new Structure(); $structure->file('foo', new TwigContents($this->createTwig()->loadTemplate('template_two.twig'), array('foo' => 'foo', 'baz' => 'baz'))); $generator->generate($structure); // See if structure was generated $this->assertEquals(file_get_contents($generator->getRoot() . '/foo'), "foo baz\n"); }
/** * Test copy fail * * @expectedException Naneau\FileGen\File\Contents\Exception * @return void **/ public function testNotReadable() { $generator = $this->createGenerator(); // Create unreadable file touch($generator->getRoot() . '/not-readable'); chmod($generator->getRoot() . '/not-readable', 00); $structure = new Structure(); $structure->file('bar', new CopyContents($generator->getRoot() . '/not-readable')); $generator->generate($structure); }
/** * test invalid structure * * @expectedException Naneau\FileGen\Structure\Exception * @return void **/ public function testDirectoryFileMix() { // Can't add file under a node that's a file already $structure = new Structure(); $structure->file('foo', 'bar contents')->file('foo/baz', 'baz contents'); }