test: Replace deprecated assertion methods that access non-public properties with methods that use reflection.

Co-authored-by: Kenshin Okinaka <okinakak@yahoo.co.jp>
This commit is contained in:
Koji Tanaka 2023-01-07 20:25:24 +09:00 committed by Kamil Wylegala
parent b5e7d582d9
commit 7e4adb37e5
2 changed files with 22 additions and 8 deletions

View file

@ -2149,10 +2149,14 @@ class DboSourceTest extends CakeTestCase {
$this->db->query('SELECT 1');
$this->db->query('SELECT 1');
$this->db->query('SELECT 2');
$this->assertAttributeCount(2, '_queryCache', $this->db);
$property = new ReflectionProperty($this->db, '_queryCache');
$property->setAccessible(true);
$this->assertCount(2, $property->getValue($this->db));
$this->db->flushQueryCache();
$this->assertAttributeCount(0, '_queryCache', $this->db);
$this->assertCount(0, $property->getValue($this->db));
}
/**

View file

@ -8765,11 +8765,15 @@ class FormHelperTest extends CakeTestCase {
$this->assertEquals(array('Post.title'), $this->Form->fields);
$this->assertStringContainsString($hash, $result, 'Should contain the correct hash.');
$this->assertAttributeEquals(
$property = new ReflectionProperty($this->Form, '_lastAction');
$property->setAccessible(true);
$this->assertSame(
'/basedir/posts/add',
'_lastAction',
$this->Form,
'lastAction was should be restored.');
$property->getValue($this->Form),
'lastAction was should be restored.'
);
}
/**
@ -11188,7 +11192,10 @@ class FormHelperTest extends CakeTestCase {
$this->Form->request->here = $here;
$this->Form->create('User');
$this->assertAttributeEquals($here, '_lastAction', $this->Form, "_lastAction shouldn't be empty.");
$property = new ReflectionProperty($this->Form, '_lastAction');
$property->setAccessible(true);
$this->assertSame($here, $property->getValue($this->Form), "_lastAction shouldn't be empty.");
}
/**
@ -11204,7 +11211,10 @@ class FormHelperTest extends CakeTestCase {
$this->Form->request->here = $here;
$this->Form->create('User');
$this->assertAttributeEquals($here, '_lastAction', $this->Form, "_lastAction shouldn't be empty.");
$property = new ReflectionProperty($this->Form, '_lastAction');
$property->setAccessible(true);
$this->assertSame($here, $property->getValue($this->Form), "_lastAction shouldn't be empty.");
}
/**