{"action":"closed","issue":{"url":"https://api.github.com/repos/kenjis/ci-phpunit-test/issues/122","repository_url":"https://api.github.com/repos/kenjis/ci-phpunit-test","labels_url":"https://api.github.com/repos/kenjis/ci-phpunit-test/issues/122/labels{/name}","comments_url":"https://api.github.com/repos/kenjis/ci-phpunit-test/issues/122/comments","events_url":"https://api.github.com/repos/kenjis/ci-phpunit-test/issues/122/events","html_url":"https://github.com/kenjis/ci-phpunit-test/issues/122","id":158959592,"number":122,"title":"Using a test database.","user":{"login":"lesfleurs","id":10000948,"avatar_url":"https://avatars.githubusercontent.com/u/10000948?v=3","gravatar_id":"","url":"https://api.github.com/users/lesfleurs","html_url":"https://github.com/lesfleurs","followers_url":"https://api.github.com/users/lesfleurs/followers","following_url":"https://api.github.com/users/lesfleurs/following{/other_user}","gists_url":"https://api.github.com/users/lesfleurs/gists{/gist_id}","starred_url":"https://api.github.com/users/lesfleurs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lesfleurs/subscriptions","organizations_url":"https://api.github.com/users/lesfleurs/orgs","repos_url":"https://api.github.com/users/lesfleurs/repos","events_url":"https://api.github.com/users/lesfleurs/events{/privacy}","received_events_url":"https://api.github.com/users/lesfleurs/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/kenjis/ci-phpunit-test/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-06-07T15:53:54Z","updated_at":"2016-06-08T06:44:53Z","closed_at":"2016-06-08T06:44:53Z","body":"Maybe i am going about this all wrong and should mock out my models instead. Currently I have  two databases on my local server, one which is being used just for tests, i have the following code in testcase.php that switches to the test database before running any tests.\r\n\r\n```\r\nclass TestCase extends CIPHPUnitTestCase\r\n{\r\n    protected $_class = 'TestCase';\r\n    protected function setUp()\r\n    {\r\n        $this->resetInstance();\r\n        $this->CI->db->db_select($db);\r\n        $this->db = $this->CI->db;\r\n        $this->CI->load->library('environment');\r\n        $this->testEnvironment = $this->CI->environment;\r\n        $this->users = $this->testEnvironment->setUpTestEnvironment($this->CI);\r\n    }\r\n}\r\n```\r\n\r\n\r\n```\r\nclass Login_test extends TestCase\r\n{\r\n    protected $_class = 'Login_test';\r\n    public function test_login()\r\n    {\r\n        $loginresponse = $this->request('POST', 'main/login', array(\r\n            'email' => 'johndoe@galaxy.al',\r\n            'password' => 'YodelGrate',\r\n            'submit' => true));\r\n        $this->assertRedirect('profile');\r\n        $this->assertNotNull($this->CI->session->userdata('user_id'));\r\n    }\r\n}\r\n```\r\n\r\ntest environment library creates test users and other required test stubs, i have a test that verifies that the users and other objects are created and that works fine, my issue is when i try to simulate a test to login using one of the test users, it appears that the default database is being used instead of the test database and the login test fails. Using a user in the default database causes the login test to pass however. How do i ensure that the test database is used throughout when the tests are running? \r\n"}}
{"actor":{"display_login":"lesfleurs"}}