Git Product home page Git Product logo

Comments (19)

kenjis avatar kenjis commented on May 24, 2024

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.

jkudebeh avatar jkudebeh commented on May 24, 2024

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.

kenjis avatar kenjis commented on May 24, 2024

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.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

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.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.

β€”
Reply to this email directly or view it on GitHub
#72 (comment)
.

from ci-phpunit-test.

jkudebeh avatar jkudebeh commented on May 24, 2024

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.

DakuTree avatar DakuTree commented on May 24, 2024

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.

kenjis avatar kenjis commented on May 24, 2024

How about like this?

public function setUp() {
    $this->resetInstance();
    $this->CI->load->library('vendor/ion_auth');
}

from ci-phpunit-test.

DakuTree avatar DakuTree commented on May 24, 2024

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.

kenjis avatar kenjis commented on May 24, 2024

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.

DakuTree avatar DakuTree commented on May 24, 2024

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.

kenjis avatar kenjis commented on May 24, 2024

Yes, the controller should handle the loading.

If you remove the setUp() method, what happens?

from ci-phpunit-test.

DakuTree avatar DakuTree commented on May 24, 2024

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.

kenjis avatar kenjis commented on May 24, 2024

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.

DakuTree avatar DakuTree commented on May 24, 2024

I guess I'll just stick with using setUp() then. Thanks for the help.

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

@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.

kenjis avatar kenjis commented on May 24, 2024

@jkudebeh Do you use $this->request->setCallablePreConstructor()?

from ci-phpunit-test.

DakuTree avatar DakuTree commented on May 24, 2024

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.

kenjis avatar kenjis commented on May 24, 2024

@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.

jkudebeh avatar jkudebeh commented on May 24, 2024

this works: $output = $this->request('GET', 'libraries/Session/Session');
closing issue

from ci-phpunit-test.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.