Skip to content

Commit c892d4a

Browse files
authored
Merge pull request #6 from dennisinteractive/support_fixed_filename
Support fixed filename for report file
2 parents 3dddccf + fa9e626 commit c892d4a

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ bin/behat -f cucumber_json
4040

4141
- `fileNamePrefix`: Filename prefix of generated report
4242
- `outputDir`: Generated report will be placed in this directory
43+
- `fileName` _(optional)_: Filename of generated report - current feature name will be used by default.
4344

4445
## Licence
4546

src/Extension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function configure(ArrayNodeDefinition $builder)
3939
{
4040
$builder->children()->scalarNode('fileNamePrefix')->defaultValue('report');
4141
$builder->children()->scalarNode('outputDir')->defaultValue('build/tests');
42+
$builder->children()->scalarNode('fileName');
4243
}
4344

4445
/**
@@ -52,6 +53,10 @@ public function load(ContainerBuilder $container, array $config)
5253
$definition->addArgument($config['fileNamePrefix']);
5354
$definition->addArgument($config['outputDir']);
5455

56+
if (!empty($config['fileName'])) {
57+
$definition->addMethodCall('setFileName', [$config['fileName']]);
58+
}
59+
5560
$container
5661
->setDefinition('json.formatter', $definition)
5762
->addTag('output.formatter')

src/Formatter/Formatter.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public static function getSubscribedEvents()
7373
];
7474
}
7575

76+
/** @inheritdoc */
77+
public function setFileName($fileName) {
78+
$this->printer->setResultFileName($fileName);
79+
}
80+
7681
/** @inheritdoc */
7782
public function getDescription()
7883
{
@@ -123,13 +128,16 @@ public function onAfterExercise(TestworkEvent\ExerciseCompleted $event)
123128
$this->timer->stop();
124129

125130
$this->renderer->render();
126-
$this->printer->setResultFileName(
127-
str_replace(
128-
DIRECTORY_SEPARATOR,
129-
FileOutputPrinter::FILE_SEPARATOR,
130-
$this->currentFeature->getFilenameForReport()
131-
)
132-
);
131+
if (!$this->printer->getResultFileName()) {
132+
$this->printer->setResultFileName(
133+
str_replace(
134+
DIRECTORY_SEPARATOR,
135+
FileOutputPrinter::FILE_SEPARATOR,
136+
$this->currentFeature->getFilenameForReport()
137+
)
138+
);
139+
}
140+
133141
$this->printer->write($this->renderer->getResult());
134142
}
135143

@@ -299,7 +307,7 @@ public function onAfterStepTested(BehatEvent\AfterStepTested $event)
299307
$arguments = [];
300308
foreach ($result->getSearchResult()->getMatchedArguments() as $argument) {
301309
$a = new \stdClass();
302-
$a->val = $argument;
310+
$a->val = (string) $argument;
303311
$arguments[] = $a;
304312
}
305313
if ($arguments) {

src/Formatter/FormatterInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ interface FormatterInterface extends FormatterOutputInterface
1313
* @return Suite[]
1414
*/
1515
public function getSuites();
16+
17+
/**
18+
* Set a fixed filename, which will override the current feature filename.
19+
*
20+
* @param $fileName
21+
*/
22+
public function setFileName($fileName);
1623
}

src/Printer/FileOutputPrinter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public function setResultFileName($resultFileName)
7373
$this->resultFileName = $resultFileName;
7474
}
7575

76+
/**
77+
* @return string
78+
*/
79+
public function getResultFileName()
80+
{
81+
return $this->resultFileName;
82+
}
83+
7684
/** @inheritdoc */
7785
public function getOutputPath()
7886
{

0 commit comments

Comments
 (0)