public function process(Config\Template $tmpl)
 {
     /* process template if condition is not set or condition is valid */
     if ($tmpl->getCondition() == null || $this->conditionValidator->isValid($tmpl->getCondition(), $this->vars)) {
         /* load source file */
         if (is_file($tmpl->getSource())) {
             $content = file_get_contents($tmpl->getSource());
             /* replace all vars by values */
             if (is_array($this->vars)) {
                 foreach ($this->vars as $key => $value) {
                     $content = str_replace('${' . $key . '}', $value, $content);
                 }
             }
             /* save destination file */
             if (is_file($tmpl->getDestination()) && !$tmpl->isCanRewrite()) {
                 $this->io->write(__CLASS__ . ": <comment>Destination file '{$tmpl->getDestination()}' is already exist and cannot be rewrote (rewrite = false).</comment>");
             } else {
                 $this->fileSaver->save($tmpl->getDestination(), $content);
                 $this->io->write(__CLASS__ . ": <info>Destination file '{$tmpl->getDestination()}' is created from source template '{$tmpl->getSource()}'.</info>");
             }
         } else {
             $this->io->writeError(__CLASS__ . ": <error>Cannot open source template ({$tmpl->getSource()}).</error>");
         }
     } else {
         /* there is wrong condition for template */
         $outSrc = $tmpl->getSource();
         $cond = $tmpl->getCondition();
         $outCond = '${' . $cond->getVar() . '}' . $cond->getOperation() . $cond->getValue();
         $this->io->write(__CLASS__ . ": <comment>Skip processing of the template ({$outSrc}) because condition ({$outCond}) is 'false'.</comment>");
     }
 }
 public function test_dstExists_withoutRewrite()
 {
     /** === Test Data === */
     $src = FILE_SRC_DUMP;
     $dst = FILE_DST_DUMP;
     $saver = new FileSaver();
     $saver->save($dst, 'content');
     $tmpl = new Template();
     $tmpl->setSource($src);
     $tmpl->setDestination($dst);
     $tmpl->setCanRewrite(false);
     /** === Setup Mocks === */
     $expected = self::CLAZZ . ": <comment>Destination file '{$dst}' is already exist and cannot be rewrote (rewrite = false).</comment>";
     $this->mIo->shouldReceive('write')->once()->with($expected);
     /** === Call and asserts  === */
     $proc = new Handler([], $this->mIo);
     $proc->process($tmpl);
     unlink($dst);
 }