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 MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace KawaiiGherkin\Formatter; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Jefersson Nathan <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
final class ComposedFormatter |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var AbstractFormatter |
28
|
|
|
*/ |
29
|
|
|
private $featureDescription; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var AbstractFormatter |
33
|
|
|
*/ |
34
|
|
|
private $background; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var AbstractFormatter |
38
|
|
|
*/ |
39
|
|
|
private $scenario; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var AbstractFormatter |
43
|
|
|
*/ |
44
|
|
|
private $tags; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param AbstractFormatter $featureDescription |
48
|
|
|
* @param AbstractFormatter $background |
49
|
|
|
* @param AbstractFormatter $scenario |
50
|
|
|
* @param AbstractFormatter $tags |
51
|
|
|
*/ |
52
|
|
|
public function __construct( |
53
|
|
|
AbstractFormatter $featureDescription, |
54
|
|
|
AbstractFormatter $background, |
55
|
|
|
AbstractFormatter $scenario, |
56
|
|
|
AbstractFormatter $tags |
57
|
|
|
) { |
58
|
|
|
$this->featureDescription = $featureDescription; |
59
|
|
|
$this->background = $background; |
60
|
|
|
$this->scenario = $scenario; |
61
|
|
|
$this->tags = $tags; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function __invoke($feature) |
65
|
|
|
{ |
66
|
|
|
$formatted = $feature->getLanguage() && $feature->getLanguage() !== 'en' ? '# language: ' . trim($feature->getLanguage()) . "\n" : ''; |
67
|
|
|
$formatted .= $feature->hasTags() ? $this->tags->format($feature->getTags()) . "\n" : ''; |
68
|
|
|
$formatted .= $this->featureDescription->format($feature) . "\n\n"; |
69
|
|
|
$formatted .= $feature->hasBackground() ? $this->background->format($feature->getBackground()) . "\n" : ''; |
70
|
|
|
$formatted .= $feature->hasScenarios() ? $this->scenario->format($feature->getScenarios()) : ''; |
71
|
|
|
|
72
|
|
|
return $formatted; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|