Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Although it does not handle advanced data, it is JUnit xsd compliant!
- Loading branch information
Showing
5 changed files
with
290 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Feature: Use the JUnit formatter | ||
In order to provide my CI tool with parsable phpspec results | ||
As a developper | ||
I need to be able to use a JUnit formatter | ||
|
||
Scenario: Successfully export phpspec results in JUnit format | ||
Given the spec file "spec/Formatter/SpecExample/MarkdownSpec.php" contains: | ||
""" | ||
<?php | ||
namespace spec\Formatter\SpecExample; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
class MarkdownSpec extends ObjectBehavior | ||
{ | ||
function it_converts_plain_text_to_html_paragraphs() | ||
{ | ||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>'); | ||
} | ||
} | ||
""" | ||
And the class file "src/Formatter/SpecExample/Markdown.php" contains: | ||
""" | ||
<?php | ||
namespace Formatter\SpecExample; | ||
class Markdown | ||
{ | ||
public function toHtml($text) | ||
{ | ||
return sprintf('<p>%s</p>', $text); | ||
} | ||
} | ||
""" | ||
When I run phpspec using the "junit" format | ||
Then I should see valid junit output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace spec\PhpSpec\Formatter; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use PhpSpec\Formatter\Presenter\PresenterInterface; | ||
use PhpSpec\IO\IOInterface; | ||
use PhpSpec\Listener\StatisticsCollector; | ||
use PhpSpec\Event\SpecificationEvent; | ||
use PhpSpec\Event\ExampleEvent; | ||
use PhpSpec\Loader\Node\SpecificationNode; | ||
use PhpSpec\Event\SuiteEvent; | ||
|
||
class JUnitFormatterSpec extends ObjectBehavior | ||
{ | ||
function let( | ||
PresenterInterface $presenter, | ||
IOInterface $io, | ||
StatisticsCollector $stats | ||
) { | ||
$this->beConstructedWith($presenter, $io, $stats); | ||
} | ||
|
||
function it_stores_a_testcase_node_after_example_run( | ||
ExampleEvent $event, | ||
SpecificationNode $specification, | ||
\ReflectionClass $class | ||
) { | ||
$event->getResult()->willReturn(ExampleEvent::PASSED); | ||
$event->getTitle()->willReturn('example title'); | ||
|
||
$this->afterExample($event); | ||
|
||
$this->getTestCaseNodes()->shouldReturn([ | ||
'<testcase name="example title" />' | ||
]); | ||
} | ||
|
||
function it_aggregates_testcase_nodes_and_store_them_after_specification_run(SpecificationEvent $event) | ||
{ | ||
$event->getTitle()->willReturn('specification title'); | ||
|
||
$this->setTestCaseNodes(array( | ||
'<testcase name="example1" />', | ||
'<testcase name="example2" />', | ||
'<testcase name="example3" />', | ||
)); | ||
$this->afterSpecification($event); | ||
|
||
$this->getTestSuiteNodes()->shouldReturn([ | ||
'<testsuite name="specification title" tests="3">' . "\n" . | ||
'<testcase name="example1" />' . "\n" . | ||
'<testcase name="example2" />' . "\n" . | ||
'<testcase name="example3" />' . "\n" . | ||
'</testsuite>' | ||
]); | ||
$this->getTestCaseNodes()->shouldHaveCount(0); | ||
} | ||
|
||
function it_aggregates_testsuite_nodes_and_display_them_after_suite_run(SuiteEvent $event, $io) | ||
{ | ||
$this->setTestSuiteNodes(array( | ||
'<testsuite name="specification1" tests="3">' . "\n" . | ||
'<testcase name="example1" />' . "\n" . | ||
'<testcase name="example2" />' . "\n" . | ||
'<testcase name="example3" />' . "\n" . | ||
'</testsuite>', | ||
'<testsuite name="specification2" tests="2">' . "\n" . | ||
'<testcase name="example1" />' . "\n" . | ||
'<testcase name="example2" />' . "\n" . | ||
'</testsuite>' | ||
)); | ||
$this->afterSuite($event); | ||
$io->write( | ||
'<testsuites>' . "\n" . | ||
'<testsuite name="specification1" tests="3">' . "\n" . | ||
'<testcase name="example1" />' . "\n" . | ||
'<testcase name="example2" />' . "\n" . | ||
'<testcase name="example3" />' . "\n" . | ||
'</testsuite>' . "\n" . | ||
'<testsuite name="specification2" tests="2">' . "\n" . | ||
'<testcase name="example1" />' . "\n" . | ||
'<testcase name="example2" />' . "\n" . | ||
'</testsuite>' . "\n" . | ||
'</testsuites>' | ||
)->shouldBeCalled(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.