aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/mocks/json
Commit message (Collapse)AuthorAgeFilesLines
* Remove 2-line PHPDocs that just repeat the types from the codethiemowmde2025-01-172-4/+0
| | | | | | | | | | | | | | | | Same as Ia294bf4 did for 1-line comments. This patch removes slightly more complex 2-line PHPDoc comments that don't add any new information to the code, but literally repeat what the code already says. They say "don't document the code, code the documentation", and we are doing this more and more. We just tend to forget to remove the obsolete comments. Note I'm also removing a line of text in a few cases when it's very short and literally says the same as the method name. Again, such comments add zero new information. Change-Id: I01535404bab458c6c47e48e5456403b7a64198ed
* [JsonCodec] Use wikimedia/json-codec to implement JsonCodecC. Scott Ananian2024-10-155-0/+230
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds support for serializing/deserializing objects which implement the JsonCodecable interface from the wikimedia/json-codec library used by Parsoid. JsonCodecable allows customizing the encoding of objects of a given class using a class-specific codec object, and JsonCodecable is an interface which is defined and can be used outside mediawiki core. In addition json-codec supports deserialization in the presence of aliased class names, fixing T353883. Backward and forward compatibility established via the mechanism described in https://www.mediawiki.org/wiki/Manual:Parser_cache/Serialization_compatibility Test data generated by this patch was added in I109640b510cef9b3b870a8c188f3b4f086d75d06 to ensure forward compatibility with the output after this patch is merged. Benchmarks: PHP 7.4.33 PHP 8.2.19 PHP 8.3.6 BEFORE AFTER BEFORE AFTER BEFORE AFTER Serialize: 926.7/s 1424.8/s 978.5/s 1542.4/s 1023.5/s 1488.6/s Serialize (assoc): 930.2/s 1378.6/s 974.6/s 1541.9/s 1022.4/s 1463.4/s Deserialize: 1942.7/s 1961.3/s 2118.8/s 2175.9/s 2129.8/s 2063.5/s Deserialize (assoc): 1952.0/s 1905.7/s 2107.5/s 2192.1/s 2153.3/s 2011.1/s These numbers definitely do not have as many significant digits as written here. But they should be sufficient to demonstrate that performance is not impaired by this patch and in fact serialization speed improves slightly. Bug: T273540 Bug: T327439 Bug: T346829 Bug: T353883 Depends-On: If1d70ba18712839615c1f4fea236843ffebc8645 Change-Id: Ia1017dcef462f3ac1ff5112106f7df81f5cc384f
* mocks: Add missing documentation to class propertiesUmherirrender2024-09-142-0/+2
| | | | | | | | | | Add doc-typehints to class properties found by the PropertyDocumentation sniff to improve the documentation. Once the sniff is enabled it avoids that new code is missing type declarations. This is focused on documentation and does not change code. Change-Id: I56a1d27ba2dfbcdd929a0e0c96664bc2a31e38f2
* Rename JsonUnserial… to JsonDeserial…James D. Forrester2024-06-122-13/+13
| | | | | | | | This is to make it clearer that they're related to converting serialized content back into JSON, rather than stating that things are not representable in JSON. Change-Id: Ic440ac2d05b5ac238a1c0e4821d3f2d858bc3d76
* Remove all @package commentsthiemowmde2024-05-102-2/+0
| | | | | | | | | | | | I don't think these do anything with the documentation generators we currently use. Especially not in tests. How are tests part of a "package" when the code is not? Note how most of these are simply identical to the namespace. They are most probably auto-generated by some IDEs but don't actually mean anything. Change-Id: I771b5f2041a8e3b077865c79cbebddbe028543d1
* JsonCodec: fix en/decoding of nested objects and stdClass objectsC. Scott Ananian2023-01-122-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a type annotation when encoding `stdClass` objects so that we can be sure to decode them as objects instead of arrays. This avoids issues such as that seen in the Graph extension (T312589) where an extension data key is stored as a stdClass. If ParserOutput was computed fresh, a subsequent getExtensionData(..) call will return a stdClass object, but if the ParserOutput was cached, getExtensionData() would return an array. After this change the return type is always consistent. Properly handle nested objects: encode all object values returned by JsonSerializable::jsonSerialize() (so that client is not responsible for implementing this correctly), and decode all object values *before* calling JsonUnserializable::newFromJsonArray (again, so that the client is not responsible for decoding its property values). The new behavior matches how serialize/unserialize is handled in the 'naive' JsonUnserializable{Sub,Super}Class test cases; ParserOutput (the only users of JsonCodec in core) was doing an extra manual decode for the ExtensionData array in ParserOutput::initFromJson that is no longer necessary. The GrowthExperiments and SemanticMediaWiki extensions were working around the non-recursive nature of JsonCodec; this patch depends on patches to GrowthExperiments to make it agnostic about whether object unserialization occurs before or after ::newFromJsonArray() is called, which can then be further cleaned up once this is released. A pull request for SemanticMediaWiki has also been submitted. Bug: T312589 Depends-On: I3413609251f056893d3921df23698aeed40754ed Change-Id: Id7d0695af40b9801b42a9b82f41e46118da288dc
* Safe ParserOutput extension data and JsonUnserializable helper.Petr Pchelko2020-11-102-0/+70
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