-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Bug #18469: fix Link::serialize method #20020
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0183e95
Bug #18469: fix Link::serialize method
ggh2e3 7cf5ebf
Bug #18469: fix changelog pattern
ggh2e3 9c43085
Bug #18469: removed space at the end of changelog
ggh2e3 000e77e
Merge branch 'master' into 18469-bug-link-fix
ggh2e3 bf84616
Issue #18469: fix tests
ggh2e3 9e7b68c
Merge branch 'master' into 18469-bug-link-fix
ggh2e3 972683d
bug #18469: apply suggestions from code review
ggh2e3 ab168e7
Merge branch 'master' into 18469-bug-link-fix
ggh2e3 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 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 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 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,105 @@ | ||
<?php | ||
/** | ||
* @link https://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license https://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace yiiunit\framework\web; | ||
|
||
use yii\base\BaseObject; | ||
use yii\web\Link; | ||
use yiiunit\TestCase; | ||
|
||
/** | ||
* @group web | ||
*/ | ||
class LinkTest extends TestCase | ||
{ | ||
public function testSerializeSimpleArraySuccessfully() | ||
{ | ||
$this->assertEquals([ | ||
'link' => [ | ||
'href' => 'http://example.com/users/4' | ||
], | ||
'title' => [ | ||
'href' => 'My user', | ||
] | ||
], Link::serialize([ | ||
'link' => 'http://example.com/users/4', | ||
'title' => 'My user', | ||
])); | ||
} | ||
|
||
public function testSerializeArrayWithLinkSuccessfully() | ||
{ | ||
$link = new UserLink([ | ||
'link' => 'http://example.com/users/4', | ||
'title' => 'User 4', | ||
]); | ||
|
||
$this->assertEquals([ | ||
'link serialized' => [ | ||
'title' => 'User 4', | ||
'link' => 'http://example.com/users/4' | ||
], | ||
'title' => ['href' => 'My user'], | ||
], Link::serialize([ | ||
'link serialized' => $link, | ||
'title' => 'My user', | ||
])); | ||
} | ||
|
||
public function testSerializeNestedArrayWithLinkSuccessfully() | ||
{ | ||
$link = new UserLink([ | ||
'link' => 'http://example.com/users/4', | ||
'title' => 'User 4', | ||
]); | ||
|
||
$this->assertEquals([ | ||
'link serialized' => [ | ||
'href' => [ | ||
'manager' => [ | ||
'title' => 'User 4', | ||
'link' => 'http://example.com/users/4' | ||
]] | ||
], | ||
'title' => ['href' => 'My user'], | ||
], | ||
Link::serialize([ | ||
'link serialized' => [ | ||
'manager' => $link | ||
], | ||
'title' => 'My user', | ||
])); | ||
} | ||
|
||
public function testSerializeArrayWithNotaLinkClassesSuccessfully() | ||
{ | ||
$notALink = new NotALink([ | ||
'fakeName' => 'John', | ||
]); | ||
|
||
$this->assertEquals([ | ||
'this is not a link' => ['href' => $notALink], | ||
], Link::serialize([ | ||
'this is not a link' => $notALink, | ||
])); | ||
} | ||
} | ||
|
||
class UserLink extends Link | ||
{ | ||
/** @var string */ | ||
public $link; | ||
|
||
/** @var string */ | ||
public $title; | ||
} | ||
|
||
class NotALink extends BaseObject | ||
{ | ||
/** @var string */ | ||
public $fakeName; | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's refactor this method to a recursive call instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you referring to line 66(or maybe the whole method)?
I'd replace the second loop with this recursive call
$link = self::serialize($link);
in order to remove it