Comments (28)
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.
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.
Do you have catch-all route?
from ci-phpunit-test.
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.
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.
Ah! Because of 404_override
?
from ci-phpunit-test.
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.
By the way, you should set like $route['404_override'] = 'controller/method';
.
Your $route['404_override'] = '/';
is apparently wrong.
from ci-phpunit-test.
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 :
I don't see any override with _dummy/_dummy in bootstrap, where is it ?
from ci-phpunit-test.
I don't understand why your values are Auth and index.
from ci-phpunit-test.
Is it normal that argv is still the same here:
from ci-phpunit-test.
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.
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.
Try this branch: https://github.com/kenjis/ci-phpunit-test/tree/fix-404_override
from ci-phpunit-test.
with this return, yes there is no problem :D
from ci-phpunit-test.
@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.
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.
This is probably because I have a MY_Form_validation class and form_validation is in the auto_load libraries
from ci-phpunit-test.
What's CI_Controller::$loadFilename
?
from ci-phpunit-test.
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.
I think you should reset the is_loaded() before calling new CI_Controller(); in CIPHPUnitTest.php:68
from ci-phpunit-test.
To reproduce, I think you just should add form_validation in the autoload libraries
from ci-phpunit-test.
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.
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.
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.
master
branch is not released.
If you want to use it:
- 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"
}
}
- Run composer update.
$ composer update kenjis/ci-phpunit-test
- Install to
application/tests
folder.
$ php vendor/kenjis/ci-phpunit-test/update.php
from ci-phpunit-test.
I've just released v0.8.1.
from ci-phpunit-test.
I believe this bug was fixed.
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.