Git Product home page Git Product logo

Comments (28)

kenjis avatar kenjis commented on May 24, 2024

I can't reproduce it. Please show me how to reproduce.

What do you mean by "bootstrap fails"? Bootstrap of ci-phpunit-test does not call the default controller.

And redirect() can be tested with $this->assertRedirect(). See https://github.com/kenjis/ci-phpunit-test/blob/master/docs/HowToWriteTests.md#redirect

[Edited]

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

Ok let me try to tell you how to reproduce:
First, here is the stacktrace when the bootstrap file is ran:
Bootstrap.php:331
CIPHPUnitTest:65
CodeIgniter.php:514 : Here is called the default controller/Method

In my routes.php I have the following :
$route['default_controller'] = 'auth';

Therefore I get the function Auth/index executed in the bootstrap, which was containing a redirect() to Auth/login.

The assertRedirect is useful for tests but I'm still in bootstrap there and there is not yet a hook on redirect method.

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

Do you have catch-all route?

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

Nope, I don't know that feature.
My whole routes.php file is

$route['default_controller'] = 'auth';
$route['404_override'] = '/';
$route['translate_uri_dashes'] = FALSE;

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

Bootstrap.php:331
CIPHPUnitTest:65
CodeIgniter.php:514 : Here is called the default controller/Method

Normally CodeIgniter.php:514 does not run. Because ci-phpunit-test call _dummy/_dummy (changed $_SERVER['argv']) in bootstrap and it is 404.

So Line 476 show_404($RTR->directory.$class.'/'.$method); is called.

Why do you go to line 514?

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

Ah! Because of 404_override?

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

Hum maybe...
$RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL);
$class = ucfirst($RTR->class);
$method = $RTR->method;

At this 514 line:
$class=="Auth"
$method=="index"

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

By the way, you should set like $route['404_override'] = 'controller/method';.

Your $route['404_override'] = '/'; is apparently wrong.

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

I just want the show_404 method to be called but anyway, I created a controller/method to see if this is the problem, It is not, even like that I get the Auth method called in bootstrap :
image

I don't see any override with _dummy/_dummy in bootstrap, where is it ?

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

See https://github.com/kenjis/ci-phpunit-test/blob/master/application/tests/_ci_phpunit_test/CIPHPUnitTest.php#L19-L22

I don't understand why your values are Auth and index.

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

Is it normal that argv is still the same here:
image

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

Here in the CIPHPUnitTest.php:72, there is a $_SERVER restoration:

// Restore $_SERVER
        $_SERVER = $_server_backup;

EDIT : Nevermind, this is called after the bootstrap execution

Where is the $_SERVER["argv"] is it supposed to be used ?

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

Where is the $_SERVER["argv"] is it supposed to be used ?

CodeIgniter uses it to get route. See URI::_parse_argv().

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

Try this branch: https://github.com/kenjis/ci-phpunit-test/tree/fix-404_override

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

with this return, yes there is no problem :D

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

@kenjis I had a patch in the URI file for CLI uses, I was removing argv parameters :/
I removed the patch and now the argv is correctly read !
I removed your patch to get the try catch back and the show_404 exception is now correctly caught.

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

It's now failing in the new CI_Controller();
When initializing the Form_validation helper, the constructor tries to load the form helper, it fails because it doesn't find the load method in get_instance :/

    public function __construct($rules = array()) 
    {
        $this->CI =& get_instance();
[...]
        // Automatically load the form helper
        $this->CI->load->helper('form');
        log_message('info', 'Form Validation Class Initialized');
    }

Error is :

A PHP Error was encountered
Severity: NoticeMessage:  Undefined property: CI_Controller::$loadFilename: C:\Users\NICOLAS\Documents\damaaas\v1\system\libraries\Form_validation.phpLine Number: 147
Fatal error: Call to a member function helper() on null in C:\Users\NICOLAS\Documents\damaaas\v1\system\libraries\Form_validation.php on line 147

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

This is probably because I have a MY_Form_validation class and form_validation is in the auto_load libraries

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

What's CI_Controller::$loadFilename?

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

Actually, you try to instanciate a second time the Controller class calling new CI_Controller(); in CIPHPUnitTest.php:68

It was loaded the first time at line 500 in CodeIgniter.php (called from CIPHPUnitTest.php:65). Autoload libraries were loaded too (including form_validation which loads a helper using get_instance()->load object which was correctly initialised).

The problem is with this first loop in Controller.php which uses the is_loaded() static method. Because it is static, it remembers that Form_validation was loaded one time. Therefore it tries to instantiate it again with load_class("Form_validation") and call the constructor, and call $this->CI->load which is not yet initialized !

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

I think you should reset the is_loaded() before calling new CI_Controller(); in CIPHPUnitTest.php:68

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

To reproduce, I think you just should add form_validation in the autoload libraries

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

only resetting the is_loaded() array is not working but the reset_instance() function does the job 👍

try {
            // Request to 404 route
            // This is needed for not to call Welcome::index()
            // If controller Welcome is called in bootstrap, we can't test
            // the same name sub controller Welcome even when we use
            // `@runInSeparateProcess` and `@preserveGlobalState disabled`
            require_once BASEPATH . 'core/CodeIgniter.php';
        } catch (CIPHPUnitTestShow404Exception $e) {
            // Catch 404 exception
            reset_instance();
            new CI_Controller();
        }

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

After all, if we have 404_override, the controller is called in Bootstrap. And you see the output.
It should not be called.

I've fixed it on master branch.

from ci-phpunit-test.

PhoenixFnX avatar PhoenixFnX commented on May 24, 2024

I installed your framework through composer, how do I upgrade it with this last commit ?
composer update kenjis/ci-phpunit-test = Nothing to install or update

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

master branch is not released.

If you want to use it:

  1. Change the version in composer.json.
--- a/composer.json
+++ b/composer.json
@@ -6,6 +6,6 @@
        },
        "require-dev": {
                "mikey179/vfsStream": "1.1.*",
-               "kenjis/ci-phpunit-test": "^0.8.0"
+               "kenjis/ci-phpunit-test": "1.0.x@dev"
        }
 }
  1. Run composer update.
$ composer update kenjis/ci-phpunit-test
  1. Install to application/tests folder.
$ php vendor/kenjis/ci-phpunit-test/update.php

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

I've just released v0.8.1.

from ci-phpunit-test.

kenjis avatar kenjis commented on May 24, 2024

I believe this bug was fixed.

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.