function PhpUnitWarningsTest::testAssertAttribute

Tests assertion methods accessing class attributes.

File

core/tests/Drupal/Tests/PhpUnitWarningsTest.php, line 72

Class

PhpUnitWarningsTest
@coversDefaultClass \Drupal\Tests\Traits\PhpUnitWarnings[[api-linebreak]] @group legacy

Namespace

Drupal\Tests

Code

public function testAssertAttribute() {
  if (RunnerVersion::getMajor() > 8) {
    $this->markTestSkipped("In PHPUnit 9+, assertion methods accessing class attributes are removed.");
  }
  $this->expectDeprecation('assertAttributeEquals() is deprecated and will be removed in PHPUnit 9.');
  $this->expectDeprecation('readAttribute() is deprecated and will be removed in PHPUnit 9.');
  $this->expectDeprecation('getObjectAttribute() is deprecated and will be removed in PHPUnit 9.');
  $this->expectDeprecation('assertAttributeSame() is deprecated and will be removed in PHPUnit 9.');
  $this->expectDeprecation('assertAttributeInstanceOf() is deprecated and will be removed in PHPUnit 9.');
  $this->expectDeprecation('assertAttributeEmpty() is deprecated and will be removed in PHPUnit 9.');
  $obj = new class  {
    protected $attribute = 'value';
    protected $class;
    protected $empty;
    public function __construct() {
      $this->class = new \stdClass();
    }

};
  $this->assertAttributeEquals('value', 'attribute', $obj);
  $this->assertAttributeSame('value', 'attribute', $obj);
  $this->assertAttributeInstanceOf(\stdClass::class, 'class', $obj);
  $this->assertAttributeEmpty('empty', $obj);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.