Skip to content
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

Unable to run Model Test #204

Closed
pareshchouhan opened this issue Aug 25, 2017 · 1 comment
Closed

Unable to run Model Test #204

pareshchouhan opened this issue Aug 25, 2017 · 1 comment

Comments

@pareshchouhan
Copy link

I was trying out Model testing so I created this model

<?php


class User_model extends CI_Model {

	public $table_name;

	public function __consturct() {
		parent::__construct();
		$this->load->database();
		$this->table_name = 'users';
	}

	public function insertUser($user) {
		$status = $this->db->insert($this->table_name, $user);
		if($status) {
			return $this->db->insert_id();
		} {
			return NULL;
		}

	}

	public function getUserById($id) {
		$this->db->where('id', $id);
		$this->db->get($this->table_name);
		foreach($query->result() as $row) {
			return $row;
		}

		return NULL;
	}

}

Model Tests are

<?

class User_Model_run_test extends TestCase {

	public function setUp() {
	}

	public function test_user() {
		$user = $this->newModel('User_Model');
		$id = $user->insertUser([
			'name' => 'XYZ',
			'email' => '[email protected]',
			'status' => 1
		]);
		//expected and actual
		//assert $id not NULL
		$this->assertNotEquals(NULL, $id);

		$userData = $user->getUserById($id);
		//assert user data not NULL
		$this->assertNotEuals(NULL, $userData);
		// print_r($userData);
	}
}

I have created a seperate database.php in config/testing/ and I am using PHP 7.1.1, CI 3.1.5 and

        "phpunit/phpunit": "6.2",
        "kenjis/ci-phpunit-test": "^0.15.0"

Output when I run phpunit

G:\xampp_php_7\htdocs\codeigniter-test\application\tests>..\vendor\bin\phpunit.bat
<?

class User_Model_run_test extends TestCase {

        public function setUp() {
                // $this->resetInstance();
                // $this->CI->load->model('User_Model');
                // $this->obj = $this->CI->User_Model;
                // $CI =& get_instance();
        }

        public function test_user() {
                $user = $this->newModel('User_Model');
                $id = $user->insertUser([
                        'name' => 'Paresh Chouhan',
                        'email' => '[email protected]',
                        'status' => 1
                ]);
                //expected and actual
                //assert $id not NULL
                $this->assertNotEquals(NULL, $id);

                $userData = $user->getUserById($id);
                //assert user data not NULL
                $this->assertNotEuals(NULL, $userData);
                // print_r($userData);
        }

}

PHPUnit 6.2.0 by Sebastian Bergmann and contributors.

Error:         No code coverage driver is available

...                                                                 3 / 3 (100%) <-- this should be 4, these 3 are default tests in Welcome_test.php.

Time: 4.11 seconds, Memory: 4.00MB

OK (3 tests, 3 assertions)
@pareshchouhan
Copy link
Author

missing <?php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant