Problem/Motivation

When using a bare PHP install, missing extensions can trigger unclear error messages.

Proposed resolution

PHPUnit provides functionality for documenting and providing feedback to the user about the missing extension with the @requires annotation so we should use is.

Remaining tasks

Patch, Review, Commit.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

neclimdul created an issue. See original summary.

neclimdul’s picture

Status: Active » Needs review
FileSize
1.27 KB

curl is pretty obvious, missing constant error with a CURL_* constant. Still this is going to be clearer.

gd is not obvious unless you're familiar with php's wonky function names and the fact that image_* refers to gd methods.

dawehner’s picture

curl is pretty obvious, missing constant error with a CURL_* constant. Still this is going to be clearer.

What about requiring the CURL php extension in the require-dev section of composer.json? All tests basically rely on CURL, don't they, so adding it to individual classes doesn't really make that much sense.

neclimdul’s picture

Pretty sure only WebTests need CURL as a general rule.

dawehner’s picture

That is a good point! On the other hand we never trigger CURL in those tests, don't we?

On top of that I was wondering whether we could add requirements in BrowserTestBase (as a property or so), but well, sadly this is not actually the case. It just supports annotations, see
\PHPUnit_Util_Test::getRequirements

neclimdul’s picture

No I don't think we call curl methods in those tests but we do trigger code that uses the constants which is for these purposes the same. If those constants where moved we could easily move these requirements closer to the methods testing curls.

That said, its pretty reasonable to expect to have the curl extension installed since we document its requirement. Going through all that effort probably isn't worth it. Backstory, the curl extension was accidentally uninstalled for me during an upgrade and the tests telling me the constant was missing briefly made me thing something was broken in the tests or a curl was compiled wrong or something instead of immediately realizing the extension was missing. This just improved the DX of the failures by telling you the extension is missing.

For the BrowserTestBase requirement checking, I would suggest using markTestSkipped in setup as documented here:
https://phpunit.de/manual/current/en/incomplete-and-skipped-tests.html#i...

We do something similar in migrate tests. Its not in setup but a setup helper method for I'm sure good reasons I don't know or remember but its the same idea.
http://cgit.drupalcode.org/drupal/tree/core/modules/migrate/tests/src/Un...

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, I assume we don't need "@requires extension curl" on BrowserTestBase because it use Mink/Goutte/Guzzle which falls back to sockets if curl is not available, right?

Related: #2742541: ApcuBackendTest is skipped in phpunit because of wrong @requires

tstoeckler’s picture

What about requiring the CURL php extension in the require-dev section of composer.json?

I still think that makes sense because without it you cannot enable Simpletest module, so I think that fits the "require-dev" semantic pretty well, but maybe that's a separate issue.

klausi’s picture

In a post-Simpletest world people will not enable any module when they execute phpunit.

So I think the @requires declaration just on the test classes is fine, otherwise we would also add GD to require-dev in composer.json, right?

neclimdul’s picture

re #7 Wasn't sure but just disabled curl and that seems to be the case.

re #8 Yeah, it might seem like a generally bad idea to develop without curl but its not actually a requirement. Additionally, we might actually want to run tests without curl since we don't require it for normal sites.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0d4a373 and pushed to 8.1.x and 8.2.x. Thanks!

  • alexpott committed b292739 on 8.2.x
    Issue #2714607 by neclimdul: Use phpunit's requires to require some...

  • alexpott committed 0d4a373 on 8.1.x
    Issue #2714607 by neclimdul: Use phpunit's requires to require some...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.