Merge pull request #12711 from nupplaphil/bug/config_toString

Config Fixings & Dice update
This commit is contained in:
Hypolite Petovan 2023-01-21 14:25:01 -05:00 committed by GitHub
commit 9ff3aca3b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 106 additions and 126 deletions

View file

@ -28,7 +28,6 @@
"ext-xml": "*", "ext-xml": "*",
"asika/simple-console": "^1.0", "asika/simple-console": "^1.0",
"bacon/bacon-qr-code": "^2.0.0", "bacon/bacon-qr-code": "^2.0.0",
"cweagans/composer-patches": "^1.7",
"divineomega/password_exposed": "^2.8", "divineomega/password_exposed": "^2.8",
"ezyang/htmlpurifier": "^4.7", "ezyang/htmlpurifier": "^4.7",
"friendica/json-ld": "^1.0", "friendica/json-ld": "^1.0",
@ -127,8 +126,7 @@
"mockery/mockery": "^1.3", "mockery/mockery": "^1.3",
"mikey179/vfsstream": "^1.6", "mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^9", "phpunit/phpunit": "^9",
"dms/phpunit-arraysubset-asserts": "^0.3.1", "dms/phpunit-arraysubset-asserts": "^0.3.1"
"symplify/vendor-patches": "11.2.0.72"
}, },
"scripts": { "scripts": {
"test": "phpunit", "test": "phpunit",
@ -136,12 +134,5 @@
"cs:install": "@composer install --working-dir=bin/dev/php-cs-fixer", "cs:install": "@composer install --working-dir=bin/dev/php-cs-fixer",
"cs:check": ["@cs:install", "bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"], "cs:check": ["@cs:install", "bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"],
"cs:fix": ["@cs:install", "bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix"] "cs:fix": ["@cs:install", "bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix"]
},
"extra": {
"patches": {
"level-2/dice": [
"mods/patches/level-2-dice-dice-php.patch"
]
}
} }
} }

104
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "0bbc4011b7628c0d563f80f361e98cdd", "content-hash": "5af9ac9003f4653f3aa1860dd5a4d821",
"packages": [ "packages": [
{ {
"name": "asika/simple-console", "name": "asika/simple-console",
@ -368,50 +368,6 @@
], ],
"time": "2022-07-20T07:14:26+00:00" "time": "2022-07-20T07:14:26+00:00"
}, },
{
"name": "cweagans/composer-patches",
"version": "1.7.3",
"source": {
"type": "git",
"url": "https://github.com/cweagans/composer-patches.git",
"reference": "e190d4466fe2b103a55467dfa83fc2fecfcaf2db"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/cweagans/composer-patches/zipball/e190d4466fe2b103a55467dfa83fc2fecfcaf2db",
"reference": "e190d4466fe2b103a55467dfa83fc2fecfcaf2db",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0 || ^2.0",
"php": ">=5.3.0"
},
"require-dev": {
"composer/composer": "~1.0 || ~2.0",
"phpunit/phpunit": "~4.6"
},
"type": "composer-plugin",
"extra": {
"class": "cweagans\\Composer\\Patches"
},
"autoload": {
"psr-4": {
"cweagans\\Composer\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Cameron Eagans",
"email": "me@cweagans.net"
}
],
"description": "Provides a way to patch Composer packages.",
"time": "2022-12-20T22:53:13+00:00"
},
{ {
"name": "dasprid/enum", "name": "dasprid/enum",
"version": "1.0.3", "version": "1.0.3",
@ -1289,16 +1245,16 @@
}, },
{ {
"name": "level-2/dice", "name": "level-2/dice",
"version": "4.0.3", "version": "4.0.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Level-2/Dice.git", "url": "https://github.com/Level-2/Dice.git",
"reference": "3e9a8548398c01e2527110c916a93f6efa17ac9c" "reference": "e04c98d96bcc932a917b2b7e7944887e4839056a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Level-2/Dice/zipball/3e9a8548398c01e2527110c916a93f6efa17ac9c", "url": "https://api.github.com/repos/Level-2/Dice/zipball/e04c98d96bcc932a917b2b7e7944887e4839056a",
"reference": "3e9a8548398c01e2527110c916a93f6efa17ac9c", "reference": "e04c98d96bcc932a917b2b7e7944887e4839056a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1309,9 +1265,7 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"patches_applied": [ "patches_applied": []
"mods/patches/level-2-dice-dice-php.patch"
]
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -1336,7 +1290,7 @@
"di", "di",
"ioc" "ioc"
], ],
"time": "2021-04-20T14:06:06+00:00" "time": "2022-03-28T21:20:23+00:00"
}, },
{ {
"name": "lightopenid/lightopenid", "name": "lightopenid/lightopenid",
@ -6418,50 +6372,6 @@
], ],
"time": "2020-09-28T06:39:44+00:00" "time": "2020-09-28T06:39:44+00:00"
}, },
{
"name": "symplify/vendor-patches",
"version": "11.2.0.72",
"source": {
"type": "git",
"url": "https://github.com/symplify/vendor-patches.git",
"reference": "83204e1a7a33ca958f9d1cc9c3b1b25f75270775"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symplify/vendor-patches/zipball/83204e1a7a33ca958f9d1cc9c3b1b25f75270775",
"reference": "83204e1a7a33ca958f9d1cc9c3b1b25f75270775",
"shasum": ""
},
"require": {
"cweagans/composer-patches": "^1.7",
"php": ">=7.2"
},
"bin": [
"bin/vendor-patches"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "10.3-dev"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Generate vendor patches for packages with single command",
"funding": [
{
"url": "https://www.paypal.me/rectorphp",
"type": "custom"
},
{
"url": "https://github.com/tomasvotruba",
"type": "github"
}
],
"time": "2023-01-11T09:41:31+00:00"
},
{ {
"name": "theseer/tokenizer", "name": "theseer/tokenizer",
"version": "1.2.1", "version": "1.2.1",

View file

@ -1,10 +0,0 @@
--- /dev/null
+++ ../Dice.php
@@ -257,6 +257,7 @@
for ($i = 0; $i < count($args); $i++) {
if (call_user_func('is_' . $param->getType()->getName(), $args[$i])) {
$parameters[] = array_splice($args, $i, 1)[0];
+ break;
}
}
}

View file

@ -214,6 +214,17 @@ class ConfigFileTransformer
case "NULL": case "NULL":
return "null"; return "null";
case "object": case "object":
if (method_exists($value, '__toString')) {
return sprintf('\'%s\'', $value);
} elseif ($value instanceof \Serializable) {
try {
return $value->serialize();
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('Cannot serialize %s.', gettype($value)), $e);
}
} else {
throw new \InvalidArgumentException(sprintf('%s is an object without stringify.', gettype($value)));
}
case "resource": case "resource":
case "resource (closed)": case "resource (closed)":
throw new \InvalidArgumentException(sprintf('%s in configs are not supported yet.', gettype($value))); throw new \InvalidArgumentException(sprintf('%s in configs are not supported yet.', gettype($value)));

View file

@ -783,7 +783,7 @@ class DBStructure
} }
if (!DBA::exists('verb', ['id' => 0])) { if (!DBA::exists('verb', ['id' => 0])) {
DBA::insert('verb', ['name' => '']); DBA::insert('verb', ['name' => ''], Database::INSERT_IGNORE);
$lastid = DBA::lastInsertId(); $lastid = DBA::lastInsertId();
if ($lastid != 0) { if ($lastid != 0) {
DBA::update('verb', ['id' => 0], ['id' => $lastid]); DBA::update('verb', ['id' => 0], ['id' => $lastid]);
@ -819,7 +819,7 @@ class DBStructure
} }
if (self::existsTable('contact') && !DBA::exists('contact', ['id' => 0])) { if (self::existsTable('contact') && !DBA::exists('contact', ['id' => 0])) {
DBA::insert('contact', ['nurl' => '']); DBA::insert('contact', ['nurl' => ''], Database::INSERT_IGNORE);
$lastid = DBA::lastInsertId(); $lastid = DBA::lastInsertId();
if ($lastid != 0) { if ($lastid != 0) {
DBA::update('contact', ['id' => 0], ['id' => $lastid]); DBA::update('contact', ['id' => 0], ['id' => $lastid]);
@ -834,7 +834,7 @@ class DBStructure
} }
if (self::existsTable('tag') && !DBA::exists('tag', ['id' => 0])) { if (self::existsTable('tag') && !DBA::exists('tag', ['id' => 0])) {
DBA::insert('tag', ['name' => '']); DBA::insert('tag', ['name' => ''], Database::INSERT_IGNORE);
$lastid = DBA::lastInsertId(); $lastid = DBA::lastInsertId();
if ($lastid != 0) { if ($lastid != 0) {
DBA::update('tag', ['id' => 0], ['id' => $lastid]); DBA::update('tag', ['id' => 0], ['id' => $lastid]);
@ -850,7 +850,7 @@ class DBStructure
if (self::existsTable('permissionset')) { if (self::existsTable('permissionset')) {
if (!DBA::exists('permissionset', ['id' => 0])) { if (!DBA::exists('permissionset', ['id' => 0])) {
DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']); DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''], Database::INSERT_IGNORE);
$lastid = DBA::lastInsertId(); $lastid = DBA::lastInsertId();
if ($lastid != 0) { if ($lastid != 0) {
DBA::update('permissionset', ['id' => 0], ['id' => $lastid]); DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
@ -878,7 +878,7 @@ class DBStructure
} }
$fields = ['id' => $set['psid'], 'uid' => $set['uid'], 'allow_cid' => $permission, $fields = ['id' => $set['psid'], 'uid' => $set['uid'], 'allow_cid' => $permission,
'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']; 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''];
DBA::insert('permissionset', $fields); DBA::insert('permissionset', $fields, Database::INSERT_IGNORE);
} }
DBA::close($sets); DBA::close($sets);
} }

View file

@ -0,0 +1,35 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Test\Util;
class SerializableObjectDouble implements \Serializable
{
public function serialize()
{
return '\'serialized\'';
}
public function unserialize($data)
{
return '\'unserialized\'';
}
}

View file

@ -0,0 +1,11 @@
<?php
use Friendica\Test\Util\SerializableObjectDouble;
use ParagonIE\HiddenString\HiddenString;
return [
'object' => [
'toString' => new HiddenString('test'),
'serializable' => new SerializableObjectDouble(),
],
];

View file

@ -23,6 +23,9 @@ namespace Friendica\Test\src\Core\Config\Util;
use Friendica\Core\Config\Util\ConfigFileTransformer; use Friendica\Core\Config\Util\ConfigFileTransformer;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Friendica\Test\Util\SerializableObjectDouble;
use ParagonIE\HiddenString\HiddenString;
use function PHPUnit\Framework\assertEquals;
class ConfigFileTransformerTest extends MockedTest class ConfigFileTransformerTest extends MockedTest
{ {
@ -45,9 +48,34 @@ class ConfigFileTransformerTest extends MockedTest
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/object.node.config.php'), 'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/object.node.config.php'),
'assertException' => true, 'assertException' => true,
], ],
'ressource_invalid' => [ 'resource' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/ressource.node.config.php'), 'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/ressource.node.config.php'),
'assertException' => true, 'assertException' => false,
'assertion' => <<<EOF
<?php
return [
'ressource' => [
'ressources_not_allowed' => '',
],
];
EOF,
],
'object_valid' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/object_valid.node.config.php'),
'assertException' => false,
'assertion' => <<<EOF
<?php
return [
'object' => [
'toString' => 'test',
'serializable' => 'serialized',
],
];
EOF,
], ],
'test_types' => [ 'test_types' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/types.node.config.php'), 'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/types.node.config.php'),
@ -63,7 +91,7 @@ class ConfigFileTransformerTest extends MockedTest
* *
* @dataProvider dataTests * @dataProvider dataTests
*/ */
public function testConfigFile(string $configFile, bool $assertException = false) public function testConfigFile(string $configFile, bool $assertException = false, $assertion = null)
{ {
$dataArray = include $configFile; $dataArray = include $configFile;
@ -73,6 +101,10 @@ class ConfigFileTransformerTest extends MockedTest
$newConfig = ConfigFileTransformer::encode($dataArray); $newConfig = ConfigFileTransformer::encode($dataArray);
self::assertEquals(file_get_contents($configFile), $newConfig); if (empty($assertion)) {
self::assertEquals(file_get_contents($configFile), $newConfig);
} else {
self::assertEquals($assertion, $newConfig);
}
} }
} }