Xml::arrayToXml fails on nested arrays
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 65/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- php
- Lĩnh vực
- testing-qa
Hướng nghiên cứu
Bắt đầu từ helper Xml::arrayToXml và tái hiện ví dụ về mảng lồng nhau trong issue. Kiểm tra nhánh đệ quy trong đó phần tử lồng nhau được truyền vào trước khi nó tồn tại, sau đó xác minh rằng ví dụ tạo ra XML lồng nhau như mong đợi mà không có lỗi PHP.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The helper function arrayToXml has code indended to handle nested arrays, but currently always throws PHP errors. This means nested arrays can't be used when testing soap functions with array data either.
Reproduce
Code:
$dom = new \DOMDocument();
$array = [
'foo' => [
'bar' => '1'
]
];
echo \Codeception\Util\Xml::arrayToXml($dom, $dom, $array)->saveXML();
Expected output:
<?xml version="1.0"?>
<foo><bar>1</bar></foo>
Result:
Undefined property: DOMDocument::$foo
Cause
When the function encounters an array, it calls itself to parse the array, with $domNode->$el as the new $domNode parameter. The problem is that that node ->$el will never exist, since that's the node this function was supposed to create in the first place.
Fix
Create a new element first, to pass to the recursive call, and then append that new node to the xml structure.
Current code:
if (is_array($val)) {
self::arrayToXml($xml, $domNode->$el, $val);
} else {
$domNode->appendChild($xml->createElement($el, $val));
}
Fixed code:
if (is_array($val)) {
$elementNode = $xml->createElement($el);
self::arrayToXml($xml, $elementNode, $val);
$domNode->appendChild($elementNode);
} else {
$domNode->appendChild($xml->createElement($el, $val));
}
Alternatively, we could make it a little more consistent by always creating and appending the element in the same way, and only set the value inside the if-condition. That code would look like this:
$elementNode = $xml->createElement($el);
if (is_array($val)) {
self::arrayToXml($xml, $elementNode, $val);
} else {
$elementNode->nodeValue = $val;
}
$domNode->appendChild($elementNode);
Both solutions result in working code for nested arrays.
- Ngôn ngữ chính
- PHP
- Star
- 17
- Fork
- 1
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Codeception/lib-xml
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
Codeception/lib-xml#6 · 1 bình luận ·
Tất cả issue của Codeception/lib-xml
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
taskforcesh/bullmq#5238 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects itCó thể đã có người làm @bfs2021 đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Automattic/jetpack#55517 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
-
area/import type/enhancement when/later
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày