{"action":"created","issue":{"url":"https://api.github.com/repos/jarektkaczyk/laravel-kahlan/issues/2","repository_url":"https://api.github.com/repos/jarektkaczyk/laravel-kahlan","labels_url":"https://api.github.com/repos/jarektkaczyk/laravel-kahlan/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/jarektkaczyk/laravel-kahlan/issues/2/comments","events_url":"https://api.github.com/repos/jarektkaczyk/laravel-kahlan/issues/2/events","html_url":"https://github.com/jarektkaczyk/laravel-kahlan/issues/2","id":175971277,"number":2,"title":"Using 'DatabaseTransactions' and `toThrow` matcher","user":{"login":"pluxain","id":2682877,"avatar_url":"https://avatars.githubusercontent.com/u/2682877?v=3","gravatar_id":"","url":"https://api.github.com/users/pluxain","html_url":"https://github.com/pluxain","followers_url":"https://api.github.com/users/pluxain/followers","following_url":"https://api.github.com/users/pluxain/following{/other_user}","gists_url":"https://api.github.com/users/pluxain/gists{/gist_id}","starred_url":"https://api.github.com/users/pluxain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pluxain/subscriptions","organizations_url":"https://api.github.com/users/pluxain/orgs","repos_url":"https://api.github.com/users/pluxain/repos","events_url":"https://api.github.com/users/pluxain/events{/privacy}","received_events_url":"https://api.github.com/users/pluxain/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-09T09:52:33Z","updated_at":"2016-09-09T11:15:34Z","closed_at":"2016-09-09T11:15:34Z","body":"I don't know it this is an issue, but this is something I need to understand at least.\r\n\r\nUsing the Laravel Testing, this works:\r\n```php\r\nclass BrandTest extends TestCase\r\n{\r\n    use DatabaseTransactions;\r\n\r\n    /** @test */\r\n    public function its_name_is_unique()\r\n    {\r\n        App\\Brand::create(['name' => 'unique']);\r\n        $this->setExpectedException(Illuminate\\Database\\QueryException);\r\n        App\\Brand::create(['name' => 'unique']);\r\n        $this->assertEquals(1, App\\Brand::count());\r\n    }\r\n\r\n}\r\n```\r\nUsing Laravel Kahlan testing (thanks to your package), this does not work :\r\n``` php\r\ndescribe('Brand Model', function() {\r\n    \r\n    using('DatabaseTransactions', function() {\r\n   \r\n        it('has a unique name', function() {\r\n            App\\Brand::create(['name' => 'unique']);\r\n            expect(function() { App\\Brand::create(['name' => 'unique']); })->toThrow();\r\n            expect(App\\Brand::count())->toBe(1);\r\n        });\r\n    });\r\n});\r\n```\r\n\r\nI get this error with Laravel/Kahlan\r\n```\r\nBrand Model\r\n  Following specs run using: DatabaseTransactions ⤵\r\n    ✘ it has a unique name\r\n      an uncaught exception has been thrown in \r\n      `/vendor/laravel/framework/src/Illuminate/Database/Connection.php` line 761\r\n      \r\n      message:`Illuminate\\Database\\QueryException` Code(25P02) with message \r\n      \"SQLSTATE[25P02]: In failed sql transaction: 7 ERROR:  current transaction is aborted,\r\n      commands ignored until end of transaction block (SQL: select count(*) as aggregate \r\n      from \\\"brands\\\")\"\r\n```\r\n\r\nI understand as an error is thrown the DB transaction might be aborted as explains the message, and then the next 'count' request is rejected, but why does it work with PHPUnit and not Kahlan."},"comment":{"url":"https://api.github.com/repos/jarektkaczyk/laravel-kahlan/issues/comments/245885934","html_url":"https://github.com/jarektkaczyk/laravel-kahlan/issues/2#issuecomment-245885934","issue_url":"https://api.github.com/repos/jarektkaczyk/laravel-kahlan/issues/2","id":245885934,"user":{"login":"pluxain","id":2682877,"avatar_url":"https://avatars.githubusercontent.com/u/2682877?v=3","gravatar_id":"","url":"https://api.github.com/users/pluxain","html_url":"https://github.com/pluxain","followers_url":"https://api.github.com/users/pluxain/followers","following_url":"https://api.github.com/users/pluxain/following{/other_user}","gists_url":"https://api.github.com/users/pluxain/gists{/gist_id}","starred_url":"https://api.github.com/users/pluxain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pluxain/subscriptions","organizations_url":"https://api.github.com/users/pluxain/orgs","repos_url":"https://api.github.com/users/pluxain/repos","events_url":"https://api.github.com/users/pluxain/events{/privacy}","received_events_url":"https://api.github.com/users/pluxain/received_events","type":"User","site_admin":false},"created_at":"2016-09-09T11:15:34Z","updated_at":"2016-09-09T11:15:34Z","body":"@jarektkaczyk thanks for your time.\r\n\r\nI am sure the first `create(['name' => 'unique'])` is not causing the error : the database is fresh and it is the only test I run.\r\n\r\nBut what I found out is that in the PHPUnit test, the assertions after the error is thrown are not met. So in fact it does not \"work\", it is just not executed.\r\n\r\nI still have the error with Laravel/Kahlan. I can live without testing the count but it is really difficult to test the `Illuminate\\Database\\QueryException` the unique constraint throws in the `toThrow()` matcher. I guess I will have to make a Custom Matcher then...\r\n\r\nThanks for your plugin anyway"}}
{"actor":{"display_login":"pluxain"}}