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

Allow full, unfettered usage across all PHPUnit versions #48

Merged

Conversation

weierophinney
Copy link
Member

@weierophinney weierophinney commented May 1, 2017

In reviewing #40 after-the-fact, I found a number of issues:

  • Adding class_alias to each test case in the test suite is problematic. These should be accomplished via an autoloader file.
  • Many classes in the Zend\Test namespace were using class names that were pre-6.0 versions of PHPUnit, which meant they still could not be used under that version.
  • A few classes in the source directory, and most of the classes in the test directory, were using the setExpectedException() method, which was deprecated in the PHPUnit 5.7 series and removed in PHPUnit 6.

This patch does the following to fix these issues:

  • Adds class_alias directives to a new file, autoload/phpunit-class-aliases.php, which aliases the non-namespaced versions of both TestCase and ExpectationFailedException to the namespaced variants, allowing usage of the namespaced variants throughout all source code and tests.
  • Adds logic to assertApplicationException() to detect if pre-6.0 versions of PHPUnit are in use, and, if so, uses setExpectedException(); if not, uses expectException(), and optionally expectExceptionMessage().
  • Adds a trait to the test suite, ZendTest\Test\ExpectedExceptionTrait, with the method expectedException(). It uses the setExpectedException() signature, and then, based on the version of PHPUnit detected, proxies either to setExpectedException() or expectException() + optionally expectExceptionMessage().

TODO

  • Test against each of PHPUnit 4, 5, and 6
  • Test against each of PHPUnit 4, 5, and 6 within an actual application

- Adds `class_alias` directives to a new file,
  `autoload/phpunit-class-aliases.php`, which aliases the non-namespaced
  versions of both `TestCase` and `ExpectationFailedException` to the
  namespaced variants, allowing usage of the namespaced variants
  throughout all source code and tests.
- Adds logic to `assertApplicationException()` to detect if pre-6.0
  versions of PHPUnit are in use, and, if so, uses
  `setExpectedException()`; if not, uses `expectException()`, and
  optionally `expectExceptionMessage()`.
- Adds a trait to the test suite,
  `ZendTest\Test\ExpectedExceptionTrait`, with the method
  `expectedException()`. It uses the `setExpectedException()` signature,
  and then, based on the version of PHPUnit detected, proxies either to
  `setExpectedException()` or `expectException()` + optionally
  `expectExceptionMessage()`.
@weierophinney weierophinney added this to the 3.1.0 milestone May 1, 2017
- Ensure that PHPUnit 5 is installed for PHP 5.6 locked/latest versions
- Ensure that coverage is generated when necessary
- Consistency with other repos
@weierophinney
Copy link
Member Author

I've done the following with a skeleton application (which includes several controller unit tests):

  • Added an exceptionAction() to IndexController, and had it throw an exception.
  • Added a test case to the IndexControllerTest that performs an assertApplicationException() check for the exception thrown by IndexController::exceptionAction().
  • Added a repository entry to composer.json pointing to my fork.
  • Updated the zendframework/zend-test constraint to read dev-hotfix/class-aliases as 3.1.0.
  • Ran, under PHP 7.1, composer update --with-dependencies zendframework/zend-test to pick up the changeset. This picked up PHPUnit 6.0
  • Ran PHPUnit. Tests passed.
  • Ran composer require --update-with-dependencies --dev "phpunit/phpunit:^5.7" to switch to PHPUnit 5.7.
  • Ran PHPUnit. Tests passed.
  • Switched to PHP 5.6.
  • Ran composer require --update-with-dependencies --dev "phpunit/phpunit:^4.8" to switch to PHPUnit 4.8.
  • Ran PHPUnit. Tests passed.

I did the above using the current develop branch as well, to confirm that it was not working. Under PHPUnit 6, tests errored due to missing PHPUnit_Framework_TestCase (and likely others; as this is a required class for things to work at all, other tests may have failed as well); PHPUnit 5.7 passed (as the non-namespaced class exists already there; the namespaced version is aliased in that particular case), as did PHPUnit 4.8.

As such, I think this is ready!

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

Successfully merging this pull request may close these issues.

2 participants