From 6eb7e31067fb1237805b104ed8b5ab12ae8e811b Mon Sep 17 00:00:00 2001 From: Sascha Date: Wed, 4 Sep 2024 11:39:44 +0000 Subject: [PATCH 1/8] feat: add event cache --- src/XmlProcessor.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/XmlProcessor.php b/src/XmlProcessor.php index 703cc3b..78886f6 100644 --- a/src/XmlProcessor.php +++ b/src/XmlProcessor.php @@ -18,6 +18,7 @@ class XmlProcessor private string $currentValue = ''; private ?array $skipNodes = NULL; + private array $eventCache = []; private \XMLReader $xml; private XmlProcessorContext $context; @@ -37,7 +38,9 @@ class XmlProcessor */ public function __construct( iterable $processors, - iterable $parserProperties = [] + iterable $parserProperties = [ + \XMLReader::VALIDATE => false + ] ) { $this->xml = new \XMLReader(); @@ -158,13 +161,19 @@ private function getProcessorEvents(string $event, string $contextClass = NodePr private function getProcessorForEvent(string $event): iterable { $nodePath = implode('/', $this->nodePath); - foreach ($this->processors as $processor) { - foreach ($processor->getSubscribedEvents($nodePath, $this->context) as $e => $action) { - if ($e === $event) { - yield $action; + + if (!is_array($this->eventCache[$nodePath][$event] ?? false)) { + $this->eventCache[$nodePath][$event] = []; + foreach ($this->processors as $processor) { + foreach ($processor->getSubscribedEvents($nodePath, $this->context) as $e => $action) { + if ($e === $event) { + $this->eventCache[$nodePath][$event][] = $action; + } } } } + + yield from $this->eventCache[$nodePath][$event]; } /** From b4fe48d858cf4e4146adff17f21605e449e1c9bb Mon Sep 17 00:00:00 2001 From: Sascha Date: Thu, 26 Sep 2024 08:41:03 +0000 Subject: [PATCH 2/8] feat: update php-actions in workflow --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ee77cc..2285f4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,9 @@ jobs: - { php: 8.3, phpunit: 10, experimental: true } steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Composer cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: "vendor" key: ${{ runner.os }}-${{ matrix.env.php }}-composer-${{ hashFiles('composer.json') }} @@ -37,7 +37,7 @@ jobs: run: composer install -o --no-interaction --no-suggest --prefer-dist - name: PHPUnit tests - uses: php-actions/phpunit@v3 + uses: php-actions/phpunit@v4 env: XDEBUG_MODE: coverage with: @@ -67,6 +67,6 @@ jobs: path: code-coverage-results.md - name: Behat tests - uses: php-actions/behat@master + uses: php-actions/behat@v1.0.1 with: php_version: "${{ matrix.env.php }}" From 421a92972a1063562a0109efff66764f96f095c4 Mon Sep 17 00:00:00 2001 From: Sascha Date: Thu, 26 Sep 2024 08:43:49 +0000 Subject: [PATCH 3/8] feat: add vendored_behat_path to workflow action --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2285f4d..ab42a66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: - { php: 7.4, phpunit: 9 } - { php: 8.0, phpunit: 10 } - { php: 8.1, phpunit: 10 } - - { php: 8.2, phpunit: 10 } + - { php: 8.2, phpunit: 10, main: true } - { php: 8.3, phpunit: 10, experimental: true } steps: @@ -47,7 +47,7 @@ jobs: version: "${{ matrix.env.phpunit }}" configuration: "phpunit.xml" - name: "Code Coverage Report" - if: "matrix.env.php == '8.2' && github.event_name == 'pull_request'" + if: "matrix.env.main == true && github.event_name == 'pull_request'" uses: irongut/CodeCoverageSummary@v1.3.0 with: filename: cobertura.xml @@ -60,7 +60,7 @@ jobs: output: both thresholds: '60 80' - name: Add Coverage PR Comment - if: "matrix.env.php == '8.2' && github.event_name == 'pull_request'" + if: "matrix.env.main == true && github.event_name == 'pull_request'" uses: marocchino/sticky-pull-request-comment@v2 with: recreate: true @@ -70,3 +70,4 @@ jobs: uses: php-actions/behat@v1.0.1 with: php_version: "${{ matrix.env.php }}" + vendored_behat_path: vendor/bin/behat From f285118e0b101eca94de395c4758e1826a895d7e Mon Sep 17 00:00:00 2001 From: Sascha Date: Thu, 26 Sep 2024 08:47:05 +0000 Subject: [PATCH 4/8] fix: vendored_behat_path --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab42a66..8fdfc56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,4 +70,4 @@ jobs: uses: php-actions/behat@v1.0.1 with: php_version: "${{ matrix.env.php }}" - vendored_behat_path: vendor/bin/behat + vendored_behat_path: ${GITHUB_WORKSPACE}/vendor/bin/behat From abf5dac5d75231eb8b1de4f63f15931e7c0d5015 Mon Sep 17 00:00:00 2001 From: Sascha Date: Thu, 26 Sep 2024 08:48:39 +0000 Subject: [PATCH 5/8] fix: vendored_behat_path --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fdfc56..3c9b053 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,4 +70,4 @@ jobs: uses: php-actions/behat@v1.0.1 with: php_version: "${{ matrix.env.php }}" - vendored_behat_path: ${GITHUB_WORKSPACE}/vendor/bin/behat + vendored_behat_path: "${{ github.workspace }}/vendor/bin/behat" From 5e30f6a9ad216bca0ee8b40568a5c61772c8aef3 Mon Sep 17 00:00:00 2001 From: Sascha Date: Thu, 26 Sep 2024 08:51:58 +0000 Subject: [PATCH 6/8] fix: vendored_behat_path --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c9b053..ea6a42c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,4 +70,4 @@ jobs: uses: php-actions/behat@v1.0.1 with: php_version: "${{ matrix.env.php }}" - vendored_behat_path: "${{ github.workspace }}/vendor/bin/behat" + vendored_behat_path: "vendor/bin/behat" From 26b90cf07636b65785288768ed2e4cd21226dbeb Mon Sep 17 00:00:00 2001 From: Sascha Date: Thu, 26 Sep 2024 08:56:47 +0000 Subject: [PATCH 7/8] feat: remove php-action/behat and use installed behat --- .github/workflows/ci.yml | 6 ++---- composer.json | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea6a42c..5ef13c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,5 @@ jobs: path: code-coverage-results.md - name: Behat tests - uses: php-actions/behat@v1.0.1 - with: - php_version: "${{ matrix.env.php }}" - vendored_behat_path: "vendor/bin/behat" + run: composer run behat + diff --git a/composer.json b/composer.json index dd19a77..d3678df 100644 --- a/composer.json +++ b/composer.json @@ -27,5 +27,8 @@ "Netlogix\\XmlProcessor\\Behat\\": "features/" } }, + "scripts": { + "behat": "behat" + }, "prefer-stable": true } From b80196bc62c6586f0e285a09746fad3131ba33ed Mon Sep 17 00:00:00 2001 From: Sascha Date: Thu, 26 Sep 2024 08:58:28 +0000 Subject: [PATCH 8/8] feat: trigger workflow only on pull_request --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ef13c5..c3cdb08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: CI -on: [ push, pull_request ] +on: [ pull_request ] jobs: test: