Skip to content

Issue #151: Resolved unit tests for Moodle 5.1+#160

Merged
micoreyes merged 3 commits into
MOODLE_404_STABLEfrom
MOODLE_404_STABLE-issue151
Jun 11, 2026
Merged

Issue #151: Resolved unit tests for Moodle 5.1+#160
micoreyes merged 3 commits into
MOODLE_404_STABLEfrom
MOODLE_404_STABLE-issue151

Conversation

@niko-hoogeveen

Copy link
Copy Markdown
Contributor

Closes issue #151.

Updated search_elastic\esrequest_test::test_get_unreachable_host to expect a 503 status code for an unreachable host. This logic was updated in the plugin, but not in the test.

There were some variables with different names in the test provider than what was being checked in the tests. I've updated the tests to reflect the same variable names in the test to get rid of the errors.

Error: Unknown named parameter $status
Error: Unknown named parameter $expectednumchunks

Environment

- Moodle 5.1.3+ (Build: 20260220)
- PHP: 8.4.22
- DB: MySQL 8.4
- Branch: MOODLE_404_STABLE

Testing instructions:

  • search_elastic test suite: vendor/bin/phpunit --testsuite search_elastic_testsuite
  • Running the unit tests for search_elastic will produce the following errors (on the above environment):
Moodle 5.1.3+ (Build: 20260220)
Php: 8.4.22, mysqli: 8.4.9, OS: Linux 6.17.0-1025-oem x86_64
PHPUnit 11.5.12 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.22
Configuration: /var/www/upstream-mdl/phpunit.xml

.....SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS.....F..........SSSS  63 / 189 ( 33%)
SSSSSSSSSEEEE.................................................. 126 / 189 ( 66%)
...........................................................EEE. 189 / 189 (100%)


Time: 00:19.818, Memory: 87.50 MB

There were 7 errors:

1) search_elastic\local\chunking\fixed_size_test::test_chunk_with_overlap with data set "No overlap" (200, 0, 3)
Error: Unknown named parameter $expectednumchunks

2) search_elastic\local\chunking\fixed_size_test::test_chunk_with_overlap with data set "No overlap larger max size" (2000, 0, 1)
Error: Unknown named parameter $expectednumchunks

3) search_elastic\local\chunking\fixed_size_test::test_chunk_with_overlap with data set "Max size greater than text length with overlap" (2000, 100, 1)
Error: Unknown named parameter $expectednumchunks

4) search_elastic\local\chunking\fixed_size_test::test_chunk_with_overlap with data set "Max size less than text length with overlap" (400, 10, 2)
Error: Unknown named parameter $expectednumchunks

5) search_elastic\server_ready_check_test::test_check with data set "not set" ('', 'na')
Error: Unknown named parameter $status

6) search_elastic\server_ready_check_test::test_check with data set "invalid hostname" ('invalid.com', 'error')
Error: Unknown named parameter $status

7) search_elastic\server_ready_check_test::test_check with data set "valid hostname" ('valid.com', 'ok')
Error: Unknown named parameter $status

--

There was 1 failure:

1) search_elastic\esrequest_test::test_get_unreachable_host
Failed asserting that exception of type "GuzzleHttp\Exception\ConnectException" is thrown.

Expected Output from PHPUnit Tests

  • Pulling this branch MOODLE_404_STABLE-issue151 and re-running the testsuite:
Moodle 5.1.3+ (Build: 20260220)
Php: 8.4.22, mysqli: 8.4.9, OS: Linux 6.17.0-1025-oem x86_64
PHPUnit 11.5.12 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.22
Configuration: /var/www/upstream-mdl/phpunit.xml

.....SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS................SSSS  63 / 189 ( 33%)
SSSSSSSSS...................................................... 126 / 189 ( 66%)
............................................................... 189 / 189 (100%)


Time: 00:40.370, Memory: 87.50 MB

OK, but there were issues!
Tests: 189, Assertions: 459, PHPUnit Deprecations: 23, Skipped: 51.

@niko-hoogeveen niko-hoogeveen changed the base branch from MOODLE_404_STABLE to MOODLE_501_STABLE June 11, 2026 15:50
@micoreyes

Copy link
Copy Markdown
Contributor

Can you run this tests for me @niko-hoogeveen

vendor/bin/phpunit  public/search/engine/elastic/tests/local/chunking/chunking_engine_test.php
vendor/bin/phpunit  public/search/engine/elastic/tests/externallib_test.php

@niko-hoogeveen

niko-hoogeveen commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Sure thing @micoreyes

Looks like those tests are skipped. It's due to a test server not being available during the test.

if (!$hostname || !$port || !$index) {
    $this->markTestSkipped('Elastic extension test server not set.');
}
vendor/bin/phpunit  public/search/engine/elastic/tests/local/chunking/chunking_engine_test.php
Moodle 5.1.3+ (Build: 20260220)
Php: 8.4.22, mysqli: 8.4.9, OS: Linux 6.17.0-1025-oem x86_64
PHPUnit 11.5.12 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.22
Configuration: /var/www/upstream-mdl/phpunit.xml

SSSSSSSSSSS                                                       11 / 11 (100%)

Time: 00:00.014, Memory: 68.50 MB

OK, but there were issues!
Tests: 11, Assertions: 0, PHPUnit Deprecations: 1, Skipped: 11.
vendor/bin/phpunit  public/search/engine/elastic/tests/externallib_test.php
Moodle 5.1.3+ (Build: 20260220)
Php: 8.4.22, mysqli: 8.4.9, OS: Linux 6.17.0-1025-oem x86_64
PHPUnit 11.5.12 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.22
Configuration: /var/www/upstream-mdl/phpunit.xml

SS                                                                  2 / 2 (100%)

Time: 00:00.011, Memory: 68.50 MB

OK, but there were issues!
Tests: 2, Assertions: 0, PHPUnit Deprecations: 1, Skipped: 2.

@niko-hoogeveen niko-hoogeveen changed the base branch from MOODLE_501_STABLE to MOODLE_404_STABLE June 11, 2026 17:51
@micoreyes

micoreyes commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

LGTM merging fix for unittest now.
4.5

root@e69363f1529d:/var/www/TEST# vendor/bin/phpunit --testsuite search_elastic_testsuite
Moodle 4.5.12 (Build: 20260608), 51ed8ca19e386e52285da1d67f7b18bcc5386a36
Php: 8.3.31, mysqli: 8.0.46, OS: Linux 6.17.0-35-generic x86_64
PHPUnit 9.6.34 by Sebastian Bergmann and contributors.

.....SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS................SSSS  63 / 189 ( 33%)
SSSSSSSSS...................................................... 126 / 189 ( 66%)
............................................................... 189 / 189 (100%)


Time: 00:24.559, Memory: 99.50 MB

OK, but incomplete, skipped, or risky tests!
Tests: 189, Assertions: 459, Skipped: 51.

5.1

vendor/bin/phpunit  public/search/engine/elastic/tests/local/chunking/chunking_engine_test.php
Moodle 5.1.3+ (Build: 20260220)
Php: 8.4.22, mysqli: 8.4.9, OS: Linux 6.17.0-1025-oem x86_64
PHPUnit 11.5.12 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.22
Configuration: /var/www/upstream-mdl/phpunit.xml

SSSSSSSSSSS                                                       11 / 11 (100%)

Time: 00:00.014, Memory: 68.50 MB

OK, but there were issues!
Tests: 11, Assertions: 0, PHPUnit Deprecations: 1, Skipped: 11.

@micoreyes micoreyes merged commit 9fc4c11 into MOODLE_404_STABLE Jun 11, 2026
44 of 54 checks passed
@niko-hoogeveen niko-hoogeveen deleted the MOODLE_404_STABLE-issue151 branch June 11, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants