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
Implementing __set_state for CakeRoute #4953
Conversation
It helps the applications to cache the routes using var_export when possible.
PHPCS failures, and a possible bs failure in PG. |
cd70ba4
to
f7320cd
Compare
PHPCS fixed. The issue with PG is happening for all builds on 2.6 derived branch. |
I blame @lorenzo :P |
Why use var_export instead of serialize() ? |
@lorenzo That's a good question. My brain was half-off and I copied the solution from FastRoute (https://github.com/nikic/FastRoute/blob/master/src/functions.php#L54-L58) |
Ah well, I see one reason to do it like that. If you do it like fast route, the opcache will optimise that file, whereas doing it with serialize() will not allow that. |
That's true. I haven't thought about the opcache, but makes sense. Also, probably if you have lots of routes it will generate a gigantic string and it will take a while for the php to parse it before build the objects. |
* | ||
* @return void | ||
*/ | ||
public function testSetState() { |
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.
Maybe I'm caffeine deficient, but this test isn't testing setState. Whether the function CakeRoute::__set_state
is defined or not this test will pass, it's not really testing anything at all.
The result of calling CakeRoute::__set_state
is what should be being tested.
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 caffeinated now? :)
The test uses var_export()
which will dump the result like CakeRoute::__set_state(['key' => 'value'])
. So doing an eval()
of it will trigger the code I implemented and generate a new object. PHPUnit assertEquals
compare the object generate manually with the object generated from the CakeRoute::__set_state()
, attribute by attribute.
That makes sense? I can make a simpler test just generating an object from calling the __set_state
directly, but I thought this way would cover more the real usage of __set_state
.
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.
Ah I see =).
I'd still prefer to see a more simple, explicit test, but otherwise a comment to explain what the test is doing would be a great help.
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.
Having a test that doesn't use eval() would be nice 😄
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.
Tests updated.
It removes the eval and test the __set_state more explicitly.
d9dbc79
to
6171ef6
Compare
Looks good to me 👍 |
👍 |
Implementing __set_state for CakeRoute
It helps the applications to cache the routes using var_export when possible.