Skip to content

bug in PHPUnit Manual 9.5: Examples 3.1 #227

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

Closed
ricfio opened this issue Mar 28, 2021 · 0 comments
Closed

bug in PHPUnit Manual 9.5: Examples 3.1 #227

ricfio opened this issue Mar 28, 2021 · 0 comments

Comments

@ricfio
Copy link
Contributor

ricfio commented Mar 28, 2021

Problem

Q A
PHPUnit version 9.5.4
PHP version 8.0.1
Installation Method Composer

Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /workspaces/phpunit-tutorial/www/tests/TestCaseClass.php on line 4

Fix

ricfio#3

How to reproduce

Example 3.1 Named data sets

<?php
use PHPUnit\Framework\TestCase;

namespace TestNamespace;

class TestCaseClass extends TestCase
{
    /**
     * @dataProvider provider
     */
    public function testMethod($data)
    {
        $this->assertTrue($data);
    }

    public function provider()
    {
        return [
            'my named data' => [true],
            'my data'       => [true]
        ];
    }
}
# phpunit tests/TestCaseClass.php
Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /workspaces/phpunit-tutorial/www/tests/TestCaseClass.php on line 4

How to solve

In tests/DataTest.php apply this fix

- use PHPUnit\Framework\TestCase;

  namespace TestNamespace;

+ use PHPUnit\Framework\TestCase;
+ 
ricfio added a commit to ricfio/phpunit-documentation-english that referenced this issue Mar 28, 2021
Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script
sebastianbergmann#227
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant