{"action":"opened","issue":{"url":"https://api.github.com/repos/jarektkaczyk/eloquence/issues/219","repository_url":"https://api.github.com/repos/jarektkaczyk/eloquence","labels_url":"https://api.github.com/repos/jarektkaczyk/eloquence/issues/219/labels{/name}","comments_url":"https://api.github.com/repos/jarektkaczyk/eloquence/issues/219/comments","events_url":"https://api.github.com/repos/jarektkaczyk/eloquence/issues/219/events","html_url":"https://github.com/jarektkaczyk/eloquence/issues/219","id":297048610,"number":219,"title":"Memory leak when calling toArray() on a saved model","user":{"login":"jsdtaylor","id":15832750,"avatar_url":"https://avatars0.githubusercontent.com/u/15832750?v=4","gravatar_id":"","url":"https://api.github.com/users/jsdtaylor","html_url":"https://github.com/jsdtaylor","followers_url":"https://api.github.com/users/jsdtaylor/followers","following_url":"https://api.github.com/users/jsdtaylor/following{/other_user}","gists_url":"https://api.github.com/users/jsdtaylor/gists{/gist_id}","starred_url":"https://api.github.com/users/jsdtaylor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsdtaylor/subscriptions","organizations_url":"https://api.github.com/users/jsdtaylor/orgs","repos_url":"https://api.github.com/users/jsdtaylor/repos","events_url":"https://api.github.com/users/jsdtaylor/events{/privacy}","received_events_url":"https://api.github.com/users/jsdtaylor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-14T10:43:13Z","updated_at":"2018-02-14T10:43:13Z","closed_at":null,"author_association":"NONE","body":"When writing some API tests for a mapped model, I decided to:\r\n\r\n- use a factory to save a model\r\n- GET the resource using its ID\r\n- compare the model's mapped attributes with the json response\r\n\r\nWhen calling `$model->toArray()` I get OOM errors every time:\r\n\r\n```php\r\n$transaction = factory(Transaction::class)->create([\r\n    'user_id' => $I->user->id,\r\n]);\r\n$I->sendGET('api/v1/transactions/'.$transaction->id);\r\n$I->seeResponseCodeIs(HttpCode::OK);\r\n$I->seeResponseContainsJson($transaction->toArray());\r\n```\r\n\r\n```sh\r\nPHP Fatal error:  Allowed memory size of 2097152000 bytes exhausted (tried to allocate 20480 bytes) in /\r\nvar/www/html/vendor/sofa/hookable/src/Hookable.php on line 261\r\nPHP Fatal error:  Allowed memory size of 2097152000 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/codeception/codecep\r\ntion/src/Codeception/Subscriber/ErrorHandler.php on line 96\r\n```\r\n\r\nI was really stumped, but when I fetched the model again, everything worked fine:\r\n\r\n```php\r\n$transaction = factory(Transaction::class)->create([\r\n    'user_id' => $I->user->id,\r\n]);\r\n\r\n# refetch Transaction model\r\n$transaction = Transaction::findOrFail($transaction->id)->first();\r\n\r\n$I->sendGET('api/v1/transactions/'.$transaction->id);\r\n$I->seeResponseCodeIs(HttpCode::OK);\r\n$I->seeResponseContainsJson($transaction->toArray());\r\n\r\n# print memory usage\r\necho \"\\n\".format_byte_size(memory_get_usage());\r\n```\r\n\r\n```sh\r\n26.79 mb\r\n```"}}
{"actor":{"display_login":"jsdtaylor"}}