1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19

20
/**
21
 * A wrapper for the implementations of PHPUnit2ResultFormatter.
22
 *
23
 * @author  Michiel Rook <mrook@php.net>
24
 * @package phing.tasks.ext.phpunit
25
 * @since   2.1.0
26
 */
27
class FormatterElement
28
{
29
    /**
30
     * @var PHPUnitResultFormatter7 $fomatter
31
     */
32
    protected $formatter;
33

34
    protected $type = "";
35

36
    protected $useFile = true;
37

38
    protected $toDir = ".";
39

40
    protected $outfile = "";
41

42
    protected $parent;
43

44
    /**
45
     * Sets parent task
46
     *
47
     * @param Task $parent Calling Task
48
     */
49 1
    public function setParent($parent)
50
    {
51 1
        $this->parent = $parent;
52
    }
53

54
    /**
55
     * Loads a specific formatter type
56
     *
57
     * @param string $type
58
     */
59 1
    public function setType($type)
60
    {
61 1
        $this->type = $type;
62
    }
63

64
    /**
65
     * Loads a specific formatter class
66
     *
67
     * @param $className
68
     */
69 0
    public function setClassName($className)
70
    {
71 0
        $classNameNoDot = Phing::import($className);
72

73 0
        $this->formatter = new $classNameNoDot();
74
    }
75

76
    /**
77
     * Sets whether to store formatting results in a file
78
     *
79
     * @param $useFile
80
     */
81 1
    public function setUseFile($useFile)
82
    {
83 1
        $this->useFile = $useFile;
84
    }
85

86
    /**
87
     * Returns whether to store formatting results in a file
88
     */
89 1
    public function getUseFile()
90
    {
91 1
        return $this->useFile;
92
    }
93

94
    /**
95
     * Sets output directory
96
     *
97
     * @param string $toDir
98
     * @throws IOException
99
     * @throws NullPointerException
100
     */
101 0
    public function setToDir($toDir)
102
    {
103 0
        if (!is_dir($toDir)) {
104 0
            $toDir = new PhingFile($toDir);
105 0
            $toDir->mkdirs();
106
        }
107

108 0
        $this->toDir = $toDir;
109
    }
110

111
    /**
112
     * Returns output directory
113
     *
114
     * @return string
115
     */
116 0
    public function getToDir()
117
    {
118 0
        return $this->toDir;
119
    }
120

121
    /**
122
     * Sets output filename
123
     *
124
     * @param string $outfile
125
     */
126 0
    public function setOutfile($outfile)
127
    {
128 0
        $this->outfile = $outfile;
129
    }
130

131
    /**
132
     * Returns output filename
133
     *
134
     * @return string
135
     */
136 0
    public function getOutfile()
137
    {
138 0
        if ($this->outfile) {
139 0
            return $this->outfile;
140
        }
141

142 0
        return $this->formatter->getPreferredOutfile() . $this->getExtension();
143
    }
144

145
    /**
146
     * Returns extension
147
     *
148
     * @return string
149
     */
150 0
    public function getExtension()
151
    {
152 0
        return $this->formatter->getExtension();
153
    }
154

155
    /**
156
     * Returns formatter object
157
     *
158
     * @throws BuildException
159
     * @return PHPUnitResultFormatter7
160
     */
161 1
    public function getFormatter()
162
    {
163 1
        if ($this->formatter !== null) {
164 1
            return $this->formatter;
165
        }
166

167 1
        if ($this->type === "summary") {
168 1
            $this->formatter = new SummaryPHPUnitResultFormatter7($this->parent);
169 1
        } elseif ($this->type === "clover") {
170 0
            $this->formatter = new CloverPHPUnitResultFormatter7($this->parent);
171 1
        } elseif ($this->type === "xml") {
172 1
            $this->formatter = new XMLPHPUnitResultFormatter7($this->parent);
173 1
        } elseif ($this->type === "plain") {
174 1
            $this->formatter = new PlainPHPUnitResultFormatter7($this->parent);
175 0
        } elseif ($this->type === "crap4j") {
176 0
            $this->formatter = new Crap4JPHPUnitResultFormatter7($this->parent);
177
        } else {
178 0
            throw new BuildException("Formatter '" . $this->type . "' not implemented");
179
        }
180

181 1
        return $this->formatter;
182
    }
183
}

Read our documentation on viewing source code .

Loading