This ensures that assertions work in a uniform way,
and provides meaningful messages in cause of failure.
Change-Id: Ic01715b9a55444d3df6b5d4097e78cb8ac082b3e
Let PHP do the UTF-8 encoding of Unicode characters in PHP strings.
Also use faster str_replace instead of preg_replace.
Change-Id: I4e99de694a607e2b5df52c6efcd3d863bb42f76e
- Removed the str_replace() call to replace unescaped line terminators
if UTF8_OK is set. PHP 7.1 and later escape these by default.
The speedup isn't much at all (about 1% in my testing when encoding an
API siteinfo result taken from enwiki). Perhaps it's not surprising
given the way str_replace() works[1]. Still, it's better not to spend
CPU time looking for characters that will not occur.
- Changed the algorithm for the optional spaces-to-tabs conversion when
pretty printing. Instead of replacing one indent level throughout the
entire string before replacing the next level, use a regex to replace
in one pass. This is usually faster now that PHP 7 enables PCRE's JIT
compiler by default. Without JIT, the regex was often slower.
The speedup can be large for deeply nested data. For example, in my
testing the languages/i18n data took about 8% less time to encode as
tab-indented JSON, yet the API site info result took about 45% less.
(This, of course, isn't actually relevant to the API even when pretty
printed output is requested, because ApiFormatJson uses the default
indent string of four spaces, which will always be faster unless
support for tab indentation is added to PHP's json extension.)
- Set options using if statements instead of the ternary operator. This
is the clearer way, and maybe the slightly faster one, skipping the
assignment when the flags do not need to be set.
[1]: https://github.com/php/php-src/blob/PHP-8.0.10/ext/standard/string.c#L2969
Change-Id: Iebb1df0264e335a1819956710eeacf6d6b8f1471
The comment added in b9461e3f1c is incorrect. This is actually a
decode error, so is relevant to FormatJson::parse().
Change-Id: I3cc33f0f260c0ba4fe96fb75565f52d089b9a975
FormatJsonUnitTest was split off back when the
rest still needed to be integration tests[1], but
after [2] with global functions being loaded for unit
tests, the rest of FormatJsonTest was moved to a
unit test since it no longer required integration
[1] I86dfe17f794c615048b3c20487b0e84d38d13b93
[2] Ib42c56a67926ebcdba53f4c6c54a5bff98cb77a3
Change-Id: I92bb7a6cafd82d8b2186f92e0953bc18f40b0ee4
Most of these are found by the not yet released I10559d8.
I remove the type MockObject in some cases when the calling
code really does not need to know if he get's a mock or the
real thing. However, I do this only in places that are very
closely related to the fixes.
Change-Id: I26a4c3c5a8ae141bf56161b52b54bce7e68f2e30
One major difference with what we've had before is that now we
actually write class names into the serialization - given that
this new mechanism is extencible, we can't establish any kind
of mapping of allowed classes. I do not think it's a problem
though.
Bug: T264394
Change-Id: Ia152f3b76b967aabde2d8a182e3aec7d3002e5ea
This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.
The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.
You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml
Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
2019-06-13 22:56:31 +02:00
Renamed from tests/phpunit/includes/json/FormatJsonTest.php (Browse further)