I would like to try some code snippets (about to make a script) which uses Magento's models and classes.
The problem is that I get the following error:
fdr#fderose-gtrade:/var/www/globaltrade$
fdr#fderose-gtrade:/var/www/globaltrade$ php -a
Interactive shell
php > require './app/Mage.php';
Fatal error: Class 'Mage' not found in /var/www/globaltrade/app/Mage.php on line 31
Line 31 of Mage.php is the following:
Mage::register('original_include_path', get_include_path());
Does anybody have an idea about what could be the cause? Thank you!
According to php.net
Autoloading is not available if using
PHP in CLI interactive mode.
see http://php.net/manual/en/features.commandline.interactive.php for more info (its a note towards the bottom of the description)
At first glance it seems that your issue stems from autoload. When you include your Mage.php file it appears that it then tries to run a php autoload and use the Mage class, but is failing in doing so. It's possible that the way that their autoload is functioning, the paths may not be correct when run from an interactive shell.
Related
I install this module to magento:
http://www.magentocommerce.com/magento-connect/addshoppers-viral-product-sharing-2577.html
and have problem with my website now:
Fatal error: Class 'Clearcode_Addshoppers_Model_Mysql4_Setup' not found in /data/web/virtuals/49508/virtual/www/includes/src/Mage_Core_Model_Resource_Setup.php on line 234
could you please help me?
Very Very thank you!
Does app/code/<local or community>/Clearcode/Addshoppers/Model/Mysql4/Setup.php exist at all? if it doesn't, you're missing that file. If it does not then try taking a look inside that file and see if the class name is Clearcode_Addshoppers_Model_Mysql4_Setup and not something else.
Path
includes/src
indicated that magento is looking for class in compiled files directory.
Try to run
php shell/compiler.php compile
and try again.
It seems like you have the compiler enabled but it cannot find the (flattened) file.
So either disable the compiler:
php shell/compiler.php disable
Or run a compilation so that it will generate the file for you:
php shell/compiler.php compile
I am trying to install xml diff ; https://github.com/mmacia/XMLdiff and i have not managed yet to make it work.Whenever i run any test example,i get
Fatal error: Interface 'PHPUnit_Framework_Test' not found in
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php on line 85
Has anyone managed to install and use the library.I am using xampp on windows.
I believe your problem has to do with PHPUnit's Autoloader.php not being included. This file sets the php spl_autoloadspl_register function which is responsible for loading in interfaces and classes like PHPUnit_Framework_Test.
According to this SO question, you have to include the autoloader file manually. Without knowing more about your set-up and how that particular library works, I would say do something like this in the appropriate file(s):
// define phpunit path
if ( ! defined('PHPUNIT_PATH')) {
// define an absolute path to your PHPUnit dir
// CHECK THIS, i'm not good with php on windows:
define('PHPUNIT_PATH','C:\xampp\php\PEAR\PHPUnit');
}
// Then include the autoloader like this:
include PHPUNIT_PATH.'Autoloader.php';
I hope this helps you or anyone else out.
Check execution flags for C:\xampp\php\PEAR\PHPUnit\Framework\Framework\Test.php
The file needs to be executable by the user who is launching tests (probably you).
I've browsed through similar problems on SO, but to no avail. I'm running PHP 5.3.6 and phpunit version 3.6.10. When attempting to execute a simple test:
require_once 'PHPUnit/Framework.php';
class UserTest extends PHPUnit_Framework_TestCase {
}
I receive the following error:
PHP Fatal error: require_once(): Failed opening required 'PHPUnit/Framework.php'
(include_path='.:/Users/username/pear/share/pear:/usr/lib/php/pear/:/Users/username/pear/share/pear/PHPUnit') in ...
When reinstalling PHPUnit, I'm not sure if the install location was duplicated, but it appears that when running which phpunit, the path is: /usr/bin/phpunit. However, it appears to also be installed in /Users/user/pear/bin/phpunit.
I've tried updating all channels and reinstalling PEAR and PHPUnit, but the problem still exists. I'm running on OSX Lion. Any help would be greatly appreciated.
Just remove the line
require_once 'PHPUnit/Framework.php';
and everything should work.
You don't need to include/require anything PHPUnit related since (at least) PHPUnit 3.6 any more and you can't include that file because it doesn't exist any more in the distribution.
The phpunit runner will take care of bootstrapping everything that is needed by PHPUnit :)
As others pointed out, Framework.php is not required anymore.
But in any case if you already have too many test files written and having the include statement, then fixing them going to be a cumbersome task. Which was the case I had to face.
If a quick workaround is needed, create an empty Framework.php file. That will resolve the problem.
Create an empty file named Framework.php under your PHPUnit directory. (eg: at: /usr/share/php/PHPUnit/Framework.php).
sudo touch /usr/share/php/PHPUnit/Framework.php
I'm trying some supposedly nice features of PHPUnit, but I cannot generate a freakin' code coverage report. What I get is:
rolf#dev ~/projects/current/tests $ scripts/phpunit --configuration $PROJECTS/current/tests/conf/inc/tests.xml
[...]
Generating code coverage report, this may take a moment.
[...]
Fatal error: require_once(): Failed opening required 'lib/DataSource.php' (include_path=':::') in path/to/lib/WS/DataParser.php on line 10
However, in this very class, a specific include path is defined, and the require_once works like a charm when the application is launched.
Could it be that PHPUnit cannot solve include paths ?
Thanks in advance and long live stackoverflöw!
Rolf
If you're using the latest PHPUNIT (3.5+) it might be because Sebastion has started using an autoloader himself within the program.
You've got to add the line
spl_autoload_register('__autoload');
after your __autoload() function gets created / included / required
so for example, the file that has my autoloader is called functions. in my bootstrap I do the following:
require_once(ROOT_PATH.'/lib/utils/functions.php');
spl_autoload_register('__autoload');
Are you changing your include_path in any of your tests/code? Because it looks really odd (:::)
I want to use php in console mode and create an environment to test my functions.
I do not want to be forced to use a web browser and create a new file each time I want to test a function.
I want to access the function in the console and then it return the result.
How do I do this?
Update:
Perhaps I have explained this badly. I only want to see what result the function's return.
Maybe I have to learn unit testing but for the moment I only want an interactive console which allows me to test all functions one by one.
In my case I have to load the wordpress functions (I know how do it with a regular .php file and then a browser to parse the file) but i don't if it is possible to do it with php from the command line.
I have used phpsh in the past and found it very useful. Once you start it you will need to chdir() to where your files are and then obviously require() any files containing functions you need to test. You can then just test your function calls by typing them into the shell e.g. var_dump(some_function(1, 2));
I guess you've to be more specific what kind of functions exactly. Wordpress does not provide something like that out of the box, most PHP apps won't.
I also think you're calling for trouble here when such apps aren't developed in mind for such environments.
Here's an example trying to call "current_time()" from functions.php and the attempts I had to do just to realize it won't work that way:
php -r 'require "functions.php"; var_dump(current_time("mysql"));'
gives
Fatal error: Call to undefined function apply_filters() in functions.php on line 346
Trying
php -r 'require "functions.php"; require "plugin.php"; var_dump(current_time("mysql"));'
gives
Fatal error: Call to undefined function wp_cache_get() in functions.php on line 351
Trying
php -r 'require "functions.php"; require "plugin.php"; require "cache.php"; var_dump(current_time("mysql"));'
gives
Fatal error: Call to a member function get() on a non-object in cache.php on line 93
Looking at the last error in the source I see
function wp_cache_get($id, $flag = '') {
global $wp_object_cache;
return $wp_object_cache->get($id, $flag);
}
Using global variables makes testing in other environments a PITA if not impossible.
If this is not what you're trying to do, you've to be more specific/detailed in your question.
You are going to want to read up on "Unit Testing" in a generic sense and then try and apply them to PHP.
The framework you are using (if any), the style of code, and the tests you want to run are going to determine the exact methods you need to use. Only by first understanding the concept of Unit Tests and implementing them into your coding best-practices will you be able to make progress in this regard.
How about:
php -a
And if you compile php with readline support it'll be more fancy.