{"action":"created","comment":{"url":"https://api.github.com/repos/Codeception/Codeception/pulls/comments/33234777","id":33234777,"diff_hunk":"@@ -181,22 +186,106 @@ To enable the database functionality in the unit tests please make sure the `Db`\n The database will be cleaned and populated after each test, as it happens for acceptance and functional tests.\n If it's not your required behavior, please change the settings of `Db` module for the current suite.\n \n+### Interacting with the Framework\n+\n+Probably you should not access your database directly if your project already uses ORM for database interactions.\n+Why not use the ORM directly inside your tests? Let's try to write a test using Laravel's ORM Eloquent, for this we need configured Laravel5 module. We won't need its web interaction methods like `amOnPage` or `see`, so let's enable only ORM part of it:\n+\n+```yaml\n+class_name: UnitTester\n+modules:\n+    enabled:\n+        - Asserts\n+        - Laravel5:\n+            part: ORM\n+        - \\Helper\\Unit\n+```\n+\n+We included Laravel5 module as we did for functional testing. Let's see how we can use it for integration tests:\n+\n+```php\n+<?php\n+function testUserNameCanBeChanged()\n+{\n+    // create a user from framework, user will be deleted after the test\n+    $id = $this->tester->haveRecord('users', ['name' => 'miles']);\n+    // access model\n+    $user = User::find($id);\n+    $user->setName('bill');\n+    $user->save();\n+    $this->assertEquals('bill', $user->getName());\n+    // verify data was saved using framework methods\n+    $this->tester->seeRecord('users', ['name' => 'bill']);\n+    $this->tester->dontSeeRecord('users', ['name' => 'miles']);\n+}\n+?>\n+```\n+\n+The very similar approach can be used to all frameworks that have ORM implementing ActiveRecord pattern.\n+These are Yii2 and Phalcon, they have methods `haveRecord`, `seeRecord`, `dontSeeRecord` working in the same manner. They also should be included with specifying `part: ORM` in order to not use functional testing actions.\n+\n+In case you are using Symfony2 with Doctrine you may not enable Symfony2 itself but use only Doctrine2 only:\n+\n+```yaml\n+class_name: UnitTester\n+modules:\n+    enabled:\n+        - Asserts\n+        - Doctrine2:\n+            depends: Symfony2\n+        - \\Helper\\Unit\n+```\n+\n+In this case you can use methods from Doctrine2 module, while Doctrine itself uses Symfony2 module to establish connection to database. In this case a test may look like:\n+\n+```php\n+<?php\n+function testUserNameCanBeChanged()\n+{\n+    // create a user from framework, user will be deleted after the test\n+    $id = $this->tester->haveInRepository('Acme\\DemoBundle\\Entity\\User', ['name' => 'miles']);\n+    // get entity manager by accessing module\n+    $em = $this->getModule('Doctrine2')->em;\n+    // get real user\n+    $user = $em->find('Acme\\DemoBundle\\Entity\\User', $id);\n+    $user->setName('bill');\n+    $em->persist($user);\n+    $em->flush();\n+    $this->assertEquals('bill', $user->getName());\n+    // verify data was saved using framework methods\n+    $this->tester->seeInRepository('Acme\\DemoBundle\\Entity\\User', ['name' => 'bill']);\n+    $this->tester->dontSeeInRepository('Acme\\DemoBundle\\Entity\\User', ['name' => 'miles']);\n+}\n+?>\n+```\n+\n+In both examples you should not be worried about the data persistance between tests. \n+Doctrine2 module as well as Laravel4 module will clean up created data at the end of a test. \n+This is done by wrapping a test in a transaction and rolling it back afterwards. \n+\n ### Accessing Module\n \n Codeception allows you to access properties and methods of all modules defined for this suite. Unlike using the UnitTester class for this purpose, using module directly grants you access to all public properties of that module.\n \n-For example, if you use `Symfony2` module, here is the way you can access Symfony container:\n+We already demonstrated this case in previous code piece where we accessed Entity Manager from a Doctrine2 module","path":"docs/05-UnitTests.md","position":109,"original_position":109,"commit_id":"275ee237be09f31d405a513dd363e76a2d20d338","original_commit_id":"275ee237be09f31d405a513dd363e76a2d20d338","user":{"login":"pfaocle","id":216767,"avatar_url":"https://avatars.githubusercontent.com/u/216767?v=3","gravatar_id":"","url":"https://api.github.com/users/pfaocle","html_url":"https://github.com/pfaocle","followers_url":"https://api.github.com/users/pfaocle/followers","following_url":"https://api.github.com/users/pfaocle/following{/other_user}","gists_url":"https://api.github.com/users/pfaocle/gists{/gist_id}","starred_url":"https://api.github.com/users/pfaocle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfaocle/subscriptions","organizations_url":"https://api.github.com/users/pfaocle/orgs","repos_url":"https://api.github.com/users/pfaocle/repos","events_url":"https://api.github.com/users/pfaocle/events{/privacy}","received_events_url":"https://api.github.com/users/pfaocle/received_events","type":"User","site_admin":false},"body":"s/in previous code piece/in a previous code example/","created_at":"2015-06-25T09:01:06Z","updated_at":"2015-06-25T09:01:06Z","html_url":"https://github.com/Codeception/Codeception/pull/1878#discussion_r33234777","pull_request_url":"https://api.github.com/repos/Codeception/Codeception/pulls/1878","_links":{"self":{"href":"https://api.github.com/repos/Codeception/Codeception/pulls/comments/33234777"},"html":{"href":"https://github.com/Codeception/Codeception/pull/1878#discussion_r33234777"},"pull_request":{"href":"https://api.github.com/repos/Codeception/Codeception/pulls/1878"}}},"pull_request":{"url":"https://api.github.com/repos/Codeception/Codeception/pulls/1878","id":34223050,"html_url":"https://github.com/Codeception/Codeception/pull/1878","diff_url":"https://github.com/Codeception/Codeception/pull/1878.diff","patch_url":"https://github.com/Codeception/Codeception/pull/1878.patch","issue_url":"https://api.github.com/repos/Codeception/Codeception/issues/1878","number":1878,"state":"closed","locked":false,"title":"Updated Guides for Codeception 2.1","user":{"login":"DavertMik","id":220264,"avatar_url":"https://avatars.githubusercontent.com/u/220264?v=3","gravatar_id":"","url":"https://api.github.com/users/DavertMik","html_url":"https://github.com/DavertMik","followers_url":"https://api.github.com/users/DavertMik/followers","following_url":"https://api.github.com/users/DavertMik/following{/other_user}","gists_url":"https://api.github.com/users/DavertMik/gists{/gist_id}","starred_url":"https://api.github.com/users/DavertMik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavertMik/subscriptions","organizations_url":"https://api.github.com/users/DavertMik/orgs","repos_url":"https://api.github.com/users/DavertMik/repos","events_url":"https://api.github.com/users/DavertMik/events{/privacy}","received_events_url":"https://api.github.com/users/DavertMik/received_events","type":"User","site_admin":false},"body":"Docs were updated and in order to reflect new features of Codeception as well as focus on best usage practices, and demonstrate some popular use cases. \r\n\r\nChapters were reordered Modules and Helpers were rewritten into more general chapter \"Reusing Test Code\" with Helpers, Actors, PageObjects, and StepObjects described. This chapter goes after Acceptance/Functional/Unit tests, that's why those chapters moved one position up in the order.\r\n\r\nPlease help by reviewing the text, and finding stupid typos and strange language constructs :)\r\nYour help on documentation improvement is highly appreciated!\r\n","created_at":"2015-04-28T00:12:33Z","updated_at":"2015-06-25T09:01:06Z","closed_at":"2015-05-01T12:21:46Z","merged_at":"2015-05-01T12:21:46Z","merge_commit_sha":"8b85351c715da1e51ac8e6d8baca09e60de81ad4","assignee":null,"milestone":{"url":"https://api.github.com/repos/Codeception/Codeception/milestones/6","html_url":"https://github.com/Codeception/Codeception/milestones/2.1","labels_url":"https://api.github.com/repos/Codeception/Codeception/milestones/6/labels","id":713276,"number":6,"title":"2.1","description":null,"creator":{"login":"DavertMik","id":220264,"avatar_url":"https://avatars.githubusercontent.com/u/220264?v=3","gravatar_id":"","url":"https://api.github.com/users/DavertMik","html_url":"https://github.com/DavertMik","followers_url":"https://api.github.com/users/DavertMik/followers","following_url":"https://api.github.com/users/DavertMik/following{/other_user}","gists_url":"https://api.github.com/users/DavertMik/gists{/gist_id}","starred_url":"https://api.github.com/users/DavertMik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavertMik/subscriptions","organizations_url":"https://api.github.com/users/DavertMik/orgs","repos_url":"https://api.github.com/users/DavertMik/repos","events_url":"https://api.github.com/users/DavertMik/events{/privacy}","received_events_url":"https://api.github.com/users/DavertMik/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":20,"state":"open","created_at":"2014-07-08T02:22:45Z","updated_at":"2015-05-01T12:21:46Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/Codeception/Codeception/pulls/1878/commits","review_comments_url":"https://api.github.com/repos/Codeception/Codeception/pulls/1878/comments","review_comment_url":"https://api.github.com/repos/Codeception/Codeception/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Codeception/Codeception/issues/1878/comments","statuses_url":"https://api.github.com/repos/Codeception/Codeception/statuses/275ee237be09f31d405a513dd363e76a2d20d338","head":{"label":"Codeception:docs2.1","ref":"docs2.1","sha":"275ee237be09f31d405a513dd363e76a2d20d338","user":{"login":"Codeception","id":1288753,"avatar_url":"https://avatars.githubusercontent.com/u/1288753?v=3","gravatar_id":"","url":"https://api.github.com/users/Codeception","html_url":"https://github.com/Codeception","followers_url":"https://api.github.com/users/Codeception/followers","following_url":"https://api.github.com/users/Codeception/following{/other_user}","gists_url":"https://api.github.com/users/Codeception/gists{/gist_id}","starred_url":"https://api.github.com/users/Codeception/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Codeception/subscriptions","organizations_url":"https://api.github.com/users/Codeception/orgs","repos_url":"https://api.github.com/users/Codeception/repos","events_url":"https://api.github.com/users/Codeception/events{/privacy}","received_events_url":"https://api.github.com/users/Codeception/received_events","type":"Organization","site_admin":false},"repo":{"id":2880469,"name":"Codeception","full_name":"Codeception/Codeception","owner":{"login":"Codeception","id":1288753,"avatar_url":"https://avatars.githubusercontent.com/u/1288753?v=3","gravatar_id":"","url":"https://api.github.com/users/Codeception","html_url":"https://github.com/Codeception","followers_url":"https://api.github.com/users/Codeception/followers","following_url":"https://api.github.com/users/Codeception/following{/other_user}","gists_url":"https://api.github.com/users/Codeception/gists{/gist_id}","starred_url":"https://api.github.com/users/Codeception/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Codeception/subscriptions","organizations_url":"https://api.github.com/users/Codeception/orgs","repos_url":"https://api.github.com/users/Codeception/repos","events_url":"https://api.github.com/users/Codeception/events{/privacy}","received_events_url":"https://api.github.com/users/Codeception/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Codeception/Codeception","description":"Full-stack testing PHP framework","fork":false,"url":"https://api.github.com/repos/Codeception/Codeception","forks_url":"https://api.github.com/repos/Codeception/Codeception/forks","keys_url":"https://api.github.com/repos/Codeception/Codeception/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Codeception/Codeception/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Codeception/Codeception/teams","hooks_url":"https://api.github.com/repos/Codeception/Codeception/hooks","issue_events_url":"https://api.github.com/repos/Codeception/Codeception/issues/events{/number}","events_url":"https://api.github.com/repos/Codeception/Codeception/events","assignees_url":"https://api.github.com/repos/Codeception/Codeception/assignees{/user}","branches_url":"https://api.github.com/repos/Codeception/Codeception/branches{/branch}","tags_url":"https://api.github.com/repos/Codeception/Codeception/tags","blobs_url":"https://api.github.com/repos/Codeception/Codeception/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Codeception/Codeception/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Codeception/Codeception/git/refs{/sha}","trees_url":"https://api.github.com/repos/Codeception/Codeception/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Codeception/Codeception/statuses/{sha}","languages_url":"https://api.github.com/repos/Codeception/Codeception/languages","stargazers_url":"https://api.github.com/repos/Codeception/Codeception/stargazers","contributors_url":"https://api.github.com/repos/Codeception/Codeception/contributors","subscribers_url":"https://api.github.com/repos/Codeception/Codeception/subscribers","subscription_url":"https://api.github.com/repos/Codeception/Codeception/subscription","commits_url":"https://api.github.com/repos/Codeception/Codeception/commits{/sha}","git_commits_url":"https://api.github.com/repos/Codeception/Codeception/git/commits{/sha}","comments_url":"https://api.github.com/repos/Codeception/Codeception/comments{/number}","issue_comment_url":"https://api.github.com/repos/Codeception/Codeception/issues/comments{/number}","contents_url":"https://api.github.com/repos/Codeception/Codeception/contents/{+path}","compare_url":"https://api.github.com/repos/Codeception/Codeception/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Codeception/Codeception/merges","archive_url":"https://api.github.com/repos/Codeception/Codeception/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Codeception/Codeception/downloads","issues_url":"https://api.github.com/repos/Codeception/Codeception/issues{/number}","pulls_url":"https://api.github.com/repos/Codeception/Codeception/pulls{/number}","milestones_url":"https://api.github.com/repos/Codeception/Codeception/milestones{/number}","notifications_url":"https://api.github.com/repos/Codeception/Codeception/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Codeception/Codeception/labels{/name}","releases_url":"https://api.github.com/repos/Codeception/Codeception/releases{/id}","created_at":"2011-11-30T04:06:44Z","updated_at":"2015-06-25T00:12:13Z","pushed_at":"2015-06-24T23:16:27Z","git_url":"git://github.com/Codeception/Codeception.git","ssh_url":"git@github.com:Codeception/Codeception.git","clone_url":"https://github.com/Codeception/Codeception.git","svn_url":"https://github.com/Codeception/Codeception","homepage":"http://codeception.com","size":64925,"stargazers_count":1559,"watchers_count":1559,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":609,"mirror_url":null,"open_issues_count":211,"forks":609,"open_issues":211,"watchers":1559,"default_branch":"2.0"}},"base":{"label":"Codeception:master","ref":"master","sha":"caa3e5d963720947fb9974a27e9f29d4ada48eac","user":{"login":"Codeception","id":1288753,"avatar_url":"https://avatars.githubusercontent.com/u/1288753?v=3","gravatar_id":"","url":"https://api.github.com/users/Codeception","html_url":"https://github.com/Codeception","followers_url":"https://api.github.com/users/Codeception/followers","following_url":"https://api.github.com/users/Codeception/following{/other_user}","gists_url":"https://api.github.com/users/Codeception/gists{/gist_id}","starred_url":"https://api.github.com/users/Codeception/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Codeception/subscriptions","organizations_url":"https://api.github.com/users/Codeception/orgs","repos_url":"https://api.github.com/users/Codeception/repos","events_url":"https://api.github.com/users/Codeception/events{/privacy}","received_events_url":"https://api.github.com/users/Codeception/received_events","type":"Organization","site_admin":false},"repo":{"id":2880469,"name":"Codeception","full_name":"Codeception/Codeception","owner":{"login":"Codeception","id":1288753,"avatar_url":"https://avatars.githubusercontent.com/u/1288753?v=3","gravatar_id":"","url":"https://api.github.com/users/Codeception","html_url":"https://github.com/Codeception","followers_url":"https://api.github.com/users/Codeception/followers","following_url":"https://api.github.com/users/Codeception/following{/other_user}","gists_url":"https://api.github.com/users/Codeception/gists{/gist_id}","starred_url":"https://api.github.com/users/Codeception/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Codeception/subscriptions","organizations_url":"https://api.github.com/users/Codeception/orgs","repos_url":"https://api.github.com/users/Codeception/repos","events_url":"https://api.github.com/users/Codeception/events{/privacy}","received_events_url":"https://api.github.com/users/Codeception/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Codeception/Codeception","description":"Full-stack testing PHP framework","fork":false,"url":"https://api.github.com/repos/Codeception/Codeception","forks_url":"https://api.github.com/repos/Codeception/Codeception/forks","keys_url":"https://api.github.com/repos/Codeception/Codeception/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Codeception/Codeception/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Codeception/Codeception/teams","hooks_url":"https://api.github.com/repos/Codeception/Codeception/hooks","issue_events_url":"https://api.github.com/repos/Codeception/Codeception/issues/events{/number}","events_url":"https://api.github.com/repos/Codeception/Codeception/events","assignees_url":"https://api.github.com/repos/Codeception/Codeception/assignees{/user}","branches_url":"https://api.github.com/repos/Codeception/Codeception/branches{/branch}","tags_url":"https://api.github.com/repos/Codeception/Codeception/tags","blobs_url":"https://api.github.com/repos/Codeception/Codeception/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Codeception/Codeception/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Codeception/Codeception/git/refs{/sha}","trees_url":"https://api.github.com/repos/Codeception/Codeception/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Codeception/Codeception/statuses/{sha}","languages_url":"https://api.github.com/repos/Codeception/Codeception/languages","stargazers_url":"https://api.github.com/repos/Codeception/Codeception/stargazers","contributors_url":"https://api.github.com/repos/Codeception/Codeception/contributors","subscribers_url":"https://api.github.com/repos/Codeception/Codeception/subscribers","subscription_url":"https://api.github.com/repos/Codeception/Codeception/subscription","commits_url":"https://api.github.com/repos/Codeception/Codeception/commits{/sha}","git_commits_url":"https://api.github.com/repos/Codeception/Codeception/git/commits{/sha}","comments_url":"https://api.github.com/repos/Codeception/Codeception/comments{/number}","issue_comment_url":"https://api.github.com/repos/Codeception/Codeception/issues/comments{/number}","contents_url":"https://api.github.com/repos/Codeception/Codeception/contents/{+path}","compare_url":"https://api.github.com/repos/Codeception/Codeception/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Codeception/Codeception/merges","archive_url":"https://api.github.com/repos/Codeception/Codeception/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Codeception/Codeception/downloads","issues_url":"https://api.github.com/repos/Codeception/Codeception/issues{/number}","pulls_url":"https://api.github.com/repos/Codeception/Codeception/pulls{/number}","milestones_url":"https://api.github.com/repos/Codeception/Codeception/milestones{/number}","notifications_url":"https://api.github.com/repos/Codeception/Codeception/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Codeception/Codeception/labels{/name}","releases_url":"https://api.github.com/repos/Codeception/Codeception/releases{/id}","created_at":"2011-11-30T04:06:44Z","updated_at":"2015-06-25T00:12:13Z","pushed_at":"2015-06-24T23:16:27Z","git_url":"git://github.com/Codeception/Codeception.git","ssh_url":"git@github.com:Codeception/Codeception.git","clone_url":"https://github.com/Codeception/Codeception.git","svn_url":"https://github.com/Codeception/Codeception","homepage":"http://codeception.com","size":64925,"stargazers_count":1559,"watchers_count":1559,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":609,"mirror_url":null,"open_issues_count":211,"forks":609,"open_issues":211,"watchers":1559,"default_branch":"2.0"}},"_links":{"self":{"href":"https://api.github.com/repos/Codeception/Codeception/pulls/1878"},"html":{"href":"https://github.com/Codeception/Codeception/pull/1878"},"issue":{"href":"https://api.github.com/repos/Codeception/Codeception/issues/1878"},"comments":{"href":"https://api.github.com/repos/Codeception/Codeception/issues/1878/comments"},"review_comments":{"href":"https://api.github.com/repos/Codeception/Codeception/pulls/1878/comments"},"review_comment":{"href":"https://api.github.com/repos/Codeception/Codeception/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Codeception/Codeception/pulls/1878/commits"},"statuses":{"href":"https://api.github.com/repos/Codeception/Codeception/statuses/275ee237be09f31d405a513dd363e76a2d20d338"}}}}