Commit graph

17 commits

Author SHA1 Message Date
Matěj Suchánek
c231736471 Fix some typos
Bug: T201491
Change-Id: I5c9408c262f09c936525f35abfacfa92a193b791
2023-03-21 15:58:09 +01:00
Subramanya Sastry
d8d6ecd39f Generate/set/get TOCData/SectionMetadata objects instead of arrays
* ParserOutput::setSections()/::getSections() are expected
  to be deprecated. Uses in extensions and skins will need to be
  migrated in follow up patches once the new interface has stabilized.

* In the skins code, the metadata is converted back to an array.
  Downstream skin TOC consumers will need to be migrated as well
  before we can remove the toLegacy() conversion.

* Fixed SerializationTestTrait's validation method
  - Not sure if this is overkill but should handle all future
    complex objects we might stuff into the ParserCache.

* This patch emits a backward-compatible Sections property in order to
  avoid changing the parser cache serialization format. T327439 has
  been filed to eventually use the JsonCodec support for object
  serialization, but for this initial patch it makes sense to avoid
  the need for a concurrent ParserCache format migration by using a
  backward-compatible serialization.

* TOCData is nullable because the intent is that
  ParserOutput::setTOCData() is MW_MERGE_STRATEGY_WRITE_ONCE; that is,
  only the top-level fragment composing a page will set the TOCData.
  This will be enforced in the future via wfDeprecated() (T327429),
  but again our first patch is as backward-compatible as possible.

Bug: T296025
Depends-On: I1b267d23cf49d147c5379b914531303744481b68
Co-Authored-By: C. Scott Ananian <cananian@wikimedia.org>
Co-Authored-By: Subramanya Sastry <ssastry@wikimedia.org>
Change-Id: I8329864535f0b1dd5f9163868a08d6cb1ffcb78f
2023-01-19 16:18:13 -05:00
Brian Wolff
e219728857 Do not compare byte-for-byte of serialized items in tests [php8.1]
PHP 8.1 changes the order of protected properties in the output
of serialize(). Previously they were at the end of the
serialized stream, now they are at the beginning.

Given that serialization formats have multiple equivalent encodings,
and there is no guarantee that they might not arbitrary change between
versions in backwards compatible ways, I think we should not do
byte for byte comparisons. Instead we should deserialize both
and compare the resulting objects for equality. This should test
what we want to know (That we can read serialized structures) well
also being safe against compatible format changes.

This fixes a number of failing ParserOutputTest::testSerialization
on php 8.1.

Bug: T313663
Change-Id: Ic7a08b436d65ab7492f343fa02281e245834aaea
2022-08-24 07:06:06 +00:00
Thiemo Kreuz
68ec2661d2 Use native array_column() in tests instead of loops
It's just a nice, lesser known convenience function. Exists since
PHP 5.5.

The changes to SerializationTestTrait ended being a little different.
Original I tried to use array_column() as well. But it drops the
array keys, which is relevant here.

We found that calling the two methods getTestInstances(AndAssertions)
multiple times is quite expensive and should be avoided. I changed
the code slightly so it's much less likely this is done unintentionally.

Change-Id: Ifaba3c370871a7c97b4d81ec21ff6ec134433fc0
2022-08-16 15:41:14 +02:00
C. Scott Ananian
ea4bedee9d Remove misleading test in SerializationTestTrain::validateObjectEquality()
The initial object comparison using `==` compares all the property values
using `==` as well.  This causes (for example) the string "1" to compare
as equal to the number `1`, the empty string `""` to compare as equal
to the number `0` and other surprising things.

It appears that this comparison was done at an attempt at performance
optimization, but that has little place in a test suite.  Use the full
recursive strict comparison instead.

This requires updating one ParserCache test case which was apparently
created incorrectly (or not properly updated) and relied on the
previous behavior (numbers comparing as equal to strings) to pass.

Change-Id: Ife0e9ccc7be0f4933975bb326203693bc15a9658
2022-03-31 09:50:51 -04:00
Kosta Harlan
0c2cc804e1 phpunit: Use is_file/is_dir instead of file_exists
Yes, it's a micro-optimization. See https://bugs.php.net/bug.php?id=78285
and https://thephp.cc/articles/caching-makes-everything-faster-right
for more info.

Change-Id: Ib8e8e9794e15066476f35cdb1236df8b983274d6
2022-01-03 21:47:56 +01:00
Petr Pchelko
a1aa3e0827 Hard-deprecate all public property access on CacheTime and ParserOutput.
- Added a test where ParserOutput objects with CacheTime
properties set are unserialized from previous versions.
- Generate new serialization tests for 1.38

Now all serialization in production is JSON, so changing
property visibility shouldn't affect ParserCache.

Bug: T263851
Depends-On: I283340ff559420ceee8f286ba3ef202c01206a23
Change-Id: I70d6feb1c995a0a0f763b21261141ae8ee6dc570
2021-10-13 13:27:16 -04:00
Petr Pchelko
4d54b4caa0 Run ParserOutput serialization tests against latest example available
In ParserOutput serialization tests we have a large number of examples
saved for different versions of MW. When MW version is released,
but the serialization doesn't change, we stop running some serialization
tests cause we can no longer find the latest example.

Change-Id: I01e8e0e17e2371b2cd08d200d3a4611d814e74bb
2021-10-13 13:26:47 -04:00
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02:00
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
Umherirrender
393b6fb508 Add missing @param tags in tests
And exclude the rest inline to remove global exclude

Bug: T238572
Change-Id: Ib4c207177dd73702c113e6233f59be6e571a0f6a
2021-02-01 20:38:05 +01:00
Thiemo Kreuz
2f66b3754f tests: Remove @param docs from test code that just repeat the signature
These are not only 100% identical to the actual code, but also:
* It's error-prone. Some are already wrong.
* These test…() functions are not meant to be called from
  anywhere. What is the target audience for this documentation?
* There is a @dataProvider. What such @param tags actually do is
  document the provider, but in an odd place. Just looking at
  the provider should give the same information.
* The MediaWiki CodeSniffer allows to skip @param when there is
  a @dataProvider, for the reasone listed.

Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
2021-01-21 03:41:23 +00:00
Umherirrender
49efbfe2fb Improve documentation about object to be stdClass or specific type
Some classes still needs exclude for the sniff

Change-Id: I9536c2ee84f6fb4c83cf862a152cf6b00344cb97
2020-11-20 14:47:56 +00:00
jenkins-bot
661b421aa3 Merge "Fix GhostFieldAccessTrait tests" 2020-11-17 18:36:25 +00:00
Petr Pchelko
841476c223 Change SerializationTestTrait to call serializers inside tests
Methods called in @dataProvider are not counted in code coverage,
making an impression we are not covering serialization code.
Move calling the serializer/deserializer into some of the tests
to fix coverage reporting.

Change-Id: I014bdee94b7297f6d298a3fea91482674c666fe3
2020-11-12 08:58:13 -07:00
Petr Pchelko
2677811351 Fix GhostFieldAccessTrait tests
Change-Id: Id03febbcb9d250a649eb03006f4984d0fb38d8e5
2020-11-11 21:53:01 -07:00
Petr Pchelko
017cfcf016 Forward-compat for merging CacheTime and ParserOutput mOptions
CacheTime::mUsedOptions and ParserOutput::mAccessedOptions
do exactly the same thing and has to be merged into a single property.
This patch adds forward-compatibility and needs to be deployed
at least one train before the patch which actually merges the properties.

Change-Id: Ic9d71a443994e2545ebf2a826b9155c82961cb88
2020-11-10 07:09:41 -07:00