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

LogicException running test suite against database #10837

Closed
dcentrica opened this issue Jun 23, 2023 · 1 comment
Closed

LogicException running test suite against database #10837

dcentrica opened this issue Jun 23, 2023 · 1 comment

Comments

@dcentrica
Copy link

dcentrica commented Jun 23, 2023

Affected Version

silverstripe/framework 5.0.4
phpunit/phpunit 9.6.8

Description

This is a framework-only project. No silverstripe/cms package. The default test DB has the proper GRANTs set but when I'm trying to run tests using the database, it results in the error:

#> ./vendor/bin/phpunit
PHPUnit 9.6.8 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 00:01.129, Memory: 20.00 MB

There was 1 error:

1) Path\To\My\Tests\ServerTest::testMethodsAllowed
LogicException: getItemPath returned null for Path\To\My\Tests\ServerTest. Try adding flush=1 to the test run.

Adding flush=all|1 of course does nothing, as neither does rm -rf /tmp/silverstripe-cache*

Similar issues are described here in framework version 4:

I've noticed that using one or both of the following in the test class, the error goes away and the suite passes (but of course I cannot develop any tests against the database).

class ServerTest extends FunctionalTest
{
   // commenting this, hides the error
   protected static $fixture_file = [
       'test/API/fixtures/ServerTest.yml',
   ];

  // commenting this, hides the error
  protected $usesDatabase = true;

  ....
}

Poking around in SapphireTest where the exception is thrown originally, there are two spots where it can be thrown, the guilty party is FixtureTestState::getTestAbsolutePath().

I've tried moving the test suite and its fixture into the top level "test" dir = same problem.

FYI my directory structure is as follows:

+ public
+ app
+ test
  - ServerTest.php
  - ServerTest.yml

Contents of phpunit.dist.xml

<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
    <testsuite name="Default">
        <directory>test</directory>
    </testsuite>
</phpunit>

Steps to Reproduce

#> ./vendor/bin/phpunit
@dcentrica
Copy link
Author

Hmmm, after more screwing around with directory structures, I came up with this, which worked :-\

    /**
     * @var array
     */
    protected static $fixture_file = [
        'app/test/fixtures/ServerTest.yml',
    ];

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