PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/buildscripts/phing/classes/phing/tasks/ext/phpunit/FormatterElement.php

http://prado3.googlecode.com/
PHP | 178 lines | 90 code | 20 blank | 68 comment | 9 complexity | 95821df5f1ee381f83b3b7961fcf1b28 MD5 | raw file
Possible License(s): Apache-2.0, IPL-1.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * $Id: 296214ebac3a12e51bffed3dcc2c0bb93fb0754e $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/system/io/PhingFile.php';
  22. /**
  23. * A wrapper for the implementations of PHPUnit2ResultFormatter.
  24. *
  25. * @author Michiel Rook <mrook@php.net>
  26. * @version $Id: 296214ebac3a12e51bffed3dcc2c0bb93fb0754e $
  27. * @package phing.tasks.ext.phpunit
  28. * @since 2.1.0
  29. */
  30. class FormatterElement
  31. {
  32. protected $formatter = NULL;
  33. protected $type = "";
  34. protected $useFile = true;
  35. protected $toDir = ".";
  36. protected $outfile = "";
  37. protected $parent = NULL;
  38. /**
  39. * Sets parent task
  40. * @param Task $parent Calling Task
  41. */
  42. public function setParent($parent)
  43. {
  44. $this->parent = $parent;
  45. }
  46. /**
  47. * Loads a specific formatter type
  48. * @param string $type
  49. */
  50. public function setType($type)
  51. {
  52. $this->type = $type;
  53. if ($this->type == "summary")
  54. {
  55. require_once 'phing/tasks/ext/phpunit/formatter/SummaryPHPUnitResultFormatter.php';
  56. $this->formatter = new SummaryPHPUnitResultFormatter($this->parent);
  57. }
  58. else
  59. if ($this->type == "clover")
  60. {
  61. require_once 'phing/tasks/ext/phpunit/formatter/CloverPHPUnitResultFormatter.php';
  62. $this->formatter = new CloverPHPUnitResultFormatter($this->parent);
  63. }
  64. else
  65. if ($this->type == "xml")
  66. {
  67. require_once 'phing/tasks/ext/phpunit/formatter/XMLPHPUnitResultFormatter.php';
  68. $this->formatter = new XMLPHPUnitResultFormatter($this->parent);
  69. }
  70. else
  71. if ($this->type == "plain")
  72. {
  73. require_once 'phing/tasks/ext/phpunit/formatter/PlainPHPUnitResultFormatter.php';
  74. $this->formatter = new PlainPHPUnitResultFormatter($this->parent);
  75. }
  76. else
  77. {
  78. throw new BuildException("Formatter '" . $this->type . "' not implemented");
  79. }
  80. }
  81. /**
  82. * Loads a specific formatter class
  83. */
  84. public function setClassName($className)
  85. {
  86. $classNameNoDot = Phing::import($className);
  87. $this->formatter = new $classNameNoDot();
  88. }
  89. /**
  90. * Sets whether to store formatting results in a file
  91. */
  92. public function setUseFile($useFile)
  93. {
  94. $this->useFile = $useFile;
  95. }
  96. /**
  97. * Returns whether to store formatting results in a file
  98. */
  99. public function getUseFile()
  100. {
  101. return $this->useFile;
  102. }
  103. /**
  104. * Sets output directory
  105. * @param string $toDir
  106. */
  107. public function setToDir($toDir)
  108. {
  109. $this->toDir = $toDir;
  110. }
  111. /**
  112. * Returns output directory
  113. * @return string
  114. */
  115. public function getToDir()
  116. {
  117. return $this->toDir;
  118. }
  119. /**
  120. * Sets output filename
  121. * @param string $outfile
  122. */
  123. public function setOutfile($outfile)
  124. {
  125. $this->outfile = $outfile;
  126. }
  127. /**
  128. * Returns output filename
  129. * @return string
  130. */
  131. public function getOutfile()
  132. {
  133. if ($this->outfile)
  134. {
  135. return $this->outfile;
  136. }
  137. else
  138. {
  139. return $this->formatter->getPreferredOutfile() . $this->getExtension();
  140. }
  141. }
  142. /**
  143. * Returns extension
  144. * @return string
  145. */
  146. public function getExtension()
  147. {
  148. return $this->formatter->getExtension();
  149. }
  150. /**
  151. * Returns formatter object
  152. * @return PHPUnitResultFormatter
  153. */
  154. public function getFormatter()
  155. {
  156. return $this->formatter;
  157. }
  158. }