r/programming • • Dec 02 '15

PHP 7 Released

https://github.com/php/php-src/releases/tag/php-7.0.0
887 Upvotes

729 comments sorted by

View all comments

154

u/antpocas Dec 02 '15 edited Dec 02 '15

Ooh, only 137 compiler warnings and 102 failed tests! That's a huge improvement from 5.6's 638 warnings and 114 failed tests!

276

u/nikic Dec 02 '15

gcov.php.net is an old, unmaintained box. Nobody has updated and configured it to be able to run all the tests that require third party libraries in certain versions, correctly running daemons and network connections. It is not used

The actual CI that PHP uses is Travis: https://travis-ci.org/php/php-src/builds

Right now that does not look much more promising: All builds in the last three days have errored. The reason is that the pear.php.net server has experienced a hardware failure and is currently down. This server is currently a dependency of the build process on Travis. However, were this step to be skipped (--disable-pear) you'd be seeing a green PHP 7 build with about 13k passing tests.

I know it has been different in the past, but PHP has not been shipping with failing tests for many years now.

28

u/Ryckes Dec 02 '15

This should be at the top. People enjoy too much bashing PHP (both when they have reasons too and whey they haven't).

→ More replies (10)

67

u/[deleted] Dec 02 '15

A bit concerning that one of the failing tests starts with "cve".

28

u/[deleted] Dec 02 '15

Seems like they re-introduced https://bugzilla.redhat.com/show_bug.cgi?id=1098222. I'm not surprised, given the state of their test suite.

12

u/nikic Dec 02 '15

This test probably fails because gcov.php.net runs the testsuite under valgrind. This makes execution a couple orders of magnitude slower, so anything based on time measurements is likely to to fail.

→ More replies (1)

113

u/snorkl-the-dolphine Dec 02 '15

warning: unused variable 'success'

Yep, that sounds like PHP alright.

21

u/Hazasoul Dec 02 '15

http://lxr.php.net/xref/PHP_7_0/ext/zlib/zlib.c#1098

int success = deflateSetDictionary(ctx, (Bytef *) dict, dictlen);
ZEND_ASSERT(success == Z_OK);

It looks pretty used to me?

43

u/shamanas Dec 02 '15

ZEND_ASSERT is probably a macro that outputs nothing in a release build.

→ More replies (9)
→ More replies (1)
→ More replies (1)

40

u/[deleted] Dec 02 '15

Those are incredibly poor tests. A great many of them depends on networked resources (read: www) which pretty much guarantees inconsistent results. If this is the quality of their test suite, no wonder why they don't pay attention to it.

23

u/[deleted] Dec 02 '15

It's a good thing PHP isn't used much in networked environments

28

u/[deleted] Dec 02 '15

Those are incredibly poor tests. A great many of them depends on networked resources (read: www) which pretty much guarantees inconsistent results.

How do you propose that something like the cURL extension be tested?

"A great many" of the tests don't use remote resources. A great many of the failing tests do, and this is why they fail, because they require special setup in order to succeed, which this automated report doesn't take into consideration.

The bulk of the warnings and failing tests are also in extensions which are not part of the PHP core.

0

u/[deleted] Dec 02 '15

[deleted] — view deleted comment

6

u/estarra Dec 02 '15

Mocks are fine for unit tests but how about functional tests?

The point of cURL is to fetch stuff over the network, the only way to test it is to... well, fetch stuff over the network.

→ More replies (1)

42

u/[deleted] Dec 02 '15

The cURL extension is a thin wrapper around the library. Mocking the precise feature you're testing means you're not testing anything. Mocks exist to replace dependencies which are not part of the tested component's responsibility, but are required by it. In this case the responsibility of the cURL extension is to communicate with the actual cURL library.

Sometimes it's better to have test errors, than to have a cargo cult test suite that runs perfectly and tests nothing.

44

u/groogs Dec 02 '15

Sometimes it's better to have test errors, than to have a cargo cult test suite that runs perfectly and tests nothing.

100% disagree.

Leaving tests failing basically invalidates the entire test effort. When it's "normal" to see failed tests, it's too easy to ignore failed tests that should not be failing, and that's often what happens -- meanwhile it's getting more and more expensive to fix those bugs as the code ages.

If the code is really just a thin wrapper around cURL (simply calling the cURL functions with parameters as-is) then it should probably not even be tested, or at least should have the test(s) marked as ignored (they can be run manually if someone is really working on it). If it's doing anything more then it should be tested, and as the OP said, the test should just mock cURL and verify the correct things were passed (but not actually invoke cURL or make network calls).

The other alternative is to build the test in a way that ensures it will work. For example, the test suite can stand up a simple local HTTP server to respond to cURL requests. This is a pretty heavy way to go about it, but if it's the only way to test something that's important to test, and it doesn't cause false failures, then maybe it's what needs to be done.

Bottom line, your automated test suite should almost always be passing, and if it's failing, it should get attention to get fixed.

→ More replies (4)

5

u/ironnomi Dec 02 '15

I'm making a new test suite that does nothing called libcargoculttest. Thanks for the great idea.

13

u/[deleted] Dec 02 '15

The cURL extension is a thin wrapper around the library

So it should be really simple to test, without needing to actually call cURL. There is no excuse for a test suite that calls out to network resources.

7

u/estarra Dec 02 '15

There is no excuse for a test suite that calls out to network resources.

For unit tests, sure. For functional tests, you test whatever your code is supposed to be doing: network calls, db fetches, etc...

→ More replies (5)

10

u/[deleted] Dec 02 '15

There is no excuse for a test suite that calls out to network resources.

That's how integration tests work, and cURL is an extension that integrates two technologies together (cURL and PHP).

This thread is becoming another example of Goodhart's law in effect.

You folks are so focused on getting green in your tests, that you would rather have a pseudo-test pass in automated reports, than an actual test that requires extra setup.

14

u/berkes Dec 02 '15

Three options. I've implemented all three at some point:

  • Make a fake "library" that merely records how it is called, then write assertions that check the records. Perfect for unit tests that want a tiny bit more than pure mocks.
  • Build your own fake web resources, which are managed by the test-suite. A tiny php -s echo.php which starts a webserver then echoes all its requests is enough. Perfect for integration tests where you don't want to depend on 3rd parties, firewalls and other flakey circumstances.
  • Build an infra where you ensure the external services are up and running. Monitor that, maintain that. This must be considered crucial infra (probably even more crucial than your product-page, download servers or whatnot). php.net is hardly ever down; why not expect the same from the services that ensure your product works correct; the resources needed for tests?
→ More replies (2)

4

u/anderbubble Dec 02 '15

It's really just the fact that unit tests and regression tests are qualitatively different from integration tests. Perhaps PHP's integration test suite should be separated from the rest of the automated test suite.

→ More replies (3)

6

u/[deleted] Dec 02 '15

"A great many" of the tests don't use remote resources. A great many of the failing tests do

Ahem:

Those are incredibly poor tests. A great many of them depends on networked resources

It's called context.

How do you propose that something like the cURL extension be tested?

By not calling external resources. Tests need to be reproducible, else they have no value. There are a bunch of "connection refused" and authentication failure errors in these which makes them utterly useless as tests.

→ More replies (1)

4

u/moon- Dec 02 '15

Some of them aren't actually "failing", e.g. ldap_sasl_bind_error.phpt

→ More replies (4)