Passing xpath to XmlStructure::matchElement() always throws Exception

未關閉
#6 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
45/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
php, symfony
領域
backend

研究方向

閱讀 src/Util/XmlStructure.php 和 SOAP 模組的 grabTextContentFrom() 路徑,然後建立一個重現類似 /example 的 XPath 的單元測試。完成標準是 XPath 不再引發 CSS selector exception,並回傳符合的元素。

由索引模型根據 Issue 內容生成。

描述

The signature allows param $cssOrXpath: https://github.com/Codeception/lib-xml/blob/main/src/Util/XmlStructure.php#L37
But when an xpath is passed, it will throw an exception.

This is broken since Codeception 5.0:

Reproduce

$xpath = '/example';
$I->grabTextContentFrom($xpath))
  • Run the test. Output:
1) ExampleCest: Call undefined operation
 Test  ExampleCest.php:example

  [Symfony\Component\CssSelector\Exception\SyntaxErrorException] Expected selector, but <delimiter "/" at 0> found.

Scenario Steps:

 4. $I->grabTextContentFrom("/example") at (..)

#1  (..)\vendor\symfony\css-selector\Exception\SyntaxErrorException.php:28
#2  (..)\vendor\symfony\css-selector\Parser\Parser.php:284
#3  (..)\vendor\symfony\css-selector\Parser\Parser.php:115
#4  (..)\vendor\symfony\css-selector\Parser\Parser.php:100
#5  (..)\vendor\symfony\css-selector\Parser\Parser.php:42
#6  (..)\vendor\symfony\css-selector\XPath\Translator.php:222
#7  (..)\vendor\symfony\css-selector\XPath\Translator.php:92
#8  (..)\vendor\symfony\css-selector\CssSelectorConverter.php:65
#9  Codeception\Module\SOAP->grabTextContentFrom

Possible fix

Re-implement the try-catch:

    public function matchElement(string $cssOrXPath): ?DOMNode
    {
        $domXpath = new DOMXpath($this->xml);
        try {
            $selector = (new CssSelectorConverter())->toXPath($cssOrXPath);
            $els = $domXpath->query($selector);
            if ($els !== false && count($els) > 0) {
                return $els->item(0);
            }
        } catch (\Symfony\Component\CssSelector\Exception\ParseException $e) {
        }
        $els = $domXpath->query($cssOrXPath);
        if ($els !== false && count($els) > 0) {
            return $els->item(0);
        }
        throw new ElementNotFound($cssOrXPath);
    }
主要語言
PHP
星號
17
分支
1
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Codeception/lib-xml 的其他 Issue

查看 Codeception/lib-xml 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。