zendframework / zend-test

Test component from Zend Framework
BSD 3-Clause "New" or "Revised" License
18 stars 38 forks source link

Release 3.2.1 breaks vendors behavior #71

Closed loic-couharde closed 5 years ago

loic-couharde commented 5 years ago

Hi,

The #66 hotfix breaks many vendors since Global arrays are cleared on setUp(). For example I use spatie/phpunit-snapshot-assertions to make snapshots which use $_SERVER here or Hoa Protocol here. These are only 2 examples but it may have a huge impact on other large projects with many vendors.

Is it possible to consider fine fixing the problem encountered in #61 instead of clearing all global arrays ?

Thanks.

Ocramius commented 5 years ago

If this scenario needs to be supported, then we'd need:

Overall, changing $_ variables should not affect testing, and tests that expose failures if that happens are extremely smelly.

Specifically, in the two cases listed above:

Ocramius commented 5 years ago

As an added suggestion, consider using @runInSeparateProcess, if you have tests relying on super-globals or statics. I generally isolate anything that uses statics/globals (and all related anti-patterns) in such tests, at an extreme performance penalty, but usually works.

EDIT: this includes tests that rely on changing $_GLOBALS

Hywan commented 5 years ago

We can update hoa/protocol but we are certainly not the only ones doing so :-).

Thanks for the ping!

reinfi commented 5 years ago

This not even fails vendor products it fails all our integration controller tests now.

PHPUnit allows to add server variable via configuration (like HTTP_HOST i.e.). These configuration settings are now thrown away when ever a new controller test is started.

The next problem is, that if the test fails and throws an exception the global variables are not restored and phpunit now fails hard.

Is this really expected behaviour?

michalbundyra commented 5 years ago

Is this really expected behaviour?

No. I'll try to prepare another fix today, I have an idea and it could work for everyone! :)

michalbundyra commented 5 years ago

@reinfi @loic-couharde @Ocramius I've prepared PR: https://github.com/zendframework/zend-test/pull/74 which depends on https://github.com/zendframework/zend-http/pull/165 - recognise correct base url.

reinfi commented 5 years ago

looks good to me

jaydiablo commented 5 years ago

We have some controller tests failing now with zend-test 3.2.1 (that includes changes from #66) because of this line in zend-session:

https://github.com/zendframework/zend-session/blob/master/src/AbstractContainer.php#L260

Exception 'PHPUnit\Framework\Error\Notice' with message 'Undefined index: REQUEST_TIME' in ./vendor/zendframework/zend-session/src/AbstractContainer.php:260

Reverting to 3.2.0 fixes the tests.