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

Use PHPUnit 10 for testing #2409

Merged
merged 18 commits into from
Jun 20, 2023
Merged

Use PHPUnit 10 for testing #2409

merged 18 commits into from
Jun 20, 2023

Conversation

spawnia
Copy link
Collaborator

@spawnia spawnia commented Jun 5, 2023

No description provided.

composer.json Outdated Show resolved Hide resolved
@spawnia
Copy link
Collaborator Author

spawnia commented Jun 15, 2023

The remaining issue is this:

Failed asserting that exception of type "Illuminate\Contracts\Container\BindingResolutionException" matches expected exception "Nuwave\Lighthouse\Exceptions\DefinitionException". Message was: "Unresolvable dependency resolving [Parameter #0 [ <required> string $name ]] in class PHPUnit\Framework\TestCase" at
/home/runner/work/lighthouse/lighthouse/vendor/laravel/framework/src/Illuminate/Container/Container.php:1143
...
/home/runner/work/lighthouse/lighthouse/tests/Integration/Schema/Types/UnionTest.php:170

Essentially, the problem lies within the use of $this->qualifyTestResolver() - whereas PHPUnit\Framework\TestCase required no constructor arguments prior to PHPUnit 10, it now needs one - meaning the container cannot instantiate it. The only solution I can think of is to move the test resolvers to separate files, which will complicate things a bit.

@pyrou
Copy link
Collaborator

pyrou commented Jun 15, 2023

The remaining issue is this:

Failed asserting that exception of type "Illuminate\Contracts\Container\BindingResolutionException" matches expected exception "Nuwave\Lighthouse\Exceptions\DefinitionException". Message was: "Unresolvable dependency resolving [Parameter #0 [ <required> string $name ]] in class PHPUnit\Framework\TestCase" at
/home/runner/work/lighthouse/lighthouse/vendor/laravel/framework/src/Illuminate/Container/Container.php:1143
...
/home/runner/work/lighthouse/lighthouse/tests/Integration/Schema/Types/UnionTest.php:170

Essentially, the problem lies within the use of $this->qualifyTestResolver() - whereas PHPUnit\Framework\TestCase required no constructor arguments prior to PHPUnit 10, it now needs one - meaning the container cannot instantiate it. The only solution I can think of is to move the test resolvers to separate files, which will complicate things a bit.

This is a possible (dirty) workaround

https://laravel.com/docs/10.x/container#binding-primitives

$this->app->when(TestCase::class)
          ->needs('$name')
          ->give("TestName");

@spawnia
Copy link
Collaborator Author

spawnia commented Jun 19, 2023

Thanks @pyrou, unfortunately I could not get it to work. Could you check out the branch and see if you can make it work?

@pyrou
Copy link
Collaborator

pyrou commented Jun 19, 2023

Looks like because its called to early. Somehow it is reset somewhere

When moving code in TestCase::setUp() it works fine

// tests/TestCase.php
protected function setUp(): void
{
    parent::setUp();

    // This default is only valid for testing Lighthouse itself and thus
    // is not defined in the reusable test trait.
    $this->schema ??= self::PLACEHOLDER_QUERY;
    $this->setUpTestSchema();

    $this->app->when($this::class)
        ->needs('$name')
        ->give('TestName');

}

@spawnia
Copy link
Collaborator Author

spawnia commented Jun 20, 2023

Using $this was the key - I switched to static though, now it works fine.

@spawnia spawnia merged commit a1c031a into master Jun 20, 2023
1 check passed
@spawnia spawnia deleted the phpunit-10 branch June 20, 2023 13:30
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

Successfully merging this pull request may close these issues.

None yet

2 participants