Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Dependency issue with test requirement #182

Open
marc-mabe opened this issue Feb 21, 2017 · 9 comments
Open

Dependency issue with test requirement #182

marc-mabe opened this issue Feb 21, 2017 · 9 comments

Comments

@marc-mabe
Copy link
Member

This component ships a trait used by other components in tests.
Now with 07d53d3 the tests have been upgraded to PHPUnit5 and tests of other components fails because they still using PHPUnit4.
E.g.: https://travis-ci.org/marc-mabe/zend-cache/jobs/203261654

The main problem is not to have a reusable trait for tests or the upgraded PHPUnit dependency but:

  • The dependency of PHPUnit5 is defined in require-dev - so only valid running zend-servicemanager in development environment but not verified by other components
  • Can't be moved to require as then every production environment would load PHPUnit and it's dependencies
  • The test trait will be available for everyone even in production environment but they shouldn't use it 😕
  • The test trait is in namespace Zend\ServiceManager\Test but it should be in ZendTest\*

To solve this I would do the following (like what I started to do with splitting zend-cache):

  • create own repo for reusable test classes (like zend-servicemanager-test)
    • set autoload (not autoload-dev) to load the common test classes in namespace ZendTest\*
    • set require (not require-dev) to depend on zend-servicemanager and everything else required to use these test classes
  • add require-dev: zend-servicemanager-test in this component and all components using this class
    -> Now the dependencies of such test classes are defined by composer and they are not part of any production environment

How this would look like as I started to do that with zend-cache:

Ping @weierophinney @Ocramius

@akrabat
Copy link
Contributor

akrabat commented Feb 24, 2017

This is causing problems with Zend Validator too: https://travis-ci.org/zendframework/zend-validator

@kokspflanze
Copy link
Contributor

i also start working to update all modules, which i found, to work with the latest phpunit version.

@weierophinney
Copy link
Member

Honestly, I think the approach by @kokspflanze is the best one for us to take. PHPUnit 5.7 is considered "legacy" currently (technically "old stable"), with version 6.0 the current stable release; the PHPUnit 4 series is no longer supported. As such, we need to start updating all components to pin them to newer versions. PHPUnit 5 is needed when testing against PHP 5.6, and PHPUnit 6 for versions 7 and up. We've done this across a number of components recently, most notably the Expressive components, and have approaches that work across each in terms of testing on Travis.

The main "gotchas" we've observed when updating are:

  • setExpectedException() goes away, and needs to be replaced with expectException(), plus optionally expectExceptionMessage().
  • PHPUnit\Framework\TestCase should be used instead of PHPUnit_Framework_TestCase.
  • A number of commonly used classes from the phpunit package do not have namespaced, forwards-compatibility shims, which require doing things like class_alias hacks, to allow using namespaced versions of classes that will work under both major versions of PHPUnit.

I've found that most adaptations to components take less than an hour, and I see that @kokspflanze has already started submitting a number of these in the past week; if we can get these merged soon, and get others to help in the effort, we can get these cases sorted fairly quickly.

While we could certainly split the test trait(s) into their own package, I hate to do this, as it adds yet another dependency during normal development, particularly when this is a transient problem.

@kokspflanze
Copy link
Contributor

@weierophinney from my site i see the biggest problem to support PHPUnit 4, 5 and 6, some modules like zend-validator start with min php 5.5 so they want PHPUnit 4 but there is no expectException method, these method added with phpunit 5.2 code, so i stuck atm there to find a good solution without writing hacks.

maybe someone have a good solution for that.

from my site i try 1 or 2 modules each week, some modules take bit longer some are less than 1hour done.

@froschdesign
Copy link
Member

froschdesign commented Mar 1, 2017

@kokspflanze

…to support PHPUnit 4, 5 and 6…

Why? PHP 5.5 and PHPUnit 4.8 are no longer supported!

@kokspflanze
Copy link
Contributor

can i realy remove php 5.5 in modules like zend-validator?

@weierophinney
Copy link
Member

@kokspflanze — We can issue new minor releases that bump the PHP requirement to ^5.6 || ^7.0 for any component at any time; I'm a bit surprised we haven't done so with zend-validator already, as we've been steadily doing so with new component releases for the past year!

@kokspflanze
Copy link
Contributor

okay thats cool=) didnt know it that we can easy set it to the latest version=) that save many time

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-servicemanager; a new issue has been opened at laminas/laminas-servicemanager#19.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants