Skip to content

PHPUnit Error: Replace removed assertObjectHasAttribute() with assertObjectHasProperty() (Moodle 5.1) #504

@ctam

Description

@ctam

The PHPUnit test suite is failing in the Moodle 5.1 environment because it calls assertObjectHasAttribute(), which has been removed in PHPUnit 10.

To maintain compatibility with Moodle 5.1 and newer PHPUnit versions, these calls must be updated to assertObjectHasProperty().

Error Logs

The following 4 errors were identified in:

There were 4 errors:

1) locallib_test::test_local_kaltura_format_lti_instance_object
Error: Call to undefined method locallib_test::assertObjectHasAttribute()

/home/runner/work/moodle/moodle/public/local/kaltura/tests/locallib_test.php:719

2) locallib_test::test_local_kaltura_log_data_logging_request_data
Error: Call to undefined method locallib_test::assertObjectHasAttribute()

/home/runner/work/moodle/moodle/public/local/kaltura/tests/locallib_test.php:849

3) locallib_test::test_local_kaltura_log_data_logging_response_data
Error: Call to undefined method locallib_test::assertObjectHasAttribute()

/home/runner/work/moodle/moodle/public/local/kaltura/tests/locallib_test.php:908

4) migrationlib_test::test_initialization_of_config_values
Error: Call to undefined method migrationlib_test::assertObjectHasAttribute()

/home/runner/work/moodle/moodle/public/local/kaltura/tests/migrationlib_test.php:47

Steps to Reproduce

Run the PHPUnit tests in a Moodle 5.1 environment:

vendor/bin/phpunit local/kaltura/tests/locallib_test.php
vendor/bin/phpunit local/kaltura/tests/migrationlib_test.php

Proposed Fix

Replace all instances of $this->assertObjectHasAttribute('name', $object) with $this->assertObjectHasProperty('name', $object).

Example:

// Before
$this->assertObjectHasAttribute('id', $result);

// After
$this->assertObjectHasProperty('id', $result);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions