Skip to content

Commit

Permalink
reflection: setAccessible nicht mehr aufrufen (#5484)
Browse files Browse the repository at this point in the history
Da seit PHP 8.1 nicht mehr notwendig.
  • Loading branch information
gharlan committed Jan 4, 2023
1 parent eb02de5 commit c3975eb
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .tools/phpstan/baseline.neon
Expand Up @@ -2306,7 +2306,7 @@ parameters:
path: ../../redaxo/src/addons/structure/tests/article_test.php

-
message: "#^Method class@anonymous/addons/structure/tests/category_test\\.php\\:179\\:\\:__construct\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
message: "#^Method class@anonymous/addons/structure/tests/category_test\\.php\\:177\\:\\:__construct\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
count: 1
path: ../../redaxo/src/addons/structure/tests/category_test.php

Expand Down Expand Up @@ -2366,7 +2366,7 @@ parameters:
path: ../../redaxo/src/addons/structure/tests/category_test.php

-
message: "#^Property class@anonymous/addons/structure/tests/category_test\\.php\\:179\\:\\:\\$parent has no type specified\\.$#"
message: "#^Property class@anonymous/addons/structure/tests/category_test\\.php\\:177\\:\\:\\$parent has no type specified\\.$#"
count: 1
path: ../../redaxo/src/addons/structure/tests/category_test.php

Expand Down
Expand Up @@ -18,7 +18,6 @@ public function testGetCacheFilename()
$media->setMediaPath(__DIR__.'/bar.gif');

$property = new ReflectionProperty(rex_media_manager::class, 'type');
$property->setAccessible(true);
$property->setValue($manager, 'test');

static::assertSame($cachePath.'test/foo.jpg', $manager->getCacheFilename());
Expand Down
Expand Up @@ -13,7 +13,6 @@ public function testHasValue()

// fake meta field in database structure
$propArticle = new ReflectionProperty(rex_article_content_base::class, 'ARTICLE');
$propArticle->setAccessible(true);
$propArticle->setValue($instance, rex_sql::factory()->setValue('art_foo', 'teststring'));

static::assertTrue($instance->hasValue('foo'));
Expand All @@ -29,7 +28,6 @@ public function testGetValue()

// fake meta field in database structure
$propArticle = new ReflectionProperty(rex_article_content_base::class, 'ARTICLE');
$propArticle->setAccessible(true);
$propArticle->setValue($instance, rex_sql::factory()->setValue('art_foo', 'teststring'));

static::assertEquals('teststring', $instance->getValue('foo'));
Expand Down
Expand Up @@ -37,7 +37,6 @@ protected function setUp(): void
rex_article::getClassVars();
$class = new ReflectionClass(rex_article::class);
$classVarsProperty = $class->getProperty('classVars');
$classVarsProperty->setAccessible(true);
$classVarsProperty->setValue(
array_merge(
$classVarsProperty->getValue(),
Expand All @@ -58,7 +57,6 @@ protected function tearDown(): void
// reset static properties
$class = new ReflectionClass(rex_article::class);
$classVarsProperty = $class->getProperty('classVars');
$classVarsProperty->setAccessible(true);
$classVarsProperty->setValue(null);

rex_article::clearInstancePool();
Expand All @@ -69,12 +67,10 @@ public function testBcHasValue()
$instance = new rex_article_content(1, 1);

$viaSql = new ReflectionProperty(rex_article_content::class, 'viasql');
$viaSql->setAccessible(true);
$viaSql->setValue($instance, true);

// fake meta field in database structure
$propArticle = new ReflectionProperty(rex_article_content_base::class, 'ARTICLE');
$propArticle->setAccessible(true);
$propArticle->setValue($instance, rex_sql::factory()->setValue('art_foo', 'teststring'));

static::assertTrue($instance->hasValue('foo'));
Expand All @@ -89,12 +85,10 @@ public function testBcGetValue()
$instance = new rex_article_content(1, 1);

$viaSql = new ReflectionProperty(rex_article_content::class, 'viasql');
$viaSql->setAccessible(true);
$viaSql->setValue($instance, true);

// fake meta field in database structure
$propArticle = new ReflectionProperty(rex_article_content_base::class, 'ARTICLE');
$propArticle->setAccessible(true);
$propArticle->setValue($instance, rex_sql::factory()->setValue('art_foo', 'teststring'));

static::assertEquals('teststring', $instance->getValue('foo'));
Expand All @@ -107,7 +101,6 @@ public function testBcGetValueNonExisting(string $value): void
$instance = new rex_article_content(1, 1);

$viaSql = new ReflectionProperty(rex_article_content::class, 'viasql');
$viaSql->setAccessible(true);
$viaSql->setValue($instance, true);

$this->expectException(rex_exception::class);
Expand Down
2 changes: 0 additions & 2 deletions redaxo/src/addons/structure/tests/article_test.php
Expand Up @@ -13,7 +13,6 @@ protected function setUp(): void
rex_article::getClassVars();
$class = new ReflectionClass(rex_article::class);
$classVarsProperty = $class->getProperty('classVars');
$classVarsProperty->setAccessible(true);
$classVarsProperty->setValue(
array_merge(
$classVarsProperty->getValue(),
Expand All @@ -27,7 +26,6 @@ protected function tearDown(): void
// reset static properties
$class = new ReflectionClass(rex_article::class);
$classVarsProperty = $class->getProperty('classVars');
$classVarsProperty->setAccessible(true);
$classVarsProperty->setValue(null);

rex_article::clearInstancePool();
Expand Down
2 changes: 0 additions & 2 deletions redaxo/src/addons/structure/tests/category_test.php
Expand Up @@ -13,7 +13,6 @@ protected function setUp(): void
rex_category::getClassVars();
$class = new ReflectionClass(rex_category::class);
$classVarsProperty = $class->getProperty('classVars');
$classVarsProperty->setAccessible(true);
$classVarsProperty->setValue(
array_merge(
$classVarsProperty->getValue(),
Expand All @@ -27,7 +26,6 @@ protected function tearDown(): void
// reset static properties
$class = new ReflectionClass(rex_article::class);
$classVarsProperty = $class->getProperty('classVars');
$classVarsProperty->setAccessible(true);
$classVarsProperty->setValue(null);

rex_category::clearInstancePool();
Expand Down
2 changes: 0 additions & 2 deletions redaxo/src/core/tests/console/command_test.php
Expand Up @@ -10,7 +10,6 @@ class rex_console_command_test extends TestCase
public function testDecodeMessage()
{
$method = new ReflectionMethod(rex_console_command::class, 'decodeMessage');
$method->setAccessible(true);

$command = $this->getMockForAbstractClass(rex_console_command::class);

Expand All @@ -20,7 +19,6 @@ public function testDecodeMessage()
public function testDecodeMessageSingleQuotes()
{
$method = new ReflectionMethod(rex_console_command::class, 'decodeMessage');
$method->setAccessible(true);

$command = $this->getMockForAbstractClass(rex_console_command::class);

Expand Down
1 change: 0 additions & 1 deletion redaxo/src/core/tests/list_test.php
Expand Up @@ -10,7 +10,6 @@ class rex_list_test extends TestCase
public function testPrepareCountQuery(): void
{
$method = new ReflectionMethod(rex_list::class, 'prepareCountQuery');
$method->setAccessible(true);

$query = 'SELECT *, IF(foo = 1, 0, (SELECT x FROM bar)) as qux FROM foo ORDER qux';
$expected = 'SELECT COUNT(*) AS `rows` FROM (SELECT *, IF(foo = 1, 0, (SELECT x FROM bar)) as qux FROM foo ORDER qux) t';
Expand Down
1 change: 0 additions & 1 deletion redaxo/src/core/tests/login/password_policy_test.php
Expand Up @@ -54,7 +54,6 @@ public function provideCheck()
public function testGetRule(): void
{
$getRule = new ReflectionMethod(rex_password_policy::class, 'getRule');
$getRule->setAccessible(true);

$policy = new rex_password_policy(['length' => ['min' => 5, 'max' => 25]]);
$rule = $getRule->invoke($policy);
Expand Down
1 change: 0 additions & 1 deletion redaxo/src/core/tests/sql/sql_select_test.php
Expand Up @@ -274,7 +274,6 @@ public function testUnbufferedQuery()

// get DB 1 PDO object
$property = new ReflectionProperty(rex_sql::class, 'pdo');
$property->setAccessible(true);
/** @var PDO $pdo */
$pdo = $property->getValue()[1];

Expand Down
4 changes: 0 additions & 4 deletions redaxo/src/core/tests/util/socket_test.php
Expand Up @@ -58,9 +58,7 @@ public function testWriteRequest($socket)
{
$class = new ReflectionClass(rex_socket::class);
$property = $class->getProperty('stream');
$property->setAccessible(true);
$method = $class->getMethod('writeRequest');
$method->setAccessible(true);

$stream = fopen('php://temp', 'r+');
$property->setValue($socket, $stream);
Expand Down Expand Up @@ -103,7 +101,6 @@ public function parseUrlProvider()
public function testParseUrl($url, $expectedHost, $expectedPort, $expectedSsl, $expectedPath)
{
$method = new ReflectionMethod(rex_socket::class, 'parseUrl');
$method->setAccessible(true);
$result = $method->invoke(null, $url);
$expected = [
'host' => $expectedHost,
Expand Down Expand Up @@ -131,7 +128,6 @@ public function testParseUrlException($url)
$this->expectException(rex_socket_exception::class);

$method = new ReflectionMethod(rex_socket::class, 'parseUrl');
$method->setAccessible(true);
$method->invoke(null, $url);
}
}
1 change: 0 additions & 1 deletion redaxo/src/core/tests/util/stream_test.php
Expand Up @@ -21,7 +21,6 @@ public function testStreamInclude()
public function testStreamIncludeWithRealFile()
{
$property = new ReflectionProperty(rex_stream::class, 'useRealFiles');
$property->setAccessible(true);
$property->setValue(true);

$content = 'foo <?php echo "bar";';
Expand Down

0 comments on commit c3975eb

Please sign in to comment.