Closed sunggun1 closed 3 years ago
@sunggun1
PHP Fatal error: Class 'OFM_COMMON\Tests\Service\Service' not found in D:\refactoring\application_common\tests\controllers\Email_test.php on line 9
How do you load the OFM_COMMON\Tests\Service\Service
class?
Do you have an autoloader for it?
It seems you don't have an autoloader.
@kenjis What is an autoloader? How do I set it? I only call it as namespace... That is impossible? And I can't call model in the Test Code?
I also changed the configuration of bootstrap.php to index.php configuration system_path , APPPATH... everything
I changed Bootstrap.php like this
Then , error exist like this
@sunggun1
What is an autoloader?
PHP does not have class autoloader. You have to write it by yourself. See https://www.php.net/manual/en/language.oop5.autoload.php
Or you can use thrid-party autoloader like Composer autoloader.
@sunggun1 The autoloader of ci-phpunit-test does not support namespaced classes. If you want to autoload your namespaced classess, I recommend you use Composer autoloader.
@sunggun1
It seems your test runs perfectly. The error is because of your model (or other) code.
The picture of the error above was about two functions that were 'Email_test/find_login_email' and 'Welcome_test/math_test'
class Welcome_test extends TestCase{
function test_math(){
$this->assertEquals(1+1,2);
}
}
test_math worked well but every time I wanted to use model from 'refactoring/applicaion_common/models' or 'refactoring/applicaion_pc/models'
(I tested on )
'refactoring/application_common/tests/'
I couldn't get any one of these even though I used
$this->load->model('Account/Account','Account'); -> 'from refactoring/application_common/models/Account/Account'
$this->obj = $this->CI->Account;
Error :
Function :
Model : application_common/models/Account/Account
<?php
namespace OFM_COMMON\Models\Account;
class Account extends \CI_Model{
public function __construct()
{
parent::__construct();
$this->load->helper('datetime');
$this->load->helper('url');
$this->load->database();
}
`
public function find_login_email($name, $phone){
$sql = "SELECT USER_EMAIL_ADDR
FROM
user_info ui
WHERE
ui.USE_YN = 'Y' AND ui.USER_NM =:USER_NM AND ui.USER_CEL_NO =:USER_CEL_NO
";
$query = $this->db->prepare($sql)
->bind('USER_NM', $name)
->bind('USER_CEL_NO', $phone)
->execute(null, true);
return $query->result_array();
}
}
Test on pc or mobile environment have an access to 'application_common/models' I tested on pc (I can use 'application_pc/models' and 'application_common/models' ) environment
@sunggun1 Can you load the model Account
when you call it via web (not in testing)?
If my memory is correct, CodeIgniter3 does not support namespaced model classes.
Uhmm.. I found out APPPATH was only 'application_pc/' so I added 'application_common/' with array_push();
and junit...
But after changing it, Suddenly it doesn't work... even though I did 'composer dump'
@sunggun1 It seems that is not a problem of ci-phpunit-test, but a problem of your customized CodeIgniter.
I have application_common which is for both pc and mobile version of my company's website There are 'refactoring/application_common' 'refactoring/application_pc' 'refactoring/application_mobile'
Each directory has a MVC pattern
I downloaded ci-phpunit-test on 'refactoring/application_common/tests'
This is a test code in 'refactoring/application_common/tests/controllers/Email_test'
Service Code 'refactoring/application_common/tests/service/Service'
Account Model is on 'refactoring/application_common/models/Account/Account.php'
Error is like
I typed 'cd application_common/tests' 'phpunit'
PHPUnit is on 'refactoring/application_common/tests/phpunit.xml'