Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DateTime normalization bug with GetSetMethodNormalizer() when using HHVM #10229

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
gitnik opened this issue Feb 10, 2014 · 17 comments
Closed

DateTime normalization bug with GetSetMethodNormalizer() when using HHVM #10229

gitnik opened this issue Feb 10, 2014 · 17 comments

Comments

@gitnik
Copy link

gitnik commented Feb 10, 2014

I have the following array of entities:

array(2) {
  [0]=>
  object(JustNik\CoreBundle\Entity\Entry)#2955 (4) {
    ["id":protected]=>
    int(1)
    ["title":protected]=>
    string(7) "title 1"
    ["date":protected]=>
    object(DateTime)#2956 (0) {
    }
    ["markdown":protected]=>
    NULL
  }
  [1]=>
  object(JustNik\CoreBundle\Entity\Entry)#2967 (4) {
    ["id":protected]=>
    int(2)
    ["title":protected]=>
    string(7) "title 2"
    ["date":protected]=>
    object(DateTime)#2968 (0) {
    }
    ["markdown":protected]=>
    NULL
  }
}

When I try to normalize one element wth the following code:

$normalizers = array(new GetSetMethodNormalizer());
$serializer = new Serializer($normalizers);
$serializer->normalize($entries[0]);

I get this (obviously shortened)

array(4) {
  ["id"]=>
  int(1)
  ["title"]=>
  string(7) "title 1"
  ["date"]=>
  array(4) {
    ["lastErrors"]=>
    array(4) {
      ["warning_count"]=>
      int(0)
      ["warnings"]=>
      array(0) {
      }
      ["error_count"]=>
      int(0)
      ["errors"]=>
      array(0) {
      }
    }
    ["offset"]=>
    int(3600)
    ["timestamp"]=>
    int(1392058587)
    ["timezone"]=>
    array(3) {
      ["location"]=>
      array(4) {
        ["country_code"]=>
        string(0) ""
        ["latitude"]=>
        float(0)
        ["longitude"]=>
        float(0)
        ["comments"]=>
        NULL
      }
      ["name"]=>
      string(13) "Europe/Berlin"
      ["transitions"]=>
      array(144) {
        [0]=>
        array(5) {
          ["ts"]=>
          int(-1693706400)
          ["time"]=>
          string(24) "1916-05-01T00:00:00+0200"
          ["offset"]=>
          int(7200)
          ["isdst"]=>
          bool(true)
          ["abbr"]=>
          string(4) "CEST"
        }
        [1]=>
        array(5) {
          ["ts"]=>
          int(-1680483600)
          ["time"]=>
          string(24) "1916-10-01T00:00:00+0100"
          ["offset"]=>
          int(3600)
          ["isdst"]=>
          bool(false)
          ["abbr"]=>
          string(3) "CET"
        }
        ..... more entries which times keep increasing with every entry
        [143]=>
        array(5) {
          ["ts"]=>
          int(2140045200)
          ["time"]=>
          string(24) "2037-10-25T02:00:00+0100"
          ["offset"]=>
          int(3600)
          ["isdst"]=>
          bool(false)
          ["abbr"]=>
          string(3) "CET"
        }
      }
    }
  }
  ["markdown"]=>
  NULL
}

I'm not sure whether this is a bug or I just missed a configuration option which causes this behaviour

@gitnik
Copy link
Author

gitnik commented Feb 10, 2014

OK weird.... I didn't do anything and now all of a sudden this is no longer happening. I will however report back when I experience this again

@jakzal
Copy link
Contributor

jakzal commented Feb 10, 2014

Closing for now. Feel free to reopen when you have more details on what you're trying to achieve, what have you tried and what's going wrong.

@jakzal jakzal closed this as completed Feb 10, 2014
@gitnik
Copy link
Author

gitnik commented Feb 10, 2014

Can you reopen this again? It's happening again,,,

What do you mean with more details? I'm trying to normalize an entity into an array and it doesn't work

@jakzal
Copy link
Contributor

jakzal commented Feb 10, 2014

You'll need to provide more details on how to reproduce it (more than "it doesn't work"). I just tested a simple scenario and it works fine for me. Would you mind forking the Symfony Standard Edition and reproducing your issue on a branch? Would help debugging.

@jakzal jakzal reopened this Feb 10, 2014
@gitnik
Copy link
Author

gitnik commented Feb 10, 2014

Just found out that this is an issue related to HHVM. When I run my tests with php, it works fine.

@gitnik
Copy link
Author

gitnik commented Feb 10, 2014

OK what's weird is that when I use the same code on my webserver (also running HHVM) it works like a charm.

@jakzal
Copy link
Contributor

jakzal commented Feb 10, 2014

Here's how I tried to reproduce it: https://github.com/jakzal/symfony-standard/compare/issue10229 (test case is just to run it on travis with hhvm).

Locally everything is fine (also with hhvm).

Take a look at my branch please (look for SerializerController): https://github.com/jakzal/symfony-standard/tree/issue10229 we need a reproducible scenario.

@gitnik
Copy link
Author

gitnik commented Feb 10, 2014

I get the feeling that is to due to sqlite since that's what I'm using within my tests. I will open a fork in 5 minutes

@gitnik
Copy link
Author

gitnik commented Feb 10, 2014

alright here we go:
https://github.com/gitnik/symfony-standard

@gitnik
Copy link
Author

gitnik commented Feb 10, 2014

I also tried to debug it with hhvm --mode debug but debugging on the cli isn't exactly the greatest thing ever

@gitnik
Copy link
Author

gitnik commented Feb 10, 2014

Tried to use a mysql database for testing, but the result is still the same. This mean we can exclude that it's either doctrine's/sqlite's fault

@gitnik
Copy link
Author

gitnik commented Feb 10, 2014

Is there a way to run phpunit tests in a different environment other than "testing"? since it's only happening in the "testing" environment that might help us figure out where the problem lies

@cordoval
Copy link
Contributor

the bug is real, i am using mongodb and having this problem. It is reproducible and @jakzal you should add a service definition and configure camelcase attributes, @jakzal could you please add confirmed tag?

working on it now, i will launch a PR if i can 👶

@cordoval
Copy link
Contributor

@gitnik did you try the setCallbacks? cc/ @jakzal

@gitnik
Copy link
Author

gitnik commented Mar 20, 2014

No

@cordoval
Copy link
Contributor

i will confirm before you can close this, 👶

@cordoval
Copy link
Contributor

confirmed: it works with callbacks. let's close this. @fabpot

weaverryan added a commit to symfony/symfony-docs that referenced this issue Apr 2, 2014
… (cordoval)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #3701).

Discussion
----------

[Serializer] add documentation for serializer callbacks

related symfony/symfony#10229

| Q             | A                   |
| ---           | ---                 |
| Doc fix?      | no                  |
| New docs?     | yes                 |
| Applies to    | 2.3+                |
| Fixed tickets | self 👶      |
| License       | CC-ASA 3.0 Unported |

 Sent using [Gush](https://github.com/gushphp/gush)

Commits
-------

b865b40 add comma madness and lowercasing W
efe2029 plug new revision
eabdbd0 add serializer set callback documentation
@fabpot fabpot closed this as completed Apr 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants