You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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)
The text was updated successfully, but these errors were encountered:
I was trying out Model testing so I created this model
Model Tests are
I have created a seperate database.php in config/testing/ and I am using PHP 7.1.1, CI 3.1.5 and
Output when I run phpunit
The text was updated successfully, but these errors were encountered: