-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.1] Indexer result serializer PHP 8.1 fixes #37338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ae140d9
Indexer result serializer PHP 8.1 fixes
laoneo a2b06b8
Update administrator/components/com_finder/src/Indexer/Result.php
laoneo 387025c
Docs
laoneo ca81ba4
Merge branch 'j4/finder/indexer-81' of github.com:Digital-Peak/joomla…
laoneo 737329e
Merge branch '4.1-dev' into j4/finder/indexer-81
laoneo db4da23
Merge branch '4.1-dev' into j4/finder/indexer-81
laoneo d446bee
Merge branch '4.1-dev' into j4/finder/indexer-81
laoneo 3004d25
Merge branch '4.1-dev' into j4/finder/indexer-81
laoneo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
tests/Unit/CMS/administrator/components/com_finder/src/Indexer/ResultTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.UnitTest | ||
| * @subpackage com_finder | ||
| * | ||
| * @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
| namespace Joomla\Tests\Unit\Administrator\Components\Finder\Indexer; | ||
|
|
||
| use Joomla\Component\Finder\Administrator\Indexer\Result; | ||
| use Joomla\Tests\Unit\UnitTestCase; | ||
| use ReflectionClass; | ||
|
|
||
| /** | ||
| * Test class for \Joomla\Component\Finder\Administrator\Indexer\Result | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class ResultTest extends UnitTestCase | ||
| { | ||
| /** | ||
| * Include non-autoloaded files as Namespace in the files that don't implement PSR-4 | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function setUp(): void | ||
| { | ||
| // Can be removed once we have autoloading working in Unit Tests | ||
| // @see https://github.com/joomla/joomla-cms/pull/36486 | ||
| if (!class_exists(Result::class)) | ||
| { | ||
| require_once JPATH_ADMINISTRATOR . '/components/com_finder/src/Indexer/Indexer.php'; | ||
| require_once JPATH_ADMINISTRATOR . '/components/com_finder/src/Indexer/Result.php'; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @return void | ||
| * | ||
| * @throws \ReflectionException | ||
| * | ||
| * @covers Result::unserialize | ||
| * @covers Result::serialize | ||
| * @covers Result::__serialize | ||
| * @covers Result::__unserialize | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function testSerialize(): void | ||
| { | ||
| /** @var Result $obj */ | ||
| $obj = $this->createNoConstructorMock(); | ||
| $obj->setElement('this', 'that'); | ||
| $obj->title = 'MyTitle'; | ||
|
|
||
| // Test the `serialize` method provided by the object - Pre PHP 8.1 deprecated style | ||
| $this->assertIsString( | ||
| $obj->serialize($obj) | ||
| ); | ||
|
|
||
| // Test PHP `serialize` the object - PHP 8.1+ style (uses magic methods) | ||
| $this->assertEquals( | ||
| 'that', | ||
| unserialize(serialize($obj))->getElement('this') | ||
| ); | ||
|
|
||
| $obj->title = 'MyTitle2'; | ||
| $this->assertEquals( | ||
| 'MyTitle2', | ||
| unserialize(serialize($obj))->title | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Useful method to mock the Result class so that the constructor doesn't call | ||
| * ComponentHelper which requires a db connection and full Joomla stack running. | ||
| * | ||
| * @param $class string | ||
| * | ||
| * @return object<Result> | ||
| * | ||
| * @throws \ReflectionException | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| private function createNoConstructorMock($class = Result::class): object | ||
| { | ||
| return (new ReflectionClass($class))->newInstanceWithoutConstructor(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.