Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array / Object to string conversion in NamePrettifier #3270

Closed
sebastianbergmann opened this issue Sep 5, 2018 · 0 comments
Closed

Array / Object to string conversion in NamePrettifier #3270

sebastianbergmann opened this issue Sep 5, 2018 · 0 comments
Assignees
Labels
type/bug Something is broken

Comments

@sebastianbergmann
Copy link
Owner

<?php
class ExampleTest extends PHPUnit\Framework\TestCase
{
    /**
     * @dataProvider placeHolderprovider
     * @testdox ... $value ...
     */
    public function testWithPlaceholders($value): void
    {
        $this->assertTrue(true);
    }

    public function placeHolderprovider(): array
    {
        return [
            'boolean'          => [true],
            'integer'          => [1],
            'float'            => [1.0],
            'string'           => ['string'],
            'array'            => [[1, 2, 3]],
            'object'           => [new \stdClass],
            'stringableObject' => [new class {
                public function __toString()
                {
                    return 'string';
                }
            }],
            'resource'         => [\fopen(__FILE__, 'rb')],
            'null'             => [null]
        ];
    }
}

Actual

PHPUnit 7.3.3 by Sebastian Bergmann and contributors.

Example
 ✔ ... 1 ...
 ✔ ... 1 ...
 ✔ ... 1 ...
 ✔ ... string ...
PHP Notice:  Array to string conversion in /usr/local/src/phpunit/src/Util/TestDox/NamePrettifier.php on line 76
PHP Stack trace:
PHP   1. {main}() /usr/local/src/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /usr/local/src/phpunit/phpunit:53
PHP   3. PHPUnit\TextUI\Command->run() /usr/local/src/phpunit/src/TextUI/Command.php:159
PHP   4. PHPUnit\TextUI\TestRunner->doRun() /usr/local/src/phpunit/src/TextUI/Command.php:203
PHP   5. PHPUnit\Framework\TestSuite->run() /usr/local/src/phpunit/src/TextUI/TestRunner.php:587
PHP   6. PHPUnit\Framework\DataProviderTestSuite->run() /usr/local/src/phpunit/src/Framework/TestSuite.php:750
PHP   7. ExampleTest->run() /usr/local/src/phpunit/src/Framework/TestSuite.php:750
PHP   8. PHPUnit\Framework\TestResult->run() /usr/local/src/phpunit/src/Framework/TestCase.php:798
PHP   9. PHPUnit\Framework\TestResult->startTest() /usr/local/src/phpunit/src/Framework/TestResult.php:603
PHP  10. PHPUnit\Util\TestDox\CliTestDoxPrinter->startTest() /usr/local/src/phpunit/src/Framework/TestResult.php:395
PHP  11. PHPUnit\Util\TestDox\NamePrettifier->prettifyTestCase() /usr/local/src/phpunit/src/Util/TestDox/CliTestDoxPrinter.php:66
PHP  12. str_replace() /usr/local/src/phpunit/src/Util/TestDox/NamePrettifier.php:76
 ✔ ... Array ...
PHP Catchable fatal error:  Object of class stdClass could not be converted to string in /usr/local/src/phpunit/src/Util/TestDox/NamePrettifier.php on line 76
PHP Stack trace:
PHP   1. {main}() /usr/local/src/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /usr/local/src/phpunit/phpunit:53
PHP   3. PHPUnit\TextUI\Command->run() /usr/local/src/phpunit/src/TextUI/Command.php:159
PHP   4. PHPUnit\TextUI\TestRunner->doRun() /usr/local/src/phpunit/src/TextUI/Command.php:203
PHP   5. PHPUnit\Framework\TestSuite->run() /usr/local/src/phpunit/src/TextUI/TestRunner.php:587
PHP   6. PHPUnit\Framework\DataProviderTestSuite->run() /usr/local/src/phpunit/src/Framework/TestSuite.php:750
PHP   7. ExampleTest->run() /usr/local/src/phpunit/src/Framework/TestSuite.php:750
PHP   8. PHPUnit\Framework\TestResult->run() /usr/local/src/phpunit/src/Framework/TestCase.php:798
PHP   9. PHPUnit\Framework\TestResult->startTest() /usr/local/src/phpunit/src/Framework/TestResult.php:603
PHP  10. PHPUnit\Util\TestDox\CliTestDoxPrinter->startTest() /usr/local/src/phpunit/src/Framework/TestResult.php:395
PHP  11. PHPUnit\Util\TestDox\NamePrettifier->prettifyTestCase() /usr/local/src/phpunit/src/Util/TestDox/CliTestDoxPrinter.php:66
PHP  12. str_replace() /usr/local/src/phpunit/src/Util/TestDox/NamePrettifier.php:76

Expected

PHPUnit 7.3.3 by Sebastian Bergmann and contributors.

Example
 ✔ ... true ...
 ✔ ... 1 ...
 ✔ ... 1.0 ...
 ✔ ... string ...
 ✔ ... array ...
 ✔ ... object ...
 ✔ ... string ...
 ✔ ... resource ...
 ✔ ... NULL ...

Time: 31 ms, Memory: 4.00MB

OK (9 tests, 9 assertions)
@sebastianbergmann sebastianbergmann added the type/bug Something is broken label Sep 5, 2018
@sebastianbergmann sebastianbergmann self-assigned this Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

1 participant