-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4][com_finder] - php 8.1 serializable-deprecated with unit test #36482
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
17e7723
[4][com_finder] - php 8.1 serializable-deprecated
PhilETaylor 6c7e2cb
🎄Add our first CMS Unit Test...
PhilETaylor 6fd8d77
fix headers
PhilETaylor 65cac60
remove redundant import
PhilETaylor e619ce5
add `@covers` tags
PhilETaylor 50e03bd
Update ResultTest.php
PhilETaylor a0b1b91
s/2021/2022
PhilETaylor f5d3464
revert to force drone build
PhilETaylor 10f7fe1
Add note
PhilETaylor 2a33b78
Update namespace and import SUT class
PhilETaylor 1497d5f
change to trigger drone
PhilETaylor e812394
trigger drone
PhilETaylor 2395ab6
Merge branch '4.1-dev' into php81findercornflakes
chmst 4d9c10b
Merge branch '4.1-dev' into php81findercornflakes
PhilETaylor 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
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
92 changes: 92 additions & 0 deletions
92
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,92 @@ | ||
| <?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\Component\Finder\Administrator\Indexer; | ||
PhilETaylor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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.