Allow to differentiate between a template directory and a single template file.
authorGunnar Wrobel <p@rdus.de>
Tue, 11 Jan 2011 05:59:01 +0000 (06:59 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 11 Jan 2011 05:59:01 +0000 (06:59 +0100)
components/lib/Components/Helper/Templates.php
components/lib/Components/Runner/CiPrebuild.php
components/lib/Components/Runner/CiSetup.php
components/test/Components/Unit/Components/Helper/TemplatesTest.php

index 91b8e26..018d817 100644 (file)
@@ -44,17 +44,20 @@ class Components_Helper_Templates
     /**
      * 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;
     }
 
     /**
index 4854fe7..cf0c14f 100644 (file)
@@ -82,16 +82,18 @@ class Components_Runner_CiPrebuild
         }
 
         $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(
index 46a3e1a..68009f0 100644 (file)
@@ -93,9 +93,10 @@ class Components_Runner_CiSetup
         }
 
         $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(
index fffa020..06b9f5b 100644 (file)
@@ -37,20 +37,31 @@ extends Components_TestCase
 {
     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')
+        );
     }
 
     /**
@@ -64,10 +75,17 @@ extends Components_TestCase
 
     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