Skip to content

Commit

Permalink
Extra tests / wpdb
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Sep 2, 2022
1 parent ee3d836 commit 0684651
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/phpunit/tests/db/magicmethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,65 @@ private function get_clean_wpdb() {
return $mock_obj;
}

/**
* Verify that public properties are not affected by the changes made in the magic methods.
*
* @ticket 56034
*
* @coversNothing
*
* @dataProvider data_public_properties_are_not_affected_by_changes_in_magic_methods
*
* @param string $name Property name.
* @param mixed $default Default value for the property.
*/
public function test_public_properties_are_not_affected_by_changes_in_magic_methods( $name, $default = null ) {
$obj = $this->get_clean_wpdb();

// Verify initial state.
if ( null !== $default ) {
$this->assertTrue( isset( $obj->$name ), 'Unexpected initial state' );
$this->assertSame( $default, $obj->$name, 'Initial value does not match expectations' );
} else {
$this->assertFalse( isset( $obj->$name ), 'Unexpected initial state' );
$this->assertNull( $obj->$name, 'Initial value does not match expectations' );
}

// Overwrite the property value and verify the new state.
$obj->$name = self::TEST_VALUE_1;
$this->assertTrue( isset( $obj->$name ), 'Setting the property failed [1]' );
$this->assertSame( self::TEST_VALUE_1, $obj->$name, 'Property has not been assigned the first value' );

// Unset the property and verify the new state.
unset( $obj->$name );
$this->assertFalse( isset( $obj->$name ), 'Unsetting the property failed' );

// Set the property again and verify the updated state.
$obj->$name = self::TEST_VALUE_2;
$this->assertTrue( isset( $obj->$name ), 'Setting the property failed [2]' );
$this->assertSame( self::TEST_VALUE_2, $obj->$name, 'Property has not been assigned the second value' );
}

/**
* Data provider.
*
* @return array
*/
public function data_public_properties_are_not_affected_by_changes_in_magic_methods() {
return array(
'Declared public property: $show_errors (has default value)' => array(
'name' => 'show_errors',
'default' => false,
),
'Declared public property: $charset (no default value)' => array(
'name' => 'charset',
),
'Declared public property: $is_mysql (has default value: null)' => array(
'name' => 'is_mysql',
),
);
}

/**
* @ticket 18510
*/
Expand Down

0 comments on commit 0684651

Please sign in to comment.