Fix test suite when ext/intl isn't available #5111

Closed
wants to merge 8 commits into from

4 participants

@dshafik
  • This will hopefully enable the testsuite to run in HHVM (see: this blog post)
  • There were a bunch of errors caused by Zend\I18n\Validator\Int, switching some tests to use Zend\Validation\Digits might be a good idea
@Ocramius
Zend Framework member

did you look into #5110 first? :)

@dshafik

@Ocramius of... course not. BLAH!

I'll work with @TheFrozenFire to see which works better :)

@samsonasik samsonasik commented on the diff Sep 14, 2013
...endTest/Form/View/Helper/MissingIntlExtensionTest.php
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Form
+ */
+
+namespace ZendTest\Form\View\Helper;
+
+use PHPUnit_Framework_TestCase as TestCase;
+use Zend\Form\Element\DateSelect;
+use Zend\Form\View\Helper\FormDateSelect as FormDateSelectHelper;
+use Zend\Form\View\Helper\FormDateTimeSelect as FormDateTimeSelectHelper;
+use Zend\Form\View\Helper\FormMonthSelect as FormMonthSelectHelper;
+
+/**
+ * @category Zend
+ * @package Zend_Form
+ * @subpackage UnitTest

remove @category @package and @subpackage

@dshafik
dshafik added a note Sep 15, 2013

I'm not sure why you are wanting to do this? I followed the convention in the other tests.

@dshafik
dshafik added a note Sep 15, 2013

#3508 only applies to library and explicitly says not to apply to tests.

please take a look #3508 , it's old issue that we agree to remove all @category @package and @subpackage. I only comment to remove new created one/all of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@samsonasik samsonasik commented on the diff Sep 14, 2013
...endTest/Form/View/Helper/MissingIntlExtensionTest.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Form

remove @package

@dshafik
dshafik added a note Sep 15, 2013

Same as above: what's the reasoning?

please take a look #3508 , it's old issue that we agree to remove all @category @package and @subpackage annotations.
ping @weierophinney

@dshafik
dshafik added a note Sep 15, 2013

#3508 only applies to library and explicitly says not to apply to tests.

ah, yes. Library only. but I think we need to prevent new created one :)

ping @Maks3w

@Maks3w I can't push someone that decline to remove @package docblock, maybe you can ? :)

@Maks3w
Zend Framework member
Maks3w added a note Oct 3, 2013

@dshafik that docblock tags are deprecated if you use namespaces since the namespace reflects the same info about package categorization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dshafik

This latest change takes sebastianbergmann/phpunit#997 into account — it's conditional on PHPUnit 3.8 (unreleased) and works with < PHPUnit 3.8 as well for now. Don't let it stop this going in. If @sebastianbergmann rejects the PR I'll patch these tests to remove it.

@Maks3w Maks3w commented on the diff Oct 21, 2013
...endTest/Form/View/Helper/MissingIntlExtensionTest.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Form
+ */
+
+namespace ZendTest\Form\View\Helper;
+
+use PHPUnit_Framework_TestCase as TestCase;
+use Zend\Form\Element\DateSelect;
+use Zend\Form\View\Helper\FormDateSelect as FormDateSelectHelper;
@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

Following framework practice please split this test file and add a new one for each helper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Maks3w Maks3w commented on the diff Oct 21, 2013
tests/ZendTest/I18n/Filter/NumberFormatTest.php
{
+ if (!extension_loaded('intl')) {
@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

Please remove this from the dataprovider and add it in the test method

@dshafik
dshafik added a note Oct 21, 2013

This is actually required for this to work. The data providers are called BEFORE the test and use ext/intl to generate the test data. If you remove this, the tests will fatal error without ext/intl enabled.

I will not be changing this.

@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

Instead return an empty array.

@dshafik
dshafik added a note Oct 21, 2013

On what condition would I return this array? Your comment makes no sense and doesn't help solve the issue.

You'll notice I do return an empty nested array (otherwise it's an error, instead of a warning) 4 lines down, unless you have a newer version of phpunit which allows you to markTestSkipped in the provider.

@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

@dshafik There is no option for add references to non existing PHPUnit versions. So don't add this kind of code.

@dshafik
dshafik added a note Oct 21, 2013

OK, last try:

The data provider requires ext/intl. The test also requires ext/intl. If ext/intl doesn't exist, it would be correct to skip the test (markTestSkipped). However, the data provider is called before the test (which makes sense, as it gives the arguments for the test method), so it fatal errors before it hits the markTestSkipped.

The obvious solution therefore, is to markTestSkipped in the data provider. In the current PHPUnit (3.7) this is not possible. So you instead return an empty data set.

If you return an empty data set (array(array())), phpunit will emit a warning, and the test suite may be considered failed (e.g. continuous integration that blocks on errors/warnings).

So, I added a PR for PHPUnit to add the ability to markTestSkipped in the provider.

This code in the tests will stop the fatal errors in PHPUnit 3.7 (by checking for ext/intl and returning an empty data set when it doesn't exist) , and in newer versions of PHPUnit (> 3.7, e.g. 3.8-dev) will stop the warnings (and skip the test correctly).

I did not add this just for funsies, I added it for well thought out reasons. If you do not want to merge these changes (after I remove the @package tags) then just close the PR and reject it.

@jmather
jmather added a note Oct 21, 2013

What if instead the test that was dependent on php/intl was moved to a separate php/intl test suite, so that only the test in question is skipped. Is that the core of the issue, @Maks3w? Other tests being skipped? If so, this one just needs to be silo'd in it's own test suite so it can be skipped properly.

@weierophinney
Zend Framework member

@Maks3w I'm okay with it as written, as it allows changing the behavior based on PHPUnit version. The logic here is sound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Maks3w Maks3w commented on the diff Oct 21, 2013
tests/ZendTest/I18n/Filter/NumberFormatTest.php
@@ -91,8 +106,16 @@ public static function numberToFormattedProvider()
);
}
- public static function formattedToNumberProvider()
+ public function formattedToNumberProvider()
@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

here too

@dshafik
dshafik added a note Oct 21, 2013

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Maks3w Maks3w commented on the diff Oct 21, 2013
tests/ZendTest/I18n/Validator/DateTimeTest.php
@@ -65,6 +71,14 @@ public function testBasic($value, $expected, $options = array())
public function basicProvider()
{
+ if (!extension_loaded('intl')) {
+ if (version_compare(\PHPUnit_Runner_Version::VERSION, '3.8.0-dev') === 1) {
@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

here too

@dshafik
dshafik added a note Oct 21, 2013

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Maks3w Maks3w commented on the diff Oct 21, 2013
tests/ZendTest/I18n/View/Helper/DateFormatTest.php
@@ -55,6 +59,14 @@ public function tearDown()
public function dateTestsDataProvider()
{
+ if (!extension_loaded('intl')) {
+ if (version_compare(\PHPUnit_Runner_Version::VERSION, '3.8.0-dev') === 1) {
@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

here too

@dshafik
dshafik added a note Oct 21, 2013

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Maks3w Maks3w commented on the diff Oct 21, 2013
tests/ZendTest/I18n/View/Helper/DateFormatTest.php
@@ -147,6 +159,14 @@ public function dateTestsDataProvider()
public function dateTestsDataProviderWithPattern()
{
+ if (!extension_loaded('intl')) {
@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

here too

@dshafik
dshafik added a note Oct 21, 2013

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Maks3w Maks3w commented on the diff Oct 21, 2013
tests/ZendTest/I18n/View/Helper/NumberFormatTest.php
@@ -54,6 +58,14 @@ public function tearDown()
public function currencyTestsDataProvider()
{
+ if (!extension_loaded('intl')) {
+ if (version_compare(\PHPUnit_Runner_Version::VERSION, '3.8.0-dev') === 1) {
@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

here too

@dshafik
dshafik added a note Oct 21, 2013

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Maks3w
Zend Framework member

@dshafik ZF2 has a minimum requirement on PHPUnit 3.7 so why not use @requires annotation?

http://phpunit.de/manual/3.7/en/incomplete-and-skipped-tests.html#incomplete-and-skipped-tests.requires.tables.api

@dshafik

@Maks3w I believe it's because the data provider is still called. I don't remember why they didn't work, but I did try this and other options first.

@Maks3w
Zend Framework member

@dshafik You'll get a better success in your PHPUnit PR if you prevent trigger @dataProvider when @requires is false

@dshafik

@Maks3w then it would still run in older versions and fatal error. This has to be something that is possible to work in current and newer versions of PHPUnit. Fixing the @dataProvider/@requires thing for > 3.7 doesn't help, this code would STILL need to be in the dataProvider (at least the intl check and return empty data set).

@weierophinney weierophinney added a commit that referenced this pull request Oct 22, 2013
@weierophinney weierophinney [#5111] CS fixes
- EOF ending
- Remove unnecessary annotations
a6e86c3
@weierophinney weierophinney added a commit that closed this pull request Oct 22, 2013
@weierophinney weierophinney Merge branch 'hotfix/5111'
Close #5111
9c0585e
@weierophinney weierophinney added a commit that referenced this pull request Oct 22, 2013
@weierophinney weierophinney Merge branch 'hotfix/5111' into develop
Forward port #5111

Conflicts:
	tests/ZendTest/I18n/Translator/Loader/GettextTest.php
	tests/ZendTest/I18n/Translator/Loader/PhpArrayTest.php
8644746
@Maks3w
Zend Framework member

@weierophinney The referenced PHPUnit versions DON'T EXISTS! The patch proposed is not merged.

@weierophinney
Zend Framework member

@Maks3w If Sebastian chooses not to merge it, @dshafik has indicated he'll issue a revert. Indications at this point are that it will be merged, however.

@weierophinney weierophinney added a commit to zendframework/zend-config that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5111 from dshafik/fix/…
…ext-intl-missing-failure

Fix test suite when ext/intl isn't available
c8a1dba
@weierophinney weierophinney added a commit to zendframework/zend-config that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' c6bda54
@weierophinney weierophinney added a commit to zendframework/zend-config that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' into develop
Forward port zendframework/zendframework#5111

Conflicts:
	tests/ZendTest/I18n/Translator/Loader/GettextTest.php
	tests/ZendTest/I18n/Translator/Loader/PhpArrayTest.php
d97c259
@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5111 from dshafik/fix/…
…ext-intl-missing-failure

Fix test suite when ext/intl isn't available
80d00fa
@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' c05aee7
@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' into develop
Forward port zendframework/zendframework#5111

Conflicts:
	tests/ZendTest/I18n/Translator/Loader/GettextTest.php
	tests/ZendTest/I18n/Translator/Loader/PhpArrayTest.php
39d06a8
@weierophinney weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5111 from dshafik/fix/…
…ext-intl-missing-failure

Fix test suite when ext/intl isn't available
347844b
@weierophinney weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' 035e666
@weierophinney weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' into develop
Forward port zendframework/zendframework#5111

Conflicts:
	tests/ZendTest/I18n/Translator/Loader/GettextTest.php
	tests/ZendTest/I18n/Translator/Loader/PhpArrayTest.php
2595c1a
@weierophinney weierophinney added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5111 from dshafik/fix/…
…ext-intl-missing-failure

Fix test suite when ext/intl isn't available
0e2f483
@weierophinney weierophinney added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' 9e7e067
@weierophinney weierophinney added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' into develop
Forward port zendframework/zendframework#5111

Conflicts:
	tests/ZendTest/I18n/Translator/Loader/GettextTest.php
	tests/ZendTest/I18n/Translator/Loader/PhpArrayTest.php
2094f47
@weierophinney weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5111 from dshafik/fix/…
…ext-intl-missing-failure

Fix test suite when ext/intl isn't available
fc97106
@weierophinney weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' 047576f
@weierophinney weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' into develop
Forward port zendframework/zendframework#5111

Conflicts:
	tests/ZendTest/I18n/Translator/Loader/GettextTest.php
	tests/ZendTest/I18n/Translator/Loader/PhpArrayTest.php
997a8a7
@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5111 from dshafik/fix/…
…ext-intl-missing-failure

Fix test suite when ext/intl isn't available
c7cc5bc
@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' e5fd689
@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' into develop
Forward port zendframework/zendframework#5111

Conflicts:
	tests/ZendTest/I18n/Translator/Loader/GettextTest.php
	tests/ZendTest/I18n/Translator/Loader/PhpArrayTest.php
d074ac7
@weierophinney weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5111 from dshafik/fix/…
…ext-intl-missing-failure

Fix test suite when ext/intl isn't available
9cbb4dd
@weierophinney weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' 6bc8c90
@weierophinney weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5111' into develop
Forward port zendframework/zendframework#5111

Conflicts:
	tests/ZendTest/I18n/Translator/Loader/GettextTest.php
	tests/ZendTest/I18n/Translator/Loader/PhpArrayTest.php
b9b648c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment