Force codeception to ignore a PHP file? - php

I have an _ide_helper.php file in the root of my project, that Codeception is picking up, ignoring code to tell it not to, and leading to an error:
PHP Fatal error: Cannot redeclare class App (in _ide_helper.php)
Is it possible to force Codeception to not look at this file?

The underlying issue ended up being the way Codeception was handling Laravel defaults

Related

Laravel 5 class

I installed laravel 5.1 on my windows 7, after that i tried to open blog/app/Htttp/routes.php.Now there's a error on my browser saying
"Fatal error: Class 'Route' not found in
C:\xampp\htdocs\Laravel_1\blog\app\Http\routes.php on line 14".
How do i remove this error?
Before a class is available in PHP you will need to require/include it. As you have opened up the file directly in the browser, the laravel application is not bootstrapped and none of the dependencies are loaded to be used.
If you open up public/index.php, you will find a line that says
require __DIR__.'/../bootstrap/autoload.php';
// this later calls composer autoload which compiles a file
// that includes all the classes that you have specified in your `composer.json`.
Now that you have opened the file directly, non of the classes are included and hence you get the error.
I am not sure about your intentions for opening that file directly in the browser. I can only suggest you that the error is expected and you should go through the public/index.php for the application to work properly.

Laravel 5.1: Cannot redeclare class Illuminate\\Contracts\\Support\\Arrayable

I am getting an error message in my Laravel 5 application:
PHP Fatal error: Cannot redeclare class Illuminate\\Contracts\\Support\\Arrayable in /var/www/.../bootstrap/cache/compiled.php on line 156
This error only occurs on my staging environment and not on my local website. I would love to post more info but I do not have it. Because I do not know where this error is caused.
If I remove the file (cache/compiled.php) everything seems to work fine. But after every deploy the same error occurs. On my localhost everything works fine as well.
My question: does anybody have a clue where to look because I am out of ideas.
Try this way.
At first remove the cache/compiled.php file
then run this command
php artisan clear-compiled
I had the same problem and found the following article, which was very helpful:
https://sentinelstand.com/article/laravel-5-optimization-commands
The only solution that was working for me was manually deleting bootstrap/cache/compiled.php. Switching around the order in which the autoloaders are called in bootstrap/autoload.php did not work for me because I had the same problem the other way round, ie. I had a class in compiled.php that was causing something from autoload.php to be autoloaded before autoload.php ran.
In my case, I am using a combination of PSR4 and manual class mappings in my composer.json file. I'm sure this is part of the problem. (Don't judge me: this app started in Laravel 3, so it's taking time to add namespacing throughout the code base :-).
One reason why things may work differently in different environments is because the artisan optimize command will only generate the bootstrap/cache/compiled.php file if you provide the --force option or if debugging mode is not enabled. So it is likely that you are not getting this file in development because debugging is enabled but are getting this file in staging and/or production because debugging is not enabled.
Ultimately, here's what I have landed on as a solution for production deployments:
artisan config:cache
artisan optimize
rm bootstrap/cache/compiled
Update symlink to point to new version.
This way you still get bootstrap/cache/services.json, which is helpful, whereas artisan clear-compiled removes that file. Also, there will be a very brief period of time where bootstrap/cache/compiled.php will exist, which is why it is important to run these commands before you update the symlink to point your web server at the new version.
It is also worth noting that the compiled.php file that is created by artisan optimize in Laravel 5.1 is no longer generated in Laravel 5.4 because, as Taylor has stated, PHP 7 is much more performant and so the benefit of bundling all the application classes into one file, which is meant to save on disk I/O, is negligble now. Taylor recommends enabling and properly configuring your OPcache instead - you will get far more performance benefits from that.
I experienced the same but eventually found the solution.
I have my own helpers.php files in laravel. Just like the framework ones, I added them as autoloads in my composer.json. A couple of those functions are macros for the Collection (\Illuminate\Support\Collection::macro(...)).
When that helpers.php file is autoloaded, the definition of those macros cause the autoloading of Illuminate\Support\Collection. This in turn uses Illuminate\Contracts\Support\Arrayable.
So basically all of these are already loaded by the time they are defined again in cache/compiled.php. Boom.
Long story short: For me the fix was simply to switch inclusion of the compiled file and the autoloader around.
bootstrap/autoload.php:
$compiledPath = __DIR__.'/cache/compiled.php';
if (file_exists($compiledPath)) {
require $compiledPath;
}
require __DIR__.'/../vendor/autoload.php';
This might not be a viable solution add include code in your compiled file runs right away and refers to helper functions, but I think the chances on that happening should be pretty minimal.
The problem is with the artisan optimize command. If you remove the compiled.php file and then do not run optimize, it should work.

Why would (CodeIgniter) get_instance() not work?

I am trying to get PHPUnit (for TDD) working with CodeIgniter.
A perfectly reasonable guide that I am following is here: http://www.jamesfairhurst.co.uk/posts/view/codeigniter_phpunit_and_netbeans
But the problem I am getting is this:
c:\projects\project1\tests>phpunit .
Fatal error: Call to undefined function get_instance() in c:\....\PostTest.php on line 7
which almost sounds like my whole CodeIgniter framework is not being seen.
I've modified the bootstrap.php file to have an explicit path to the system and application folders, just to be sure that it's not something simple like that. But no luck.
What does get_instance depend on to run? It's part of the core CodeIgniter framework.
I got the same error.
The problem is in the file phpunit.xml
You need to place it on
c:\projects\project1\tests>
and you need to create the file bootstrap.php as on your link :
http://www.jamesfairhurst.co.uk/posts/view/codeigniter_phpunit_and_netbeans
that's how your tests connect to your codeigniter

How can I tell phpunit where the source and tests can be found

I am a newbie with phpunit but I need it to test something
So, suppose that have the following folders
mainFolder/SRC/x/y/sourceFiles.php
mainFolder/TESTS/x/y/testFiles.php
mainFolder/TESTS/bootstrap.php
When I run phpunit mainFolder it tells me:
Fatal error: Class 'x/y/sourceFile' not found in mainfolder/tests/x/y/testfile.php on line 28
Note that I am a newbie, and I need some help.
Thanks
The test files should be able to find the tested classes. Which means you have to require them, or set up a proper autoloading mechanism or pre-load them in a bootstrap file. And probably there are lots of other ways to do this. The test files behave exactly the same in this sense like simple php files.

Got Fatal error CodeIgniter CI_Controller not found

I got following error on every controller
Fatal error: Class 'CI_Controller' not found in /<path>/system/core/CodeIgniter.php on line 233
The root folder has also its same separate codeigniter system (all ci structure) folder. the site in root in working but when i copy the another ci structure in sub folder i got mentioned fatal error. please help me.
Check your database config in application/config/database.php it's one of the major time consuming error message I faced with CI. Because the error message was simply misleading. So, check the DB config first.
I had a similar problem when trying to run a migration that is within a folder, it appears that my 'git' is with a conflict in the directory separator.
I was trying to run on command line:
$ php index.php tools/migration
fix it temporarily with the command:
$ php index.php tools migration

Categories