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

オープン
#6 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
php, symfony
領域
backend

調査の方向性

src/Util/XmlStructure.php と SOAP モジュールの grabTextContentFrom() の処理経路を確認し、/example のような XPath を再現するユニットテストを作成します。XPath が CSS セレクター例外を発生させず、該当する要素が返されれば完了です。

索引モデルが 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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Codeception/lib-xml のほかの issue

Codeception/lib-xml の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。