0

我在 CakePHP 中遇到了几个我想提交修复的问题,但我想确保我所做的任何更改都通过了单元测试。问题是单元测试对我来说不太适合开箱即用的代码!我确信单元测试本身很好,并且对其他人来说也很好,所以这可能是我的环境中的某些东西导致了问题。

我在 PHP 版本 5.6.19 上运行 CakePHP 版本 3.2.5。我的 PHP 构建配置(包括在内,因为我必须重建它几次才能让它运行这么多的测试,所以理论上这可能是问题所在):

'./configure' '--enable-fileinfo' '--enable-phar' '--disable-maintainer-zts' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-mbstring' '--enable-pdo=shared' '--enable-sockets' '--with-apxs2=/usr/sbin/apxs' '--with-curl' '--with-freetype-dir=/usr' '--with-gd' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libdir=lib64' '--with-mssql=/usr' '--with-mysql=/usr' '--with-mysqli=/usr/bin/mysql_config' '--with-pcre-regex' '--with-pdo-mysql=shared' '--without-sqlite' '--with-sqlite3=shared' '--with-pdo-sqlite=shared,/usr' '--with-pic' '--with-png-dir=/usr' '--with-zlib' '--with-zlib-dir=/usr' '--with-openssl' '--enable-intl'

可能还有 php.ini 设置会影响其中的一些?

用于为测试设置 CakePHP 的命令

$ git clone git@github.com:cakephp/cakephp.git
$ cd cakephp

第一次尝试

$ make test
[bunch of stuff here where it installs all the dependencies]
vendor/bin/phpunit
PHPUnit 5.2.12 by Sebastian Bergmann and contributors.

.............................................................   61 / 6777 (  0%)
[etc.]
............................................................. 1159 / 6777 ( 17%)
........FF......PHP Fatal error:  Call to a member function format() on null in /home/cake/cakephp/tests/TestCase/I18n/DateTest.php on line 170

Fatal error: Call to a member function format() on null in /home/cake/cakephp/tests/TestCase/I18n/DateTest.php on line 170
make: *** [test] Error 255

这是因为它试图使用 fr_FR 语言环境解析“13 10, 2015”,但这似乎无效。我通过在第 169 行和第 185 行将字符串更改为“13/10/2015”来修复它。(我还添加了assertNotNull调用。)

第二次尝试

$ make test
[etc.]
............................................................. 4209 / 6777 ( 62%)
.......................FF.......................PHP Fatal error:  Call to a member function format() on null in /home/cake/cakephp/tests/TestCase/Database/Type/TimeTypeTest.php on line 184

Fatal error: Call to a member function format() on null in /home/cake/cakephp/tests/TestCase/Database/Type/TimeTypeTest.php on line 184
make: *** [test] Error 255

我没有完全跟踪这个,只是让它失败并通过添加$this->assertNotNull($result);.

第三次尝试

$ make test
[etc.]
There were 5 errors:

1) Cake\Test\TestCase\I18n\IcuFormatterTest::testNativePluralSelection
Aura\Intl\Exception\CannotInstantiateFormatter: msgfmt_create: message formatter creation failed: U_ILLEGAL_CHARACTER

/home/cake/cakephp/src/I18n/Formatter/IcuFormatter.php:97
/home/cake/cakephp/src/I18n/Formatter/IcuFormatter.php:51
/home/cake/cakephp/tests/TestCase/I18n/Formatter/IcuFormatterTest.php:81

2) Cake\Test\TestCase\ORM\QueryTest::testCountWithSubselect
PDOException: SQLSTATE[HY000]: General error: 25 bind or column index out of range

/home/cake/cakephp/src/Database/Statement/StatementDecorator.php:171
/home/cake/cakephp/src/Database/Statement/StatementDecorator.php:171
/home/cake/cakephp/src/Database/Statement/BufferedStatement.php:74
/home/cake/cakephp/src/Database/Statement/SqliteStatement.php:41
/home/cake/cakephp/src/Database/Connection.php:270
/home/cake/cakephp/src/Database/Query.php:188
/home/cake/cakephp/src/ORM/Query.php:793
/home/cake/cakephp/src/ORM/Query.php:739
/home/cake/cakephp/tests/TestCase/ORM/QueryTest.php:1543
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

3) Cake\Test\TestCase\ORM\QueryTest::testCountWithExpressions
PDOException: SQLSTATE[HY000]: General error: 25 bind or column index out of range

/home/cake/cakephp/src/Database/Statement/StatementDecorator.php:171
/home/cake/cakephp/src/Database/Statement/StatementDecorator.php:171
/home/cake/cakephp/src/Database/Statement/BufferedStatement.php:74
/home/cake/cakephp/src/Database/Statement/SqliteStatement.php:41
/home/cake/cakephp/src/Database/Connection.php:270
/home/cake/cakephp/src/Database/Query.php:188
/home/cake/cakephp/src/ORM/Query.php:793
/home/cake/cakephp/src/ORM/Query.php:739
/home/cake/cakephp/tests/TestCase/ORM/QueryTest.php:1564
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

4) Cake\Test\TestCase\ORM\QueryTest::testCountWithSubselect
PDOException: SQLSTATE[HY000]: General error: 25 bind or column index out of range

/home/cake/cakephp/src/Database/Statement/StatementDecorator.php:171
/home/cake/cakephp/src/Database/Statement/StatementDecorator.php:171
/home/cake/cakephp/src/Database/Statement/BufferedStatement.php:74
/home/cake/cakephp/src/Database/Statement/SqliteStatement.php:41
/home/cake/cakephp/src/Database/Connection.php:270
/home/cake/cakephp/src/Database/Query.php:188
/home/cake/cakephp/src/ORM/Query.php:793
/home/cake/cakephp/src/ORM/Query.php:739
/home/cake/cakephp/tests/TestCase/ORM/QueryTest.php:1543
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

5) Cake\Test\TestCase\ORM\QueryTest::testCountWithExpressions
PDOException: SQLSTATE[HY000]: General error: 25 bind or column index out of range

/home/cake/cakephp/src/Database/Statement/StatementDecorator.php:171
/home/cake/cakephp/src/Database/Statement/StatementDecorator.php:171
/home/cake/cakephp/src/Database/Statement/BufferedStatement.php:74
/home/cake/cakephp/src/Database/Statement/SqliteStatement.php:41
/home/cake/cakephp/src/Database/Connection.php:270
/home/cake/cakephp/src/Database/Query.php:188
/home/cake/cakephp/src/ORM/Query.php:793
/home/cake/cakephp/src/ORM/Query.php:739
/home/cake/cakephp/tests/TestCase/ORM/QueryTest.php:1564
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

--

There were 26 failures:

1) Cake\Test\TestCase\I18n\DateTest::testI18nFormat with data set "mutable" ('Cake\I18n\Date')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'jeudi 14 janvier 2010 00:00:00 UTC'
+'jeudi 14 janvier 2010 00:00:00 UTC+00:00'

/home/cake/cakephp/tests/TestCase/I18n/DateTest.php:112

2) Cake\Test\TestCase\I18n\DateTest::testI18nFormat with data set "immutable" ('Cake\I18n\FrozenDate')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'jeudi 14 janvier 2010 00:00:00 UTC'
+'jeudi 14 janvier 2010 00:00:00 UTC+00:00'

/home/cake/cakephp/tests/TestCase/I18n/DateTest.php:112

3) Cake\Test\TestCase\I18n\NumberTest::testCurrency
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'₹ 10,01,00,100.00'
+'Rs 10,01,00,100.00'

/home/cake/cakephp/tests/TestCase/I18n/NumberTest.php:206

4) Cake\Test\TestCase\I18n\NumberTest::testConfig
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'₹ 15,000.00'
+'Rs 15,000.00'

/home/cake/cakephp/tests/TestCase/I18n/NumberTest.php:550

5) Cake\Test\TestCase\I18n\NumberTest::testOrdinal
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'1st'
+'1ˢᵗ'

/home/cake/cakephp/tests/TestCase/I18n/NumberTest.php:569

6) Cake\Test\TestCase\I18n\TimeTest::testI18nFormat with data set "mutable" ('Cake\I18n\Time')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-jueves 14 de enero de 2010 13:59:28 GMT
+jueves 14 de enero de 2010 13:59:28 GMT+00:00

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:858
/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:439

7) Cake\Test\TestCase\I18n\TimeTest::testI18nFormat with data set "immutable" ('Cake\I18n\FrozenTime')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-jueves 14 de enero de 2010 13:59:28 GMT
+jueves 14 de enero de 2010 13:59:28 GMT+00:00

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:858
/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:439

8) Cake\Test\TestCase\I18n\TimeTest::testI18nFormatWithOffsetTimezone with data set "mutable" ('Cake\I18n\Time')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-Wednesday January 1 2014 12:00:00 AM GMT
+Wednesday January 1 2014 12:00:00 AM GMT+00:00

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:858
/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:496

9) Cake\Test\TestCase\I18n\TimeTest::testI18nFormatWithOffsetTimezone with data set "immutable" ('Cake\I18n\FrozenTime')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-Wednesday January 1 2014 12:00:00 AM GMT
+Wednesday January 1 2014 12:00:00 AM GMT+00:00

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:858
/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:496

10) Cake\Test\TestCase\I18n\TimeTest::testToString with data set "mutable" ('Cake\I18n\Time')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-dimanche 20 avril 2014 22:10:00 UTC
+dimanche 20 avril 2014 22:10:00 UTC+00:00

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:858
/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:567

11) Cake\Test\TestCase\I18n\TimeTest::testToString with data set "immutable" ('Cake\I18n\FrozenTime')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-dimanche 20 avril 2014 22:10:00 UTC
+dimanche 20 avril 2014 22:10:00 UTC+00:00

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:858
/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:567

12) Cake\Test\TestCase\I18n\TimeTest::testParseDateTime with data set "mutable" ('Cake\I18n\Time')
Failed asserting that null is not null.

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:746

13) Cake\Test\TestCase\I18n\TimeTest::testParseDateTime with data set "immutable" ('Cake\I18n\FrozenTime')
Failed asserting that null is not null.

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:746

14) Cake\Test\TestCase\I18n\TimeTest::testParseDate with data set "mutable" ('Cake\I18n\Time')
Failed asserting that null is not null.

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:780

15) Cake\Test\TestCase\I18n\TimeTest::testParseDate with data set "immutable" ('Cake\I18n\FrozenTime')
Failed asserting that null is not null.

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:780

16) Cake\Test\TestCase\I18n\TimeTest::testParseTime with data set "mutable" ('Cake\I18n\Time')
Failed asserting that null is not null.

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:800

17) Cake\Test\TestCase\I18n\TimeTest::testParseTime with data set "immutable" ('Cake\I18n\FrozenTime')
Failed asserting that null is not null.

/home/cake/cakephp/tests/TestCase/I18n/TimeTest.php:800

18) Cake\Test\TestCase\Network\ResponseTest::testOutputCompressed
Failed asserting that true is false.

/home/cake/cakephp/tests/TestCase/Network/ResponseTest.php:532

19) Cake\Test\TestCase\Validation\ValidationTest::testLocalizedTime
Failed asserting that false is true.

/home/cake/cakephp/tests/TestCase/Validation/ValidationTest.php:1570

20) Cake\Test\TestCase\View\Helper\TimeHelperTest::testFormat
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Thursday January 14 2010 1:59:28 PM GMT'
+'Thursday January 14 2010 1:59:28 PM GMT+00:00'

/home/cake/cakephp/tests/TestCase/View/Helper/TimeHelperTest.php:499
/home/cake/cakephp/tests/TestCase/View/Helper/TimeHelperTest.php:441

21) Cake\Test\TestCase\Database\Type\DateTimeTypeTest::testLocaleParserDisable
null does not match expected type "object".

/home/cake/cakephp/tests/TestCase/Database/Type/DateTimeTypeTest.php:227
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

22) Cake\Test\TestCase\Database\Type\DateTimeTypeTest::testMarshalWithLocaleParsing
null does not match expected type "object".

/home/cake/cakephp/tests/TestCase/Database/Type/DateTimeTypeTest.php:244
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

23) Cake\Test\TestCase\Database\Type\TimeTypeTest::testMarshalWithLocaleParsing
Failed asserting that null is not null.

/home/cake/cakephp/tests/TestCase/Database/Type/TimeTypeTest.php:184
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

24) Cake\Test\TestCase\Database\Type\DateTimeTypeTest::testLocaleParserDisable
null does not match expected type "object".

/home/cake/cakephp/tests/TestCase/Database/Type/DateTimeTypeTest.php:227
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

25) Cake\Test\TestCase\Database\Type\DateTimeTypeTest::testMarshalWithLocaleParsing
null does not match expected type "object".

/home/cake/cakephp/tests/TestCase/Database/Type/DateTimeTypeTest.php:244
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

26) Cake\Test\TestCase\Database\Type\TimeTypeTest::testMarshalWithLocaleParsing
Failed asserting that null is not null.

/home/cake/cakephp/tests/TestCase/Database/Type/TimeTypeTest.php:184
/home/cake/cakephp/tests/TestCase/DatabaseSuite.php:68

FAILURES!
Tests: 6777, Assertions: 20613, Errors: 5, Failures: 26, Skipped: 144.
make: *** [test] Error 2

大多数这些问题似乎与 i18n 相关。希望能够解决这个问题,以便我可以自信地制作 PR!

4

0 回答 0