/**
* Constructor.
*
- * @param string $source The template(s) source path.
- * @param string $target The template(s) target path.
+ * @param string $sdir The templates source directory.
+ * @param string $tdir The templates target directory.
+ * @param string $sfile The exact template source file.
+ * @param string $tfile The exact template target file.
*/
- public function __construct($source, $target)
+ public function __construct($sdir, $tdir, $sfile = '', $tfile = '')
{
- if (file_exists($source . '.template')) {
- $this->_source = $source . '.template';
+ $source = $sdir . DIRECTORY_SEPARATOR . $sfile . '.template';
+ if (file_exists($source)) {
+ $this->_source = $source;
} else {
throw new Components_Exception("No template at $source!");
}
- $this->_target = $target;
+ $this->_target = $tdir . DIRECTORY_SEPARATOR . $tfile;
}
/**
}
$build_template = new Components_Helper_Templates(
- $this->_config_application->getTemplateDirectory()
- . DIRECTORY_SEPARATOR . 'hudson-component-build.xml',
- $options['ciprebuild'] . DIRECTORY_SEPARATOR . 'build.xml'
+ $this->_config_application->getTemplateDirectory(),
+ $options['ciprebuild'],
+ 'hudson-component-build.xml',
+ 'build.xml'
);
$build_template->write(array('toolsdir' => $options['toolsdir']));
$phpunit_template = new Components_Helper_Templates(
- $this->_config_application->getTemplateDirectory()
- . DIRECTORY_SEPARATOR . 'hudson-component-phpunit.xml',
- $options['ciprebuild'] . DIRECTORY_SEPARATOR . 'phpunit.xml'
+ $this->_config_application->getTemplateDirectory(),
+ $options['ciprebuild'],
+ 'hudson-component-phpunit.xml',
+ 'phpunit.xml'
);
$phpunit_template->write(
array(
}
$config_template = new Components_Helper_Templates(
- $this->_config_application->getTemplateDirectory()
- . DIRECTORY_SEPARATOR . 'hudson-component-config.xml',
- $options['cisetup'] . DIRECTORY_SEPARATOR . 'config.xml'
+ $this->_config_application->getTemplateDirectory(),
+ $options['cisetup'],
+ 'hudson-component-config.xml',
+ 'config.xml'
);
$config_template->write(
array(
{
public function testWrite()
{
- $source = dirname(__FILE__) . '/../../../fixture/templates/simple';
- $target = $this->getTemporaryDirectory() . '/target';
- $templates = new Components_Helper_Templates($source, $target);
+ $tdir = $this->getTemporaryDirectory();
+ $templates = new Components_Helper_Templates(
+ dirname(__FILE__) . '/../../../fixture/templates',
+ $tdir,
+ 'simple',
+ 'target'
+ );
$templates->write();
- $this->assertTrue(file_exists($target));
+ $this->assertTrue(file_exists($tdir . DIRECTORY_SEPARATOR . 'target'));
}
public function testSource()
{
- $source = dirname(__FILE__) . '/../../../fixture/templates/simple';
- $target = $this->getTemporaryDirectory() . '/target';
- $templates = new Components_Helper_Templates($source, $target);
+ $tdir = $this->getTemporaryDirectory();
+ $templates = new Components_Helper_Templates(
+ dirname(__FILE__) . '/../../../fixture/templates',
+ $tdir,
+ 'simple',
+ 'target'
+ );
$templates->write();
- $this->assertEquals("SIMPLE\n", file_get_contents($target));
+ $this->assertEquals(
+ "SIMPLE\n",
+ file_get_contents($tdir . DIRECTORY_SEPARATOR . 'target')
+ );
}
/**
public function testVariables()
{
- $source = dirname(__FILE__) . '/../../../fixture/templates/variables';
- $target = $this->getTemporaryDirectory() . '/target';
- $templates = new Components_Helper_Templates($source, $target);
+ $tdir = $this->getTemporaryDirectory();
+ $templates = new Components_Helper_Templates(
+ dirname(__FILE__) . '/../../../fixture/templates',
+ $tdir,
+ 'variables',
+ 'target'
+ );
$templates->write(array('1' => 'One', '2' => 'Two'));
- $this->assertEquals("One : Two\n", file_get_contents($target));
+ $this->assertEquals(
+ "One : Two\n",
+ file_get_contents($tdir . DIRECTORY_SEPARATOR . 'target')
+ );
}
}
\ No newline at end of file