Skip to content

Commit 46e46b4

Browse files
committed
Allowing fixed filename to be set
1 parent 3dddccf commit 46e46b4

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

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: 15 additions & 7 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

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)