Closed weierophinney closed 7 years ago
I've done the following with a skeleton application (which includes several controller unit tests):
exceptionAction()
to IndexController
, and had it throw an exception.IndexControllerTest
that performs an assertApplicationException()
check for the exception thrown by IndexController::exceptionAction()
.composer.json
pointing to my fork.zendframework/zend-test
constraint to read dev-hotfix/class-aliases as 3.1.0
.composer update --with-dependencies zendframework/zend-test
to pick up the changeset. This picked up PHPUnit 6.0composer require --update-with-dependencies --dev "phpunit/phpunit:^5.7"
to switch to PHPUnit 5.7.composer require --update-with-dependencies --dev "phpunit/phpunit:^4.8"
to switch to PHPUnit 4.8.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!
In reviewing #40 after-the-fact, I found a number of issues:
class_alias
to each test case in the test suite is problematic. These should be accomplished via an autoloader file.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.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:
class_alias
directives to a new file,autoload/phpunit-class-aliases.php
, which aliases the non-namespaced versions of bothTestCase
andExpectationFailedException
to the namespaced variants, allowing usage of the namespaced variants throughout all source code and tests.assertApplicationException()
to detect if pre-6.0 versions of PHPUnit are in use, and, if so, usessetExpectedException()
; if not, usesexpectException()
, and optionallyexpectExceptionMessage()
.ZendTest\Test\ExpectedExceptionTrait
, with the methodexpectedException()
. It uses thesetExpectedException()
signature, and then, based on the version of PHPUnit detected, proxies either tosetExpectedException()
orexpectException()
+ optionallyexpectExceptionMessage()
.TODO