From a156f8f5ad2e75d497f3d84e5952f82302d2b8f2 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 19 Nov 2024 06:36:16 +0100 Subject: [PATCH 1/3] [DDEV] Support for `xhprof`/`xhgui` (#4325) * ddev: support for xhprof/xhgui * gitignore * gitignore [skip ci] * gitignore [skip ci] --- .gitignore | 8 +++++- .phpunit.dist.xml | 4 +++ composer.json | 1 + composer.lock | 66 +++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b1989d41de3..1b0765574d9 100644 --- a/.gitignore +++ b/.gitignore @@ -95,5 +95,11 @@ phpunit.xml /site # DDEV -.ddev/config.yaml .ddev/.sampleData +.ddev/config.yaml +.ddev/config.*.yaml +.ddev/xhgui +.ddev/xhprof +.ddev/docker-compose.xhgui.yaml +.ddev/docker-compose.xhgui_norouter.yaml +app/etc/includes/ddev.xhgui.php diff --git a/.phpunit.dist.xml b/.phpunit.dist.xml index 306b6bcc934..fad1f954416 100644 --- a/.phpunit.dist.xml +++ b/.phpunit.dist.xml @@ -13,6 +13,10 @@ stopOnFailure="false" bootstrap="tests/bootstrap.php" > + + + + tests/unit/Base diff --git a/composer.json b/composer.json index ecfc8eb1fb7..ae809716380 100644 --- a/composer.json +++ b/composer.json @@ -48,6 +48,7 @@ "macopedia/phpstan-magento1": "^1.0.5", "magento-ecg/coding-standard": "^4.5", "openmage/dev-meta-package": "^1.0", + "perftools/php-profiler": "^1.1", "phpcompatibility/php-compatibility": "^9.3", "phpmd/phpmd": "^2.13", "phpstan/phpstan": "^1.12.1", diff --git a/composer.lock b/composer.lock index e55ceabe1b5..0ad9675ad23 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d9a600770935f43ce6b2a1a5bf3fbafb", + "content-hash": "20dea09b6c23e6bf8c43a8f30690e984", "packages": [ { "name": "colinmollenhour/cache-backend-redis", @@ -3800,6 +3800,68 @@ ], "time": "2023-12-17T18:09:59+00:00" }, + { + "name": "perftools/php-profiler", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/perftools/php-profiler.git", + "reference": "b5051e96679aa0d6cb3afe9a13a4e6a1fd890fea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/perftools/php-profiler/zipball/b5051e96679aa0d6cb3afe9a13a4e6a1fd890fea", + "reference": "b5051e96679aa0d6cb3afe9a13a4e6a1fd890fea", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^5.3.0 || ^7.0 || ^8.0" + }, + "conflict": { + "perftools/xhgui-collector": "<1.8" + }, + "require-dev": { + "alcaeus/mongo-php-adapter": "^1.1", + "perftools/xhgui-collector": "^1.8" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "Adapter to provide ext-mongo interface on top of mongo-php-library (PHP>=5.6)", + "ext-curl": "cURL extension for upload saver", + "ext-mongo": "mongo extension (PHP>=5.3,<7.0)", + "ext-mongodb": "mongodb extension (PHP>=5.4)", + "ext-tideways": "Use tideways to profile", + "ext-uprofiler": "Use uprofiler to profile", + "ext-xhprof": "Use xhprof to profile", + "perftools/xhgui-collector": "For mongodb or pdo savers" + }, + "type": "library", + "autoload": { + "psr-4": { + "Xhgui\\Profiler\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Lauri Piisang", + "email": "lauri.piisang@eesti.ee" + }, + { + "name": "Elan Ruusamäe", + "email": "glen@pld-linux.org" + } + ], + "description": "PHP Profiling based on XHGui", + "support": { + "issues": "https://github.com/perftools/php-profiler/issues", + "source": "https://github.com/perftools/php-profiler/tree/1.1.2" + }, + "time": "2024-04-16T05:42:45+00:00" + }, { "name": "phar-io/manifest", "version": "2.0.4", @@ -7199,7 +7261,7 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { From 8033a6e9cd0236b7c7b6386696f11f24b5244f11 Mon Sep 17 00:00:00 2001 From: Ng Kiat Siong Date: Fri, 22 Nov 2024 21:28:28 +0800 Subject: [PATCH 2/3] Fixed null deprecation in Varien/Convert/Parser/Xml/Excel (#4375) --- lib/Varien/Convert/Parser/Xml/Excel.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Varien/Convert/Parser/Xml/Excel.php b/lib/Varien/Convert/Parser/Xml/Excel.php index 5fa94863736..764fde6305a 100644 --- a/lib/Varien/Convert/Parser/Xml/Excel.php +++ b/lib/Varien/Convert/Parser/Xml/Excel.php @@ -36,17 +36,19 @@ public function parse() $dom->loadXML($this->getData()); $worksheets = $dom->getElementsByTagName('Worksheet'); - + /** @var DOMElement $worksheet */ foreach ($worksheets as $worksheet) { $wsName = $worksheet->getAttribute('ss:Name'); $rows = $worksheet->getElementsByTagName('Row'); $firstRow = true; $fieldNames = []; $wsData = []; + /** @var DOMElement $row */ foreach ($rows as $row) { $index = 1; $cells = $row->getElementsByTagName('Cell'); $rowData = []; + /** @var DOMElement $cell */ foreach ($cells as $cell) { $value = $cell->getElementsByTagName('Data')->item(0)->nodeValue; $ind = $cell->getAttribute('ss:Index'); @@ -195,7 +197,7 @@ public function getRowXml(array $row) $xmlData = []; $xmlData[] = ''; foreach ($row as $value) { - $this->_xmlElement->row = htmlspecialchars($value); + $this->_xmlElement->row = htmlspecialchars((string) $value); $value = str_replace($xmlHeader, '', $this->_xmlElement->asXML()); $value = preg_replace($xmlRegexp, '\\1', $value); $dataType = 'String'; From 11db60758fa964faeabcf02ad722806922a2af8d Mon Sep 17 00:00:00 2001 From: Ng Kiat Siong Date: Sat, 23 Nov 2024 06:14:06 +0800 Subject: [PATCH 3/3] Fixed null deprecation in `Mage_Catalog_Model_Product_Option_Type_Text::validateUserValue()` (#4357) * Fixed null deprecation in Mage/Catalog/Model/Product/Option/Type/Text * Added test * Added method * Changed at source. * Fix bug on array to string conversion on date input type. * Revert eveything. --------- Co-authored-by: Sven Reichel --- .../Model/Product/Option/Type/Text.php | 7 +- .../Model/Product/Option/Type/TextTest.php | 81 +++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php index 442d112c0fa..42e3ca64fa7 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php @@ -21,12 +21,17 @@ */ class Mage_Catalog_Model_Product_Option_Type_Text extends Mage_Catalog_Model_Product_Option_Type_Default { + public function getUserValue(): string + { + return (string) $this->getDataByKey('user_value'); + } + /** * Validate user input for option * * @throws Mage_Core_Exception * @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...) - * @return Mage_Catalog_Model_Product_Option_Type_Default + * @return $this */ public function validateUserValue($values) { diff --git a/tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php b/tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php new file mode 100644 index 00000000000..313cf47fafe --- /dev/null +++ b/tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php @@ -0,0 +1,81 @@ +subject = Mage::getModel('catalog/product_option_type_text'); + } + + /** + * @group Mage_Catalog + * @group Mage_Catalog_Model + * @group runInSeparateProcess + * @runInSeparateProcess + */ + public function testValidateUserValue(): void + { + $this->subject->setOption(new Mage_Catalog_Model_Product_Option()); + $this->assertInstanceOf(Subject::class, $this->subject->validateUserValue([])); + } + + + /** + * @dataProvider providePrepareForCart + * @group Mage_Catalog + * @group Mage_Catalog_Model + */ + public function testPrepareForCart($expectedResult, bool $setIsValid = true, $setUserValue = null): void + { + $this->subject->setIsValid($setIsValid)->setUserValue($setUserValue); + $this->assertSame($expectedResult, $this->subject->prepareForCart()); + } + + public function providePrepareForCart(): Generator + { + yield 'valid' => [ + 'test', + true, + 'test', + ]; + yield 'invalid' => [ + null, + ]; + } + + /** + * @covers Mage_Catalog_Model_Product_Option_Type_Text::getFormattedOptionValue() + * @group Mage_Catalog + * @group Mage_Catalog_Model + */ + public function testGetDefaultAttributeSetId(): void + { + $this->assertIsString($this->subject->getFormattedOptionValue('')); + } +}