Comments (19)
Can you load the libraries when you access via your web browser?
I added a test, but can't reproduce the error:
kenjis/ci-app-for-ci-phpunit-test@7ca540e
from ci-phpunit-test.
Hi,
Yes, the libraries load fine when using the web site.
Any ideas as to what else I can look at?
Any debugging I can do on my side to help identify the problem?
Jim
From: kenjis [mailto:[email protected]]
Sent: Thursday, October 22, 2015 2:12 PM
To: kenjis/ci-phpunit-test
Cc: Jim Kudebeh
Subject: Re: [ci-phpunit-test] help wanted loading libraries in subdirectories for controller testing (#72)
Can you load the libraries when you access via your web browser?
I added a test, but can't reproduce the error:
kenjis/ci-app-for-ci-phpunit-test@7ca540ehttps://github.com/kenjis/ci-app-for-ci-phpunit-test/commit/7ca540ea3245a68c43401e4aaab0a391c85a8772
β
Reply to this email directly or view it on GitHubhttps://github.com//issues/72#issuecomment-150357717.
from ci-phpunit-test.
Install the repository: https://github.com/kenjis/ci-app-for-ci-phpunit-test/
and see my test case: https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/master/application/tests/controllers/Ci_autoload_library_test.php
Compare it with your code, you may find something different.
In my understanding, the autoload issue was solved in the past. So I don't know why you get the error again.
from ci-phpunit-test.
Hi,
Make sure you don't have another class which has the same name. Autoload
seeks for the first class with a name you search using the scope order
discussed on another issue here.
Le ven. 23 oct. 2015 00:01, kenjis [email protected] a Γ©crit :
Install the repository:
https://github.com/kenjis/ci-app-for-ci-phpunit-test/
and see my test case:
https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/master/application/tests/controllers/Ci_autoload_library_test.phpCompare it with your code, you may find something different.
In my understanding, the autoload issue was solved in the past. So I don't
know why you get the error again.β
Reply to this email directly or view it on GitHub
#72 (comment)
.
from ci-phpunit-test.
I've been temporarily pulled of the project to get unit tests working on our CI. I'll try the above when I can.
Thanks for the responses
Jim
from ci-phpunit-test.
I've been having a similar issue after moving all the Ion_Auth files into subfolders (libraries/vendor, models/vendor etc.).
PHPUnit is returning "Unable to locate the specified class: Bcrypt.php"
even though it seems load perfectly fine when viewing the website.
Doing something like:
public function setUp() {
$this->CI =& get_instance();
$this->CI->load->library('vendor/ion_auth');
}
...seems to fix the issue, but it causes travis to return "RuntimeException: Unable to locate the model you have specified: Ion_auth_model"
.
The order of tests also seems to change whether it will work or not, which seems a bit strange.
The tests I use are basically the same as the ones included in the test repo (https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.9.0/application/tests/controllers/Auth_check_in_construct_test.php), so I'm not sure what's going wrong.
from ci-phpunit-test.
How about like this?
public function setUp() {
$this->resetInstance();
$this->CI->load->library('vendor/ion_auth');
}
from ci-phpunit-test.
Still getting the same issue.
Tests run fine locally, but fail with "RuntimeException: Unable to locate the model you have specified: Ion_auth_model"
in travis.
Travis Error:
1) Login_test::test_index_logged_in RuntimeException: Unable to locate the model you have specified: Ion_auth_model /home/travis/build/DakuTree/gemushi2/application/tests/_ci_phpunit_test/replacing/core/Loader.php:316 /home/travis/build/DakuTree/gemushi2/application/libraries/vendor/Ion_auth.php:69 /home/travis/build/DakuTree/gemushi2/application/tests/_ci_phpunit_test/replacing/core/Loader.php:1252 /home/travis/build/DakuTree/gemushi2/application/tests/_ci_phpunit_test/replacing/core/Loader.php:1046 /home/travis/build/DakuTree/gemushi2/application/tests/_ci_phpunit_test/replacing/core/Loader.php:218 /home/travis/build/DakuTree/gemushi2/application/tests/controllers/User/Auth/Login_test.php:6 /home/travis/build/DakuTree/gemushi2/vendor/phpunit/phpunit/phpunit:36
from ci-phpunit-test.
Is your filename Ion_auth_model.php
?
If you get error in only travis, it may be because the case (upper/lower) in your filename is wrong.
It happens if you use case insensitive file system (Mac or Windows) on local.
from ci-phpunit-test.
That seemed to fix it, thanks :)
Still not sure why the library has to be loaded in the test though, shouldn't the controller be able to handle all the loading?
from ci-phpunit-test.
Yes, the controller should handle the loading.
If you remove the setUp()
method, what happens?
from ci-phpunit-test.
Removing setUp() gives the "Unable to locate the specified class: Bcrypt.php"
error.
Strangely this only seems to occur on one of the tests that uses ion_auth. Commenting it out shows another similar test works perfectly fine.
I've uploaded a gist with the controllers & tests which might help find the issue: https://gist.github.com/DakuTree/94e29543d750b9836334
from ci-phpunit-test.
Probably you must load Ion_auth
in your test code. Because you autoload it before the controller construction in setCallablePreConstructor()
.
$auth = $this->getDouble('Ion_auth', ['logged_in' => TRUE]);
The above code only autoload (PHP autoloading) Ion_auth
. So $this->load->library()
in your controller does not work perfectly.
from ci-phpunit-test.
I guess I'll just stick with using setUp() then. Thanks for the help.
from ci-phpunit-test.
@DakuTree My explanation was not accurate.
I'm not sure but the patch below may resolve the error:
--- a/application/tests/_ci_phpunit_test/CIPHPUnitTestDouble.php
+++ b/application/tests/_ci_phpunit_test/CIPHPUnitTestDouble.php
@@ -38,6 +38,7 @@ class CIPHPUnitTestDouble
$methods = array_keys($params);
$mock = $this->testCase->getMockBuilder($classname)
+ ->disableOriginalConstructor()
->setMethods($methods)->getMock();
foreach ($params as $method => $return)
from ci-phpunit-test.
@jkudebeh Do you use $this->request->setCallablePreConstructor()
?
from ci-phpunit-test.
That patch seems to have fixed the error. Tests seem to run fine without needing to load the library in setUp() now. π
from ci-phpunit-test.
@DakuTree Thank you for your beedback!
Basically, we can't use $this->load
in $this->request->setCallablePreConstructor()
, because the CodeIgniter instance which we test does not exist yet.
But in your case, when you create the mock object, the constructor of mocked Ion_auth
class is executed and it calls $this->load->model('ion_auth_model');
and it calls $this->load->library('vendor/bcrypt',$params);
.
It causes Unable to locate the specified class: Bcrypt.php
error, when you create the new controller (= CodeIgniter instance).
The disableOriginalConstructor()
method disables the constructor call when you create the mock object.
I'm going to merge the patch in the next release.
from ci-phpunit-test.
this works: $output = $this->request('GET', 'libraries/Session/Session');
closing issue
from ci-phpunit-test.
Related Issues (20)
- 3.0.2 release date? HOT 2
- Coverage report is acting weird HOT 2
- Cannot create mock whose methods throw exceptions HOT 2
- How to extend the test runner for post operations? HOT 4
- 3.x new version with Updates for PHP 8.1 HOT 3
- How to stop PHP code execution when exit() in unit test? HOT 5
- Argument 1 passed to PHPUnit\Runner\TestSuiteSorter::reorderTestsInSuite() must implement interface PHPUnit\Framework\Test, instance of PHPUnit\Framework\TestSuite given HOT 3
- PHPUnit 9.5.24 + CodeIgniter 3.1.13 + PHP 8.1 HOT 2
- Session problem HOT 8
- Mocking DB object can't use getDouble? HOT 1
- How to clear RAM memory after run testcase in testsuite? HOT 3
- How to mock DB in CI? HOT 1
- PHP Fatal error: Uncaught Error: Class "TestCase" not found HOT 2
- Replacement of helper function redirect() does not work HOT 3
- cant set session $this->session->userdata HOT 1
- Upgrading to CodeIgniter4 is strongly recommended
- How to test external API with json response? HOT 1
- 1.0.2 fails with phpunit <7 when installed with "--from-composer" HOT 2
- issue during code coverage when referencing $this->uri in a view HOT 5
- Add support for php 8.2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ci-phpunit-test.