We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
PHPUnit 9.5.25 #StandWithUkraine PHP 7.3.29 with Xdebug 3.0.0
How to mock this CI function with all DB codes as well
function update($sessionActiveUserId = null) { $logTitle = "update usertype"; $data = $methodResponseObj = array(); try { array_walk($_POST, 'trim'); foreach ($_POST as $k => $r) { if ($k === 'id') { ${$k} = base64_decode($r); $data[$k] = base64_decode($r); } } $this->db->where('id', $id); if ($this->db->update('tbl_demo', $data)) { $this->logArray[] = helperFunction($logTitle, $this->db->last_query()); $methodResponseObj = array( 'status' => true, 'type' => W_STATUS_SUCCESS, 'msg' => 'Usertype Updated Successfully.' ); } else { $this->traitFunction1($logTitle); } } catch (Exception $e) { $methodResponseObj = $this->traitFunction2($e, $logTitle); } return $methodResponseObj; }
I started to write test case but somehow I am lost not sure I am going in right direction
<?php class Project_Model_Test extends TestCase { /** @var Project_Model $modelObj */ protected $modelObj; /** @var \CI_Model $CI */ protected $CI; /** @var \CI_DB_mysqli_driver $dbMock */ protected $dbMock; /** * Set up * * @return void */ public function setUp(): void { $this->resetInstance(); $this->CI->load->model('Project_Model'); $this->modelObj = $this->CI->Project_Model; $this->dbMock = $this->getMockBuilder('CI_DB_query_builder') ->disableOriginalConstructor() ->getMock(); } public function testUpdateUsertype() { $actual = $this->modelObj->update(); // // Set up a mock database connection $dbMock = $this->getMockBuilder('CI_DB_query_builder') ->disableOriginalConstructor() ->getMock(); // Expect the 'where' and 'update' methods to be called with specific arguments $dbMock->expects($this->once()) ->method('where') ->with('id', base64_decode('example_id')) ->will($this->returnValue(false)); } }
Thanks is advance!!!
The text was updated successfully, but these errors were encountered:
See https://github.com/kenjis/ci-phpunit-test/blob/3.x/docs/HowToWriteTests.md#using-phpunit-mock-objects and https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/3.x/application/tests/models/Category_model_mocking_db_test.php
Sorry, something went wrong.
No branches or pull requests
PHPUnit 9.5.25 #StandWithUkraine
PHP 7.3.29 with Xdebug 3.0.0
How to mock this CI function with all DB codes as well
I started to write test case but somehow I am lost not sure I am going in right direction
Thanks is advance!!!
The text was updated successfully, but these errors were encountered: