Skip to content

Commit

Permalink
Fix dataProvider tests with user output (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-mxp authored Jun 27, 2024
1 parent ea5daba commit 9e4709f
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 3 deletions.
5 changes: 2 additions & 3 deletions junit-handler/src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ private function parseTestCases(
$output['name'] = $testdox->getDescription();
}

$testName = $method->getName();
if ($this->teamcityResult->hasOutputOf($testName)) {
$output['output'] = $this->teamcityResult->outputOf($testName);
if ($this->teamcityResult->hasOutputOf($name)) {
$output['output'] = $this->teamcityResult->outputOf($name);
}

foreach ($testcase->children() ?? [] as $name => $data) {
Expand Down
7 changes: 7 additions & 0 deletions tests/dataProvider-error-with-user-output/HelloWorld.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

function helloWorld()
{
echo "Some output";
throw new \BadFunctionCallException("Implement the helloWorld() function");
}
25 changes: 25 additions & 0 deletions tests/dataProvider-error-with-user-output/HelloWorldTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

class HelloWorldTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
{
require_once 'HelloWorld.php';
}

static public function input(): array
{
return [
['first input'],
['second input'],
];
}

/** @dataProvider input */
public function testHelloWorld($input): void
{
$this->assertEquals('Hello, World!', helloWorld($input));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":3,"status":"fail","tests":[{"name":"testHelloWorld with data set #0","status":"error","test_code":"$this->assertEquals('Hello, World!', helloWorld($input));\n","output":"Some output","message":"HelloWorldTest::testHelloWorld with data set #0\nBadFunctionCallException: Implement the helloWorld() function\n\nHelloWorld.php:6\nHelloWorldTest.php:23"},{"name":"testHelloWorld with data set #1","status":"error","test_code":"$this->assertEquals('Hello, World!', helloWorld($input));\n","output":"Some output","message":"HelloWorldTest::testHelloWorld with data set #1\nBadFunctionCallException: Implement the helloWorld() function\n\nHelloWorld.php:6\nHelloWorldTest.php:23"}]}
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions tests/dataProvider-fail-with-user-output/HelloWorld.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

function helloWorld()
{
echo "Some output";
return "Goodbye, Mars!";
}
25 changes: 25 additions & 0 deletions tests/dataProvider-fail-with-user-output/HelloWorldTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

class HelloWorldTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
{
require_once 'HelloWorld.php';
}

static public function input(): array
{
return [
['first input'],
['second input'],
];
}

/** @dataProvider input */
public function testHelloWorld($input): void
{
$this->assertEquals('Hello, World!', helloWorld($input));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":3,"status":"fail","tests":[{"name":"testHelloWorld with data set #0","status":"fail","test_code":"$this->assertEquals('Hello, World!', helloWorld($input));\n","output":"Some output","message":"HelloWorldTest::testHelloWorld with data set #0\nFailed asserting that two strings are equal.\n--- Expected\n+++ Actual\n@@ @@\n-'Hello, World!'\n+'Goodbye, Mars!'\n\nHelloWorldTest.php:23"},{"name":"testHelloWorld with data set #1","status":"fail","test_code":"$this->assertEquals('Hello, World!', helloWorld($input));\n","output":"Some output","message":"HelloWorldTest::testHelloWorld with data set #1\nFailed asserting that two strings are equal.\n--- Expected\n+++ Actual\n@@ @@\n-'Hello, World!'\n+'Goodbye, Mars!'\n\nHelloWorldTest.php:23"}]}
10 changes: 10 additions & 0 deletions tests/dataProvider-partial-fail-with-user-output/HelloWorld.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

function helloWorld($input)
{
if ($input !== 'first input') {
echo "Some output";
return "Goodbye, Mars!";
}
return "Hello, World!";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

class HelloWorldTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
{
require_once 'HelloWorld.php';
}

static public function input(): array
{
return [
['first input'],
['second input'],
];
}

/** @dataProvider input */
public function testHelloWorld($input): void
{
$this->assertEquals('Hello, World!', helloWorld($input));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":3,"status":"fail","tests":[{"name":"testHelloWorld with data set #0","status":"pass","test_code":"$this->assertEquals('Hello, World!', helloWorld($input));\n"},{"name":"testHelloWorld with data set #1","status":"fail","test_code":"$this->assertEquals('Hello, World!', helloWorld($input));\n","output":"Some output","message":"HelloWorldTest::testHelloWorld with data set #1\nFailed asserting that two strings are equal.\n--- Expected\n+++ Actual\n@@ @@\n-'Hello, World!'\n+'Goodbye, Mars!'\n\nHelloWorldTest.php:23"}]}
7 changes: 7 additions & 0 deletions tests/dataProvider-success-with-user-output/HelloWorld.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

function helloWorld()
{
echo "Some output";
return "Hello, World!";
}
25 changes: 25 additions & 0 deletions tests/dataProvider-success-with-user-output/HelloWorldTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

class HelloWorldTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
{
require_once 'HelloWorld.php';
}

static public function input(): array
{
return [
['first input'],
['second input'],
];
}

/** @dataProvider input */
public function testHelloWorld($input): void
{
$this->assertEquals('Hello, World!', helloWorld($input));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":3,"status":"pass","tests":[{"name":"testHelloWorld with data set #0","status":"pass","test_code":"$this->assertEquals('Hello, World!', helloWorld($input));\n","output":"Some output"},{"name":"testHelloWorld with data set #1","status":"pass","test_code":"$this->assertEquals('Hello, World!', helloWorld($input));\n","output":"Some output"}]}

0 comments on commit 9e4709f

Please sign in to comment.