From 81a85bd95302fd13022875bf717654db2537ba13 Mon Sep 17 00:00:00 2001 From: Tacxticx88 <12997062+tacxticx88@users.noreply.github.com> Date: Fri, 21 Aug 2020 09:43:19 +0200 Subject: [PATCH 1/5] Fix assign method to use correctly property and method name --- composer.lock | 698 ++++++++---------- src/Mvc/Collection.php | 8 +- .../_data/fixtures/Mvc/Collections/Robots.php | 2 +- tests/integration/Collection/AssignCest.php | 76 ++ 4 files changed, 386 insertions(+), 398 deletions(-) create mode 100644 tests/integration/Collection/AssignCest.php diff --git a/composer.lock b/composer.lock index 5478293..5f8b64c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,170 +4,21 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "235c15717e4e0e3c22a04978ad78fa48", - "packages": [ - { - "name": "symfony/polyfill-ctype", - "version": "v1.17.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", - "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.17-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-06-06T08:46:27+00:00" - }, - { - "name": "vlucas/phpdotenv", - "version": "v2.6.5", - "source": { - "type": "git", - "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "2e977311ffb17b2f82028a9c36824647789c6365" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/2e977311ffb17b2f82028a9c36824647789c6365", - "reference": "2e977311ffb17b2f82028a9c36824647789c6365", - "shasum": "" - }, - "require": { - "php": "^5.3.9 || ^7.0 || ^8.0", - "symfony/polyfill-ctype": "^1.16" - }, - "require-dev": { - "ext-filter": "*", - "ext-pcre": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7.27" - }, - "suggest": { - "ext-filter": "Required to use the boolean validator.", - "ext-pcre": "Required to use most of the library." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev" - } - }, - "autoload": { - "psr-4": { - "Dotenv\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "graham@alt-three.com", - "homepage": "https://gjcampbell.co.uk/" - }, - { - "name": "Vance Lucas", - "email": "vance@vancelucas.com", - "homepage": "https://vancelucas.com/" - } - ], - "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", - "keywords": [ - "dotenv", - "env", - "environment" - ], - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", - "type": "tidelift" - } - ], - "time": "2020-06-02T14:06:52+00:00" - } - ], + "content-hash": "790177276900adb9f9d287e0af6c8509", + "packages": [], "packages-dev": [ { "name": "amphp/amp", - "version": "v2.4.4", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/amphp/amp.git", - "reference": "1e58d53e4af390efc7813e36cd215bd82cba4b06" + "reference": "f220a51458bf4dd0dedebb171ac3457813c72bbc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/amp/zipball/1e58d53e4af390efc7813e36cd215bd82cba4b06", - "reference": "1e58d53e4af390efc7813e36cd215bd82cba4b06", + "url": "https://api.github.com/repos/amphp/amp/zipball/f220a51458bf4dd0dedebb171ac3457813c72bbc", + "reference": "f220a51458bf4dd0dedebb171ac3457813c72bbc", "shasum": "" }, "require": { @@ -179,8 +30,8 @@ "ext-json": "*", "jetbrains/phpstorm-stubs": "^2019.3", "phpunit/phpunit": "^6.0.9 | ^7", - "react/promise": "^2", - "vimeo/psalm": "^3.11@dev" + "psalm/phar": "^3.11@dev", + "react/promise": "^2" }, "type": "library", "extra": { @@ -232,32 +83,39 @@ "non-blocking", "promise" ], - "time": "2020-04-30T04:54:50+00:00" + "funding": [ + { + "url": "https://github.com/amphp", + "type": "github" + } + ], + "time": "2020-07-14T21:47:18+00:00" }, { "name": "amphp/byte-stream", - "version": "v1.7.3", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/amphp/byte-stream.git", - "reference": "b867505edb79dda8f253ca3c3a2bbadae4b16592" + "reference": "f0c20cf598a958ba2aa8c6e5a71c697d652c7088" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/byte-stream/zipball/b867505edb79dda8f253ca3c3a2bbadae4b16592", - "reference": "b867505edb79dda8f253ca3c3a2bbadae4b16592", + "url": "https://api.github.com/repos/amphp/byte-stream/zipball/f0c20cf598a958ba2aa8c6e5a71c697d652c7088", + "reference": "f0c20cf598a958ba2aa8c6e5a71c697d652c7088", "shasum": "" }, "require": { - "amphp/amp": "^2" + "amphp/amp": "^2", + "php": ">=7.1" }, "require-dev": { "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1", + "amphp/phpunit-util": "^1.4", "friendsofphp/php-cs-fixer": "^2.3", "jetbrains/phpstorm-stubs": "^2019.3", "phpunit/phpunit": "^6 || ^7 || ^8", - "vimeo/psalm": "^3.9@dev" + "psalm/phar": "^3.11.4" }, "type": "library", "extra": { @@ -297,7 +155,7 @@ "non-blocking", "stream" ], - "time": "2020-04-04T16:56:54+00:00" + "time": "2020-06-29T18:35:05+00:00" }, { "name": "behat/gherkin", @@ -592,16 +450,16 @@ }, { "name": "codeception/stub", - "version": "3.6.1", + "version": "3.7.0", "source": { "type": "git", "url": "https://github.com/Codeception/Stub.git", - "reference": "a3ba01414cbee76a1bced9f9b6b169cc8d203880" + "reference": "468dd5fe659f131fc997f5196aad87512f9b1304" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeception/Stub/zipball/a3ba01414cbee76a1bced9f9b6b169cc8d203880", - "reference": "a3ba01414cbee76a1bced9f9b6b169cc8d203880", + "url": "https://api.github.com/repos/Codeception/Stub/zipball/468dd5fe659f131fc997f5196aad87512f9b1304", + "reference": "468dd5fe659f131fc997f5196aad87512f9b1304", "shasum": "" }, "require": { @@ -618,20 +476,20 @@ "MIT" ], "description": "Flexible Stub wrapper for PHPUnit's Mock Builder", - "time": "2020-02-07T18:42:28+00:00" + "time": "2020-07-03T15:54:43+00:00" }, { "name": "composer/xdebug-handler", - "version": "1.4.2", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "fa2aaf99e2087f013a14f7432c1cd2dd7d8f1f51" + "reference": "ebd27a9866ae8254e873866f795491f02418c5a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/fa2aaf99e2087f013a14f7432c1cd2dd7d8f1f51", - "reference": "fa2aaf99e2087f013a14f7432c1cd2dd7d8f1f51", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ebd27a9866ae8254e873866f795491f02418c5a5", + "reference": "ebd27a9866ae8254e873866f795491f02418c5a5", "shasum": "" }, "require": { @@ -676,7 +534,7 @@ "type": "tidelift" } ], - "time": "2020-06-04T11:16:35+00:00" + "time": "2020-08-19T10:27:58+00:00" }, { "name": "doctrine/instantiator", @@ -836,68 +694,6 @@ ], "time": "2019-06-23T21:03:50+00:00" }, - { - "name": "graham-campbell/result-type", - "version": "v1.0.1", - "source": { - "type": "git", - "url": "https://github.com/GrahamCampbell/Result-Type.git", - "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/7e279d2cd5d7fbb156ce46daada972355cea27bb", - "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb", - "shasum": "" - }, - "require": { - "php": "^7.0|^8.0", - "phpoption/phpoption": "^1.7.3" - }, - "require-dev": { - "phpunit/phpunit": "^6.5|^7.5|^8.5|^9.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "GrahamCampbell\\ResultType\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "graham@alt-three.com" - } - ], - "description": "An Implementation Of The Result Type", - "keywords": [ - "Graham Campbell", - "GrahamCampbell", - "Result Type", - "Result-Type", - "result" - ], - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type", - "type": "tidelift" - } - ], - "time": "2020-04-13T13:17:36+00:00" - }, { "name": "guzzlehttp/psr7", "version": "1.6.1", @@ -971,16 +767,16 @@ }, { "name": "mongodb/mongodb", - "version": "1.6.0", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/mongodb/mongo-php-library.git", - "reference": "dc43ba25fb593d6a2988e6a535b6f5386eda5b15" + "reference": "4bb040c620ab95c487d05d5ff50cbc92fa68e920" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mongodb/mongo-php-library/zipball/dc43ba25fb593d6a2988e6a535b6f5386eda5b15", - "reference": "dc43ba25fb593d6a2988e6a535b6f5386eda5b15", + "url": "https://api.github.com/repos/mongodb/mongo-php-library/zipball/4bb040c620ab95c487d05d5ff50cbc92fa68e920", + "reference": "4bb040c620ab95c487d05d5ff50cbc92fa68e920", "shasum": "" }, "require": { @@ -1035,20 +831,20 @@ "mongodb", "persistence" ], - "time": "2020-02-04T18:16:35+00:00" + "time": "2020-07-03T11:35:00+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.10.0", + "version": "1.10.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "5796d127b0c4ff505b77455148ea9d5269d99758" + "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/5796d127b0c4ff505b77455148ea9d5269d99758", - "reference": "5796d127b0c4ff505b77455148ea9d5269d99758", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", + "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", "shasum": "" }, "require": { @@ -1089,7 +885,7 @@ "type": "tidelift" } ], - "time": "2020-06-28T07:02:41+00:00" + "time": "2020-06-29T13:22:24+00:00" }, { "name": "netresearch/jsonmapper", @@ -1139,16 +935,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.5.0", + "version": "v4.9.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "53c2753d756f5adb586dca79c2ec0e2654dd9463" + "reference": "aaee038b912e567780949787d5fe1977be11a778" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/53c2753d756f5adb586dca79c2ec0e2654dd9463", - "reference": "53c2753d756f5adb586dca79c2ec0e2654dd9463", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/aaee038b912e567780949787d5fe1977be11a778", + "reference": "aaee038b912e567780949787d5fe1977be11a778", "shasum": "" }, "require": { @@ -1156,8 +952,8 @@ "php": ">=7.0" }, "require-dev": { - "ircmaxell/php-yacc": "0.0.5", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/php-parse" @@ -1165,7 +961,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.3-dev" + "dev-master": "4.9-dev" } }, "autoload": { @@ -1187,7 +983,7 @@ "parser", "php" ], - "time": "2020-06-03T07:24:19+00:00" + "time": "2020-08-18T19:48:01+00:00" }, { "name": "ocramius/package-versions", @@ -1610,100 +1406,35 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "time": "2020-06-27T10:12:23+00:00" }, - { - "name": "phpoption/phpoption", - "version": "1.7.4", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/php-option.git", - "reference": "b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3", - "reference": "b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3", - "shasum": "" - }, - "require": { - "php": "^5.5.9 || ^7.0 || ^8.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.3", - "phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.7-dev" - } - }, - "autoload": { - "psr-4": { - "PhpOption\\": "src/PhpOption/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com" - }, - { - "name": "Graham Campbell", - "email": "graham@alt-three.com" - } - ], - "description": "Option Type for PHP", - "keywords": [ - "language", - "option", - "php", - "type" - ], - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption", - "type": "tidelift" - } - ], - "time": "2020-06-07T10:40:07+00:00" - }, { "name": "phpspec/prophecy", - "version": "v1.10.3", + "version": "1.11.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "451c3cd1418cf640de218914901e51b064abb093" + "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/451c3cd1418cf640de218914901e51b064abb093", - "reference": "451c3cd1418cf640de218914901e51b064abb093", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/b20034be5efcdab4fb60ca3a29cba2949aead160", + "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", - "sebastian/comparator": "^1.2.3|^2.0|^3.0|^4.0", - "sebastian/recursion-context": "^1.0|^2.0|^3.0|^4.0" + "doctrine/instantiator": "^1.2", + "php": "^7.2", + "phpdocumentor/reflection-docblock": "^5.0", + "sebastian/comparator": "^3.0 || ^4.0", + "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { - "phpspec/phpspec": "^2.5 || ^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + "phpspec/phpspec": "^6.0", + "phpunit/phpunit": "^8.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.10.x-dev" + "dev-master": "1.11.x-dev" } }, "autoload": { @@ -1736,24 +1467,24 @@ "spy", "stub" ], - "time": "2020-03-05T15:02:03+00:00" + "time": "2020-07-08T12:44:21+00:00" }, { "name": "phpstan/phpstan", - "version": "0.12.31", + "version": "0.12.38", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d" + "reference": "ad606c5f1c641b465b739e79a3a0f1a5a57cf1b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/776c8056b401e1b67f277b9e9fb334d1a274671d", - "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ad606c5f1c641b465b739e79a3a0f1a5a57cf1b4", + "reference": "ad606c5f1c641b465b739e79a3a0f1a5a57cf1b4", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -1792,7 +1523,7 @@ "type": "tidelift" } ], - "time": "2020-06-24T20:55:29+00:00" + "time": "2020-08-19T08:13:30+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2044,6 +1775,7 @@ "keywords": [ "tokenizer" ], + "abandoned": true, "time": "2019-09-17T06:23:10+00:00" }, { @@ -2993,16 +2725,16 @@ }, { "name": "symfony/console", - "version": "v4.4.10", + "version": "v4.4.11", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "326b064d804043005526f5a0494cfb49edb59bb0" + "reference": "55d07021da933dd0d633ffdab6f45d5b230c7e02" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/326b064d804043005526f5a0494cfb49edb59bb0", - "reference": "326b064d804043005526f5a0494cfb49edb59bb0", + "url": "https://api.github.com/repos/symfony/console/zipball/55d07021da933dd0d633ffdab6f45d5b230c7e02", + "reference": "55d07021da933dd0d633ffdab6f45d5b230c7e02", "shasum": "" }, "require": { @@ -3080,11 +2812,11 @@ "type": "tidelift" } ], - "time": "2020-05-30T20:06:45+00:00" + "time": "2020-07-06T13:18:39+00:00" }, { "name": "symfony/css-selector", - "version": "v5.1.2", + "version": "v5.1.3", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", @@ -3151,16 +2883,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v2.1.2", + "version": "v2.1.3", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "dd99cb3a0aff6cadd2a8d7d7ed72c2161e218337" + "reference": "5e20b83385a77593259c9f8beb2c43cd03b2ac14" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/dd99cb3a0aff6cadd2a8d7d7ed72c2161e218337", - "reference": "dd99cb3a0aff6cadd2a8d7d7ed72c2161e218337", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5e20b83385a77593259c9f8beb2c43cd03b2ac14", + "reference": "5e20b83385a77593259c9f8beb2c43cd03b2ac14", "shasum": "" }, "require": { @@ -3170,6 +2902,10 @@ "extra": { "branch-alias": { "dev-master": "2.1-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -3207,20 +2943,20 @@ "type": "tidelift" } ], - "time": "2020-05-27T08:34:37+00:00" + "time": "2020-06-06T08:49:21+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v4.4.10", + "version": "v4.4.11", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "a5370aaa7807c7a439b21386661ffccf3dff2866" + "reference": "6140fc7047dafc5abbe84ba16a34a86c0b0229b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/a5370aaa7807c7a439b21386661ffccf3dff2866", - "reference": "a5370aaa7807c7a439b21386661ffccf3dff2866", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/6140fc7047dafc5abbe84ba16a34a86c0b0229b8", + "reference": "6140fc7047dafc5abbe84ba16a34a86c0b0229b8", "shasum": "" }, "require": { @@ -3291,24 +3027,24 @@ "type": "tidelift" } ], - "time": "2020-05-20T08:37:50+00:00" + "time": "2020-06-18T17:59:13+00:00" }, { "name": "symfony/event-dispatcher-contracts", - "version": "v1.1.7", + "version": "v1.1.9", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "c43ab685673fb6c8d84220c77897b1d6cdbe1d18" + "reference": "84e23fdcd2517bf37aecbd16967e83f0caee25a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/c43ab685673fb6c8d84220c77897b1d6cdbe1d18", - "reference": "c43ab685673fb6c8d84220c77897b1d6cdbe1d18", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/84e23fdcd2517bf37aecbd16967e83f0caee25a7", + "reference": "84e23fdcd2517bf37aecbd16967e83f0caee25a7", "shasum": "" }, "require": { - "php": "^7.1.3" + "php": ">=7.1.3" }, "suggest": { "psr/event-dispatcher": "", @@ -3318,6 +3054,10 @@ "extra": { "branch-alias": { "dev-master": "1.1-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -3349,11 +3089,25 @@ "interoperability", "standards" ], - "time": "2019-09-17T09:54:03+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-06T13:19:58+00:00" }, { "name": "symfony/finder", - "version": "v5.1.2", + "version": "v5.1.3", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -3414,18 +3168,94 @@ ], "time": "2020-05-20T17:43:50+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.18.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454", + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-14T12:35:20+00:00" + }, { "name": "symfony/polyfill-mbstring", - "version": "v1.17.1", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "7110338d81ce1cbc3e273136e4574663627037a7" + "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7110338d81ce1cbc3e273136e4574663627037a7", - "reference": "7110338d81ce1cbc3e273136e4574663627037a7", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/a6977d63bf9a0ad4c65cd352709e230876f9904a", + "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a", "shasum": "" }, "require": { @@ -3437,7 +3267,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.17-dev" + "dev-master": "1.18-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3489,20 +3319,20 @@ "type": "tidelift" } ], - "time": "2020-06-06T08:46:27+00:00" + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/polyfill-php73", - "version": "v1.17.1", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "fa0837fe02d617d31fbb25f990655861bb27bd1a" + "reference": "fffa1a52a023e782cdcc221d781fe1ec8f87fcca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fa0837fe02d617d31fbb25f990655861bb27bd1a", - "reference": "fa0837fe02d617d31fbb25f990655861bb27bd1a", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fffa1a52a023e782cdcc221d781fe1ec8f87fcca", + "reference": "fffa1a52a023e782cdcc221d781fe1ec8f87fcca", "shasum": "" }, "require": { @@ -3511,7 +3341,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.17-dev" + "dev-master": "1.18-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3565,20 +3395,20 @@ "type": "tidelift" } ], - "time": "2020-06-06T08:46:27+00:00" + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.17.1", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "4a5b6bba3259902e386eb80dd1956181ee90b5b2" + "reference": "d87d5766cbf48d72388a9f6b85f280c8ad51f981" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/4a5b6bba3259902e386eb80dd1956181ee90b5b2", - "reference": "4a5b6bba3259902e386eb80dd1956181ee90b5b2", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/d87d5766cbf48d72388a9f6b85f280c8ad51f981", + "reference": "d87d5766cbf48d72388a9f6b85f280c8ad51f981", "shasum": "" }, "require": { @@ -3587,7 +3417,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.17-dev" + "dev-master": "1.18-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3645,20 +3475,20 @@ "type": "tidelift" } ], - "time": "2020-06-06T08:46:27+00:00" + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/service-contracts", - "version": "v2.1.2", + "version": "v2.1.3", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "66a8f0957a3ca54e4f724e49028ab19d75a8918b" + "reference": "58c7475e5457c5492c26cc740cc0ad7464be9442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/66a8f0957a3ca54e4f724e49028ab19d75a8918b", - "reference": "66a8f0957a3ca54e4f724e49028ab19d75a8918b", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/58c7475e5457c5492c26cc740cc0ad7464be9442", + "reference": "58c7475e5457c5492c26cc740cc0ad7464be9442", "shasum": "" }, "require": { @@ -3672,6 +3502,10 @@ "extra": { "branch-alias": { "dev-master": "2.1-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -3717,11 +3551,11 @@ "type": "tidelift" } ], - "time": "2020-05-20T17:43:50+00:00" + "time": "2020-07-06T13:23:11+00:00" }, { "name": "symfony/yaml", - "version": "v5.1.2", + "version": "v5.1.3", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", @@ -3798,23 +3632,23 @@ }, { "name": "theseer/tokenizer", - "version": "1.1.3", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" + "reference": "75a63c33a8577608444246075ea0af0d052e452a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", - "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", + "reference": "75a63c33a8577608444246075ea0af0d052e452a", "shasum": "" }, "require": { "ext-dom": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": "^7.0" + "php": "^7.2 || ^8.0" }, "type": "library", "autoload": { @@ -3834,7 +3668,13 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2019-06-13T22:48:21+00:00" + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2020-07-12T23:59:07+00:00" }, { "name": "vimeo/psalm", @@ -3924,6 +3764,78 @@ ], "time": "2019-10-20T20:19:01+00:00" }, + { + "name": "vlucas/phpdotenv", + "version": "v2.6.6", + "source": { + "type": "git", + "url": "https://github.com/vlucas/phpdotenv.git", + "reference": "e1d57f62db3db00d9139078cbedf262280701479" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/e1d57f62db3db00d9139078cbedf262280701479", + "reference": "e1d57f62db3db00d9139078cbedf262280701479", + "shasum": "" + }, + "require": { + "php": "^5.3.9 || ^7.0 || ^8.0", + "symfony/polyfill-ctype": "^1.17" + }, + "require-dev": { + "ext-filter": "*", + "ext-pcre": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7.27" + }, + "suggest": { + "ext-filter": "Required to use the boolean validator.", + "ext-pcre": "Required to use most of the library." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6-dev" + } + }, + "autoload": { + "psr-4": { + "Dotenv\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "graham@alt-three.com", + "homepage": "https://gjcampbell.co.uk/" + }, + { + "name": "Vance Lucas", + "email": "vance@vancelucas.com", + "homepage": "https://vancelucas.com/" + } + ], + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", + "type": "tidelift" + } + ], + "time": "2020-07-14T17:54:18+00:00" + }, { "name": "webmozart/assert", "version": "1.7.0", diff --git a/src/Mvc/Collection.php b/src/Mvc/Collection.php index 8d04f6b..e987bbd 100644 --- a/src/Mvc/Collection.php +++ b/src/Mvc/Collection.php @@ -1453,7 +1453,7 @@ protected static function getGroupResultset(array $parameters, CollectionInterfa final protected function possibleSetter(string $property, $value): bool { - $possibleSetter = "set" . Str::camelize($property); + $possibleSetter = "set" . ucfirst(Str::camelize($property)); if (!method_exists($this, $possibleSetter)) { return false; @@ -1472,7 +1472,7 @@ final protected function possibleSetter(string $property, $value): bool */ final protected function possibleGetter(string $property) { - $possibleGetter = "get" . Str::camelize($property); + $possibleGetter = "get" . ucfirst(Str::camelize($property)); if (!method_exists($this, $possibleGetter)) { return $this->$property; @@ -1511,8 +1511,8 @@ public function assign(array $data, $dataColumnMap = null, $whiteList = null): C continue; } - if (!$this->possibleSetter($key, $value)) { - $this->$key = $value; + if (!$this->possibleSetter($key, $dataMapped[$key])) { + $this->$key = $dataMapped[$key]; } } } diff --git a/tests/_data/fixtures/Mvc/Collections/Robots.php b/tests/_data/fixtures/Mvc/Collections/Robots.php index b1d683d..76c814e 100644 --- a/tests/_data/fixtures/Mvc/Collections/Robots.php +++ b/tests/_data/fixtures/Mvc/Collections/Robots.php @@ -72,7 +72,7 @@ public function getProtectedField() */ public function setProtectedField($protected_field): void { - $this->protected_field = $protected_field; + $this->protected_field = $protected_field + 1; } /** diff --git a/tests/integration/Collection/AssignCest.php b/tests/integration/Collection/AssignCest.php new file mode 100644 index 0000000..25bb9cf --- /dev/null +++ b/tests/integration/Collection/AssignCest.php @@ -0,0 +1,76 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Incubator\MongoDB\Mvc\Test\Integration\Collection; + +use IntegrationTester; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait; + +/** + * Class AssignCest + */ +class AssignCest +{ + use DiTrait; + + public function _before() + { + $this->setNewFactoryDefault(); + $this->setDiCollectionManager(); + $this->setDiMongo(); + } + + /** + * Tests Phalcon\Mvc\Collection :: __construct() + * + * @param IntegrationTester $I + * @since 2018-11-13 + * @author Phalcon Team + */ + public function mvcCollectionAssign(IntegrationTester $I): void + { + $I->wantToTest('Mvc\Collection - assign()'); + + $name = 'Henry'; + + $robot1 = new Robots(); + $robot1->assign([ + 'first_name' => $name, + 'protected_field' => 71, + ]); + + $I->assertEquals($robot1->first_name, $name); + $I->assertEquals(72, $robot1->getProtectedField()); + + $robot2 = new Robots(); + $robot2->assign([ + 'firstn' => $name, + ], [ + 'firstn' => 'first_name' + ]); + + $I->assertEquals($robot2->first_name, $name); + + $robot3 = new Robots(); + $robot3->assign([ + 'first_name' => $name, + 'protected_field' => 0, + ], null, [ + 'first_name' + ]); + + $I->assertEquals($robot3->first_name, $name); + $I->assertEquals(42, $robot3->getProtectedField()); + } +} From 8a7c8e030afdc2328eb56a474b5b9656d98e6aaf Mon Sep 17 00:00:00 2001 From: Tacxticx88 <12997062+tacxticx88@users.noreply.github.com> Date: Fri, 21 Aug 2020 10:37:20 +0200 Subject: [PATCH 2/5] Now use Cursor for more performances in big records --- src/Mvc/Collection.php | 50 +++++++++++-------- .../integration/Collection/AggregateCest.php | 11 +++- tests/integration/Collection/FindCest.php | 13 +++-- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/Mvc/Collection.php b/src/Mvc/Collection.php index e987bbd..262e22e 100644 --- a/src/Mvc/Collection.php +++ b/src/Mvc/Collection.php @@ -13,6 +13,7 @@ namespace Phalcon\Incubator\MongoDB\Mvc; +use ArrayIterator; use JsonSerializable; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Serializable as BsonSerializable; @@ -32,6 +33,7 @@ use Phalcon\Mvc\EntityInterface; use Phalcon\Validation\ValidationInterface; use Serializable; +use Traversable; /** * Class Collection @@ -166,28 +168,37 @@ public function appendMessage(MessageInterface $message): CollectionInterface * * @param array|null $parameters * @param array|null $options - * @return array + * @return Cursor|ArrayIterator * @throws Exception */ - public static function aggregate(?array $parameters = [], ?array $options = []): array + public static function aggregate(array $parameters = [], array $options = []): Traversable { $className = static::class; - /** @var CollectionInterface $collection */ - $collection = new $className(); - $source = $collection->getSource(); + /** @var CollectionInterface $base */ + $base = new $className(); + $source = $base->getSource(); + if (empty($source)) { throw new Exception("Method getSource() returns empty string"); } - $connection = $collection->getConnection(); - $cursorOrArrayIterator = $connection->selectCollection($source)->aggregate($parameters, $options); - - if ($cursorOrArrayIterator instanceof Cursor) { - return $cursorOrArrayIterator->toArray(); + /** + * Check if a "typeMap" clause was defined or force default + */ + if (isset($options["typeMap"])) { + $options['typeMap'] = array_merge( + self::getTypeMap('array'), + $options["typeMap"] + ); + } else { + $options['typeMap'] = self::getTypeMap('array'); } - return (array)$cursorOrArrayIterator; + $connection = $base->getConnection(); + + // Driver now return a Cursor class by default for more performances. + return $connection->selectCollection($source)->aggregate($parameters, $options); } /** @@ -761,10 +772,10 @@ public static function count(array $parameters = []): int * ``` * * @param array $parameters - * @return iterable + * @return Cursor|Traversable * @throws Exception */ - public static function find(array $parameters = []): iterable + public static function find(array $parameters = []): Traversable { $className = static::class; /** @var CollectionInterface $collection */ @@ -1210,7 +1221,8 @@ public static function getTypeMap($base = null): array "document" => 'array' ]; - if (is_array($base::$typeMap)) { + /** @noinspection NotOptimalIfConditionsInspection */ + if (class_exists($base) && is_array($base::$typeMap)) { $typeMap = array_merge($typeMap, $base::$typeMap); } @@ -1342,7 +1354,7 @@ protected function exists($collection): bool * @param CollectionInterface $collection * @param mixed|Database $connection * @param bool $unique - * @return array|object|null + * @return Cursor|object|array * @throws Exception */ protected static function getResultset( @@ -1415,12 +1427,8 @@ protected static function getResultset( return $document; } - /** - * Requesting a complete resultset - */ - $documentsCursor = $mongoCollection->find($conditions, $parameters); - - return $documentsCursor->toArray(); + // Driver now return a Cursor class by default for more performances. + return $mongoCollection->find($conditions, $parameters); } /** diff --git a/tests/integration/Collection/AggregateCest.php b/tests/integration/Collection/AggregateCest.php index 99b7a6b..beac398 100644 --- a/tests/integration/Collection/AggregateCest.php +++ b/tests/integration/Collection/AggregateCest.php @@ -15,6 +15,7 @@ use IntegrationTester; use MongoDB\Database; +use MongoDB\Driver\Cursor; use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots; use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait; @@ -67,6 +68,7 @@ public function mvcCollectionAggregate(IntegrationTester $I) $options = ['typeMap' => Robots::getTypeMap()]; + /** @var Cursor $robots1 */ $robots1 = Robots::aggregate([ [ '$match' => [ @@ -75,6 +77,12 @@ public function mvcCollectionAggregate(IntegrationTester $I) ] ]); + $I->assertInstanceOf(Cursor::class, $robots1); + + foreach ($robots1 as $rb) { + $I->assertIsArray($rb); + } + $robots2 = Robots::aggregate([ [ '$match' => [ @@ -83,8 +91,7 @@ public function mvcCollectionAggregate(IntegrationTester $I) ] ], $options); - $I->assertNotEmpty($robots1); - $I->assertInstanceOf(Robots::class, $robots2[0]); + $I->assertInstanceOf(Robots::class, $robots2->toArray()[0]); } public function _after() diff --git a/tests/integration/Collection/FindCest.php b/tests/integration/Collection/FindCest.php index 972841c..fd00e7f 100644 --- a/tests/integration/Collection/FindCest.php +++ b/tests/integration/Collection/FindCest.php @@ -70,12 +70,19 @@ public function mvcCollectionFind(IntegrationTester $I) $I->wantToTest('Mvc\Collection - find()'); $robots = Robots::find(); + $robots1 = Robots::find(); $robotsE = Robots::find([['last_name' => 'E']]); + $result = $robots->toArray(); + + foreach ($robots1 as $rb) { + $I->assertInstanceOf(Robots::class, $rb); + } + $I->assertNotEmpty($robots); - $I->assertInstanceOf(Robots::class, $robots[0]); - $I->assertEquals(3, count($robots)); - $I->assertEquals(2, count($robotsE)); + $I->assertInstanceOf(Robots::class, $result[0]); + $I->assertCount(3, $result); + $I->assertCount(2, $robotsE->toArray()); } public function _after() From 6624ef2a5cda4c6af7a097ccd13b729df4af370c Mon Sep 17 00:00:00 2001 From: Tacxticx88 <12997062+tacxticx88@users.noreply.github.com> Date: Sat, 22 Aug 2020 09:41:28 +0200 Subject: [PATCH 3/5] Implements class inherit --- .../_data/fixtures/Mvc/Collections/Robots.php | 5 +++ .../fixtures/Mvc/Collections/SuperRobots.php | 37 +++++++++++++++++++ tests/integration/Collection/AssignCest.php | 12 ++++++ .../Collection/GetMessagesCest.php | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/_data/fixtures/Mvc/Collections/SuperRobots.php diff --git a/tests/_data/fixtures/Mvc/Collections/Robots.php b/tests/_data/fixtures/Mvc/Collections/Robots.php index 76c814e..5140202 100644 --- a/tests/_data/fixtures/Mvc/Collections/Robots.php +++ b/tests/_data/fixtures/Mvc/Collections/Robots.php @@ -19,6 +19,11 @@ use Phalcon\Validation; use Phalcon\Validation\Validator\Numericality; +/** + * Class Robots + * + * @package Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections + */ class Robots extends Collection { public $first_name; diff --git a/tests/_data/fixtures/Mvc/Collections/SuperRobots.php b/tests/_data/fixtures/Mvc/Collections/SuperRobots.php new file mode 100644 index 0000000..3dc348b --- /dev/null +++ b/tests/_data/fixtures/Mvc/Collections/SuperRobots.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections; + +use Phalcon\Incubator\MongoDB\Mvc\Collection; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Documents\RobotPart; +use Phalcon\Messages\Message; +use Phalcon\Validation; +use Phalcon\Validation\Validator\Numericality; + +/** + * Class SuperRobots + * + * @package Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections + */ +class SuperRobots extends Robots +{ + public function initialize(): void + { + self::$typeMap['fieldPaths']['rbpart2'] = RobotPart::class; + } + + public $rbsuperversion = 1; + + public $rbpart2; +} diff --git a/tests/integration/Collection/AssignCest.php b/tests/integration/Collection/AssignCest.php index 25bb9cf..df1d5e1 100644 --- a/tests/integration/Collection/AssignCest.php +++ b/tests/integration/Collection/AssignCest.php @@ -15,6 +15,7 @@ use IntegrationTester; use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\SuperRobots; use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait; /** @@ -72,5 +73,16 @@ public function mvcCollectionAssign(IntegrationTester $I): void $I->assertEquals($robot3->first_name, $name); $I->assertEquals(42, $robot3->getProtectedField()); + + $superrb = new SuperRobots(); + $superrb->assign([ + 'first_name' => $name, + 'protected_field' => 44, + 'rbsuperversion' => 54, + ]); + + $I->assertEquals($superrb->first_name, $name); + $I->assertEquals($superrb->getProtectedField(), 45); + $I->assertEquals($superrb->rbsuperversion, 54); } } diff --git a/tests/integration/Collection/GetMessagesCest.php b/tests/integration/Collection/GetMessagesCest.php index 0798b7c..9c910e8 100644 --- a/tests/integration/Collection/GetMessagesCest.php +++ b/tests/integration/Collection/GetMessagesCest.php @@ -53,7 +53,7 @@ public function mvcCollectionGetMessages(IntegrationTester $I) $I->wantToTest('Mvc\Collection - getMessages()'); $robot = new Robots; - $robot->setProtectedField("bad"); + $robot->version = -1; $I->assertFalse($robot->save()); $I->assertNotEmpty($robot->getMessages()); From 394ccd4ab5c3d1986a113921aec7899f9efc0997 Mon Sep 17 00:00:00 2001 From: Tacxticx88 <12997062+tacxticx88@users.noreply.github.com> Date: Sat, 22 Aug 2020 10:04:29 +0200 Subject: [PATCH 4/5] Fix assign reflectionclass to list uninitialized properties --- src/Mvc/Collection.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Mvc/Collection.php b/src/Mvc/Collection.php index 262e22e..e36d213 100644 --- a/src/Mvc/Collection.php +++ b/src/Mvc/Collection.php @@ -32,6 +32,8 @@ use Phalcon\Messages\MessageInterface; use Phalcon\Mvc\EntityInterface; use Phalcon\Validation\ValidationInterface; +use ReflectionClass; +use ReflectionException; use Serializable; use Traversable; @@ -1494,6 +1496,7 @@ final protected function possibleGetter(string $property) * @param null $dataColumnMap * @param null $whiteList * @return $this|CollectionInterface + * @throws ReflectionException */ public function assign(array $data, $dataColumnMap = null, $whiteList = null): CollectionInterface { @@ -1513,7 +1516,12 @@ public function assign(array $data, $dataColumnMap = null, $whiteList = null): C return $this; } - foreach (get_object_vars($this) as $key => $value) { + // Use reflection to list uninitialized properties + $reflection = new ReflectionClass($this); + + foreach ($reflection->getProperties() as $reflectionMethod) { + $key = $reflectionMethod->getName(); + if (isset($dataMapped[$key])) { if (is_array($whiteList) && !in_array($key, $whiteList, true)) { continue; From 41997e6cda3612a0e1431ff7035e27fa099298df Mon Sep 17 00:00:00 2001 From: Tacxticx88 <12997062+tacxticx88@users.noreply.github.com> Date: Sat, 22 Aug 2020 13:06:54 +0200 Subject: [PATCH 5/5] common collection/document constructor and assign methods --- src/Mvc/Collection.php | 15 ++- src/Mvc/Collection/Document.php | 96 ++++++++++++++++--- .../Mvc/Collections/Documents/RobotPart.php | 43 ++++++++- .../integration/Collection/ConstructCest.php | 4 + .../Collection/Document/AssignCest.php | 51 ++++++++++ .../Collection/Document/ConstructCest.php | 2 +- .../Collection/Document/JsonSerializeCest.php | 60 ++++++++++++ .../Document/ReadWriteAttributeCest.php | 2 +- .../Collection/JsonSerializeCest.php | 2 +- 9 files changed, 253 insertions(+), 22 deletions(-) create mode 100644 tests/integration/Collection/Document/AssignCest.php create mode 100644 tests/integration/Collection/Document/JsonSerializeCest.php diff --git a/src/Mvc/Collection.php b/src/Mvc/Collection.php index e36d213..3f47ea1 100644 --- a/src/Mvc/Collection.php +++ b/src/Mvc/Collection.php @@ -1496,7 +1496,6 @@ final protected function possibleGetter(string $property) * @param null $dataColumnMap * @param null $whiteList * @return $this|CollectionInterface - * @throws ReflectionException */ public function assign(array $data, $dataColumnMap = null, $whiteList = null): CollectionInterface { @@ -1517,11 +1516,21 @@ public function assign(array $data, $dataColumnMap = null, $whiteList = null): C } // Use reflection to list uninitialized properties - $reflection = new ReflectionClass($this); + try { + $reflection = new ReflectionClass($this); + $reflectionProperties = $reflection->getProperties(); + } catch (ReflectionException $e) { + $reflectionProperties = []; + } + $reserved = $this->getReservedAttributes(); - foreach ($reflection->getProperties() as $reflectionMethod) { + foreach ($reflectionProperties as $reflectionMethod) { $key = $reflectionMethod->getName(); + if (isset($reserved[$key])) { + continue; + } + if (isset($dataMapped[$key])) { if (is_array($whiteList) && !in_array($key, $whiteList, true)) { continue; diff --git a/src/Mvc/Collection/Document.php b/src/Mvc/Collection/Document.php index a945f2d..d292ff4 100755 --- a/src/Mvc/Collection/Document.php +++ b/src/Mvc/Collection/Document.php @@ -1,7 +1,5 @@ $value) { - $this->offsetSet($key, $value); - } - /** * This allows the developer to execute initialization stuff every time * an instance is created */ if (method_exists($this, 'onConstruct')) { - $this->onConstruct(); + $this->onConstruct($data); + } + + if (is_array($data)) { + $this->assign($data); + } + } + + /** + * @param array $data + * @param null $dataColumnMap + * @param null $whiteList + * @return $this|CollectionInterface + */ + public function assign(array $data, $dataColumnMap = null, $whiteList = null): self + { + if (is_array($dataColumnMap)) { + $dataMapped = []; + + foreach ($data as $key => $value) { + if (isset($dataColumnMap[$key])) { + $dataMapped[$dataColumnMap[$key]] = $value; + } + } + } else { + $dataMapped = $data; + } + + if (count($dataMapped) === 0) { + return $this; + } + + // Use reflection to list uninitialized properties + try { + $reflection = new ReflectionClass($this); + $reflectionProperties = $reflection->getProperties(); + } catch (ReflectionException $e) { + $reflectionProperties = []; + } + + foreach ($reflectionProperties as $reflectionMethod) { + $key = $reflectionMethod->getName(); + + if (isset($dataMapped[$key])) { + if (is_array($whiteList) && !in_array($key, $whiteList, true)) { + continue; + } + + if (!$this->possibleSetter($key, $dataMapped[$key])) { + $this->$key = $dataMapped[$key]; + } + } } + + return $this; } /** @@ -146,7 +196,7 @@ public function toArray(): array * * @return array */ - public function jsonSerialize() + public function jsonSerialize(): array { $data = []; @@ -157,9 +207,13 @@ public function jsonSerialize() return $data; } + /** + * @param string $property + * @return mixed + */ final protected function possibleGetter(string $property) { - $possibleGetter = "get" . Str::camelize($property); + $possibleGetter = "get" . ucfirst(Str::camelize($property)); if (!method_exists($this, $possibleGetter)) { return $this->$property; @@ -171,15 +225,33 @@ final protected function possibleGetter(string $property) /** * @return array */ - public function bsonSerialize() + public function bsonSerialize(): array { return $this->toArray(); } + /** + * @param string $property + * @param $value + * @return bool + */ + final protected function possibleSetter(string $property, $value): bool + { + $possibleSetter = "set" . ucfirst(Str::camelize($property)); + + if (!method_exists($this, $possibleSetter)) { + return false; + } + + $this->$possibleSetter($value); + + return true; + } + /** * @param array $data */ - public function bsonUnserialize(array $data) + public function bsonUnserialize(array $data): void { foreach ($data as $key => $value) { $this->offsetSet($key, $value); diff --git a/tests/_data/fixtures/Mvc/Collections/Documents/RobotPart.php b/tests/_data/fixtures/Mvc/Collections/Documents/RobotPart.php index c68dd14..a4edc01 100644 --- a/tests/_data/fixtures/Mvc/Collections/Documents/RobotPart.php +++ b/tests/_data/fixtures/Mvc/Collections/Documents/RobotPart.php @@ -15,12 +15,15 @@ use DateTime; use DateTimeInterface; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\UTCDateTime; +use Phalcon\Incubator\MongoDB\Helper\Mongo; use Phalcon\Incubator\MongoDB\Mvc\Collection\Document; +use function GuzzleHttp\Psr7\str; class RobotPart extends Document { - public $id; + protected $id; public $common_name; @@ -44,8 +47,40 @@ public function setDate(DateTimeInterface $date) */ public function getDate() { - return $this->date - ->toDateTime() - ->format(DateTime::ISO8601); + if (null !== $this->date) { + return $this->date + ->toDateTime() + ->format(DateTime::ATOM); + } + + return null; + } + + /** + * @param string $type + * @return mixed + */ + public function getId($type = 'string') + { + switch ($type) { + case 'string': + return (string) $this->id; + + case 'object': + return $this->id; + + default: + return null; + } + } + + /** + * @param mixed $id + */ + public function setId($id): void + { + $this->id = Mongo::isValidObjectId($id) + ? new ObjectId((string)$id) + : null; } } diff --git a/tests/integration/Collection/ConstructCest.php b/tests/integration/Collection/ConstructCest.php index cdbb4cc..15bbc04 100644 --- a/tests/integration/Collection/ConstructCest.php +++ b/tests/integration/Collection/ConstructCest.php @@ -14,6 +14,7 @@ namespace Phalcon\Incubator\MongoDB\Mvc\Test\Integration\Collection; use IntegrationTester; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Documents\RobotPart; use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots; use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait; @@ -43,7 +44,10 @@ public function mvcCollectionConstruct(IntegrationTester $I) $I->wantToTest('Mvc\Collection - __construct()'); $robot = new Robots(); + $robot->rbpart = new RobotPart(); + $I->assertInstanceOf(Robots::class, $robot); + $I->assertInstanceOf(RobotPart::class, $robot->rbpart); $I->assertEquals(Robots::DIRTY_STATE_TRANSIENT, $robot->getDirtyState()); } } diff --git a/tests/integration/Collection/Document/AssignCest.php b/tests/integration/Collection/Document/AssignCest.php new file mode 100644 index 0000000..e46de98 --- /dev/null +++ b/tests/integration/Collection/Document/AssignCest.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Incubator\MongoDB\Mvc\Test\Integration\Collection\Document; + +use IntegrationTester; +use MongoDB\BSON\ObjectId; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Documents\RobotPart; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait; + +/** + * Class AssignCest + */ +class AssignCest +{ + use DiTrait; + + public function _before() + { + $this->setNewFactoryDefault(); + $this->setDiCollectionManager(); + $this->setDiMongo(); + } + + /** + * Tests Phalcon\Mvc\Collection\Document :: assign() + * + * @param IntegrationTester $I + */ + public function mvcCollectionDocumentConstruct(IntegrationTester $I) + { + $I->wantToTest('Mvc\Collection\Document - assign()'); + + $robotPart = new RobotPart(); + $robotPart->assign([ + 'id' => new ObjectId() + ]); + + $I->assertInstanceOf(ObjectId::class, $robotPart->getId('object')); + } +} diff --git a/tests/integration/Collection/Document/ConstructCest.php b/tests/integration/Collection/Document/ConstructCest.php index da08e8c..cef0480 100644 --- a/tests/integration/Collection/Document/ConstructCest.php +++ b/tests/integration/Collection/Document/ConstructCest.php @@ -40,7 +40,7 @@ public function _before() */ public function mvcCollectionDocumentConstruct(IntegrationTester $I) { - $I->wantToTest('Mvc\Collection\Document - offsetExists()'); + $I->wantToTest('Mvc\Collection\Document - __construct()'); $robotPart = new RobotPart(); $I->assertInstanceOf(RobotPart::class, $robotPart); diff --git a/tests/integration/Collection/Document/JsonSerializeCest.php b/tests/integration/Collection/Document/JsonSerializeCest.php new file mode 100644 index 0000000..7e428b0 --- /dev/null +++ b/tests/integration/Collection/Document/JsonSerializeCest.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Incubator\MongoDB\Mvc\Test\Integration\Collection\Document; + +use IntegrationTester; +use MongoDB\BSON\ObjectId; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Documents\RobotPart; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots; +use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait; + +/** + * Class JsonSerializeCest + */ +class JsonSerializeCest +{ + use DiTrait; + + public function _before() + { + $this->setNewFactoryDefault(); + $this->setDiCollectionManager(); + $this->setDiMongo(); + } + + /** + * Tests Phalcon\Mvc\Collection\Document :: jsonSerialize() + * + * @param IntegrationTester $I + */ + public function mvcCollectionDocumentJsonSerializeCest(IntegrationTester $I) + { + $I->wantToTest('Mvc\Collection\Document - jsonSerialize()'); + + $parts = [ + 'id' => new ObjectId(), + 'date' => null, + 'common_name' => 'Henry' + ]; + + $robotPart = new RobotPart($parts); + $data = $robotPart->toArray(); + $data['id'] = (string)$data['id']; + + $dataCompare = json_decode(json_encode($data), true); + $robotCompare = json_decode(json_encode($robotPart), true); + + $I->assertEquals($dataCompare, $robotCompare); + } +} diff --git a/tests/integration/Collection/Document/ReadWriteAttributeCest.php b/tests/integration/Collection/Document/ReadWriteAttributeCest.php index a7fc494..074dbda 100644 --- a/tests/integration/Collection/Document/ReadWriteAttributeCest.php +++ b/tests/integration/Collection/Document/ReadWriteAttributeCest.php @@ -56,7 +56,7 @@ public function mvcCollectionDocumentReadWriteAttribute(IntegrationTester $I) $robotPart = new RobotPart(['common_name' => $common_name]); $robotPart->writeAttribute('id', $robot->getId()); - $I->assertEquals($robotPart->id, $robot->getId()); + $I->assertEquals($robotPart->getId('object'), $robot->getId()); $partName = $robotPart->readAttribute('common_name'); $I->assertEquals($common_name, $partName); diff --git a/tests/integration/Collection/JsonSerializeCest.php b/tests/integration/Collection/JsonSerializeCest.php index b8e90e9..8328219 100644 --- a/tests/integration/Collection/JsonSerializeCest.php +++ b/tests/integration/Collection/JsonSerializeCest.php @@ -49,7 +49,7 @@ public function _before() $this->mongo = $this->getDi()->get('mongo'); $rbpart = new RobotPart(); - $rbpart->id = new ObjectId(); + $rbpart->setId(new ObjectId()); $rbpart->setDate(new DateTime()); $this->data = [