I recently switched autoload in composer.json from classlist to psr-4. Then in terminal I ran vendor/bin/composer dump-autoload in the project root, which is a plugin directory.
My autoload settings:
"autoload": {
"psr-4": { "A\\" : "classes/A" }
}
There is only 1 class in ./classes/A so it was a concern when the console said it loaded 545 classes. I double checked that I was in the right (plugin) folder instead of the wordpress root.
It appears composer is recursively loading every wordpress class starting from 3 levels below. I get a list of errors, here are a few of the top ones.
owner#G700:/var/www/html/wptest2/wp-content/plugins/fvc$ vendor/bin/codecept run wpunit
Codeception PHP Testing Framework v2.5.6
Powered by PHPUnit 7.5.10 by Sebastian Bergmann and contributors.
Running with seed:
PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Utilities' not found in /var/www/html/wptest2/wp-includes/class-wp-hook.php on line 286
PHP Stack trace:
PHP 1. {main}() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/lucatume/wp-browser/src/includes/isolated-install.php:0
PHP 2. activate_plugin() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/lucatume/wp-browser/src/includes/isolated-install.php:210
PHP 3. do_action() /var/www/html/wptest2/wp-admin/includes/plugin.php:660
PHP 4. WP_Hook->do_action() /var/www/html/wptest2/wp-includes/plugin.php:465
PHP 5. WP_Hook->apply_filters() /var/www/html/wptest2/wp-includes/class-wp-hook.php:310
PHP Warning: require_once(../../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/wptest2/wp-content/plugins/fvc/tests/wpunit/T1Test.php on line 2
PHP Stack trace:
PHP 1. {main}() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/codeception/codeception/codecept:0
PHP 2. Codeception\Application->run() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/codeception/codeception/codecept:43
PHP 3. Codeception\Application->run() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/codeception/codeception/src/Codeception/Application.php:108
This is an autoload error right? Any idea how I can fix this?
In case this might be something else I am including the test file I am running. This is the only test file that should run with the command vendor/bin/codecept run wpunit
<?php
require_once("../../vendor/autoload.php");
require_once ('../../classes/A/T1.php');
class T1Test extends \Codeception\TestCase\WPTestCase
{
public function testAdd() {
$t1 = new \T1();
$this->assertEquals(1, 1);
$sum = $t1->add(5, 2);
$this->assertEquals(7, $sum, "didn't sum");
}
}
Related
I am trying to use the following github project in my wordpress plugin:
PHP Object wrapper for the Google Chart API
I tried the following:
require_once(WPPLUGIN_PATH. "gchart/gChartInit.php");
$piChart = new gPieChart(); // <---- here I get the error
$piChart->addDataSet(array(112,315,66,40));
$piChart->setLabels(array("first", "second", "third","fourth"));
$piChart->setLegend(array("first", "second", "third","fourth"));
$piChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
echo $piChart->getImgCode();
My problem seems to be that when I am using the above code, it jumps at line $piChart = new gPieChart(); into another wordpress-plugins autoloader and does not load the gPieChart.php properly.
The error message is:
[26-Jul-2016 20:39:59 UTC] PHP Fatal error: Class 'gPieChart' not found in /home/ubuntu/workspace/wp-content/plugins/wp-analytics-mail/sendTestMail.php on line 267
[26-Jul-2016 20:39:59 UTC] PHP Stack trace:
[26-Jul-2016 20:39:59 UTC] PHP 1. {main}() /home/ubuntu/workspace/index.php:0
[26-Jul-2016 20:39:59 UTC] PHP 2. require() /home/ubuntu/workspace/index.php:17
[26-Jul-2016 20:39:59 UTC] PHP 3. require_once() /home/ubuntu/workspace/wp-blog-header.php:19
[26-Jul-2016 20:39:59 UTC] PHP 4. include() /home/ubuntu/workspace/wp-includes/template-loader.php:75
[26-Jul-2016 20:39:59 UTC] PHP 5. include() /home/ubuntu/workspace/wp-content/themes/twentysixteen/page-analytics-analytics-mail.php:138
Any suggestions how to make the above code work?
I appreciate your reply!
Here's what you do.
Install Composer as per the doc or, if you're on Windows/Unix, figure out how to install the thing in your environment.
Create new file called composer.json in the root folder of your plugin (in this case wp-analytics-mail)
Again, as per the doc, paste this into the composer.json
{
"require": {
"gchartphp/gchartphp": "dev-master"
}
}
In the command line, get to the plugin folder and run composer update
Put require 'vendor/autoload.php'; somewhere close to the top of your main plugin file (sendTestMail.php)
Lower down in the same file, initialize and use the library:
$piChart = new gchart\gPieChart();
I am trying to debug Magendo 1.9.2.4 app\code\core\Mage\Core\Controller\Varien\Router\Standard.php. I am using PhpStorm with Xdebug.
During the debug it shows me an error that it cannot find the class Abstract that it's referring to.
Here is the full log:
C:\xampp\php\php.exe -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 C:\xampp\htdocs\vaimo\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php
PHP Fatal error: Class 'Mage_Core_Controller_Varien_Router_Abstract' not found in C:\xampp\htdocs\vaimo\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php on line 28
PHP Stack trace:
PHP 1. {main}() C:\xampp\htdocs\vaimo\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php:0
Fatal error: Class 'Mage_Core_Controller_Varien_Router_Abstract' not found in C:\xampp\htdocs\vaimo\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php on line 28
Call Stack:
0.0699 193008 1. {main}() C:\xampp\htdocs\vaimo\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php:0
Process finished with exit code 255
Class Standard extends from Abstract class which is located in different file but in the same folder with Standard.
You are doing it wrong.
You are debugging your code in CLI environment ("PHP Script" type of Run/Debug Configuration). This way you are executing your C:\xampp\htdocs\vaimo\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php file directly in terminal hence the Magento's bootstrap code (class autoloading etc) is not executed and PHP (yes, this error comes from PHP interpreter itself) is unable to find your parent class.
Solution: do not debug in CLI mode using "PHP Script" type of config -- debug it via browser as Web Application instead with correct type of config. This way normal Magento routine will be in place (autoloading/configs/db connection/etc) -- https://confluence.jetbrains.com/display/PhpStorm/Debugging+PHP+Web+Applications+with+Run+Debug+Configurations.
All debugging materials
Zero-configuration approach -- when you initiate debugging from the browser using xdebug browser extension or manually setting up cookie/xdebug param.
I'm trying to install log4php in a very simple site (trying to learn how it works).
Apache is installed in /etc/ and vhost is defined as:
DocumentRoot "/home/fferri/workspace/site-tutorial/www"
ServerName tutorial.localhost
php_value auto_prepend_file "/home/fferri/workspace/site-tutorial/www/ConfigureSite.php"
My site is at /home/fferri/workspace/site-tutorial/www/ and log4php folder is at /home/fferri/workspace/site-tutorial/services/lib/log4php-0.9/src/log4php/
Then, I define
define('LOG4PHP_DIR', "/home/fferri/workspace/site-tutorial/services/lib/log4php-0.9/src/log4php/");
into ConfigureSite.php
And, into another file, I try to init log4php:
include(LOG4PHP_DIR."/Logger.php");
$log = Logger::getLogger("main");
$log->info("foo");
$log->warn("bar");
The error is always the same:
Fatal error: Class 'Logger' not found in /home/fferri/workspace/site-tutorial/services/lib/log4php-0.9/src/log4php/LoggerRoot.php on line 37
It's worth to say that LoggerRoot.php and Logger.php are in the same folder. I think I have a problem of paths because my server and my site aren't in the same folder, but I need some hint
Adding the complete stack trace of error:
[22-May-2012 11:34:38] PHP Fatal error: Class 'Logger' not found in /home/fferri/workspace/site-tutorial/services/lib/log4php-0.9/src/log4php/LoggerRoot.php on line 36
[22-May-2012 11:34:38] PHP Stack trace:
[22-May-2012 11:34:38] PHP 1. {main}() /home/fferri/workspace/site-tutorial/www/index.php:0
[22-May-2012 11:34:38] PHP 2. require_once() /home/fferri/workspace/site-tutorial/www/index.php:12
[22-May-2012 11:34:38] PHP 3. require_once() /home/fferri/workspace/site-tutorial/www/greet_at_opening.php:11
[22-May-2012 11:34:38] PHP 4. require_once() /home/fferri/workspace/site-tutorial/services/lib/log4php-0.9/src/log4php/Logger.php:24
[22-May-2012 11:34:38] PHP 5. require_once() /home/fferri/workspace/site-tutorial/services/lib/log4php-0.9/src/log4php/LoggerCategory.php:27
[22-May-2012 11:34:38] PHP 6. require_once() /home/fferri/workspace/site-tutorial/services/lib/log4php-0.9/src/log4php/spi/LoggerLoggingEvent.php:28
[22-May-2012 11:34:38] PHP 7. require_once() /home/fferri/workspace/site-tutorial/services/lib/log4php-0.9/src/log4php/LoggerManager.php:29
[22-May-2012 11:34:38] PHP 8. require_once() /home/fferri/workspace/site-tutorial/services/lib/log4php-0.9/src/log4php/LoggerHierarchy.php:28
So, first, Logger is found but on loading LoggerHierarchy, Logger isn't. Why????
SOLVED: The error is to use log4php-0.9 and php5 together. Downloading the library located in apache web (2.1), the problem is solved.
Thanks!
I think using dirname(__FILE__) will look better.
I also thought it would be the path...
Maybe the Class name defenition then. do you call new Logger in Logger.php?
What about something like:
include(LOG4PHP_DIR."/Logger.php");
$log = new Logger();
$log->info("foo");
The error is to use log4php-0.9 and php5 together. Downloading the library located in apache web (2.1), the problem is solved.
I have gone through various tutorials/posts to install PHPUnit with Selenium on my Ubuntu system. I believe I have everything setup as required:
/usr/share/php$ phpunit --version
PHPUnit 3.6.10 by Sebastian Bergmann.
So using the IDE I create my test, and save it for running, which appears to be setup as required. So I run the test using:
phpunit /home/retrobadger/working_files/tutorials/phpunit/selenium1.php
But everytime I run it, I get the error below:
PHP Fatal error: Class 'PHPUnit_Extensions_SeleniumTestSuite' not found in /usr/share/php/PHPUnit/Extensions/SeleniumTestCase.php on line 394
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:130
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:150
PHP 5. ReflectionMethod->invoke() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:124
PHP 6. PHPUnit_Extensions_SeleniumTestCase::suite() /usr/share/php/PHPUnit/Extensions/SeleniumTestCase.php:0
The file in extensions exists, and I have set very open priviledges to it. The only things I can think of are that either my SeleniumTestCase.php is faulty, or that I need to require another file no other tutorials have suggested.
Any recommendations would be greatly appreciated. I have little experience with PHPUnit so expect my mistake is a basic one.
Thanks for any advice you can give,
Dan
Check that you include PHPUnit when you call tests.. either in php.ini, or with IDE that you run, or explicitly - right now it just can't find class.. which means that PHPUnit is not reachable. Try a simplier class, PHPUnit_Extensions_SeleniumTestCase
I am running Zend Framework 1.10 on Ubuntu 10.04, just installed Xdebug to generate code coverage, via PECL.
If I run phpunit like so:
$ phpunit --coverage-html ~/coverage
It works just fine. Unittests run, then code coverage output is generated. No error messages or warnings.
But if I do:
$ phpunit
The tests run fine, but when code coverage begins, I get this:
Generating code coverage report, this may take a moment.PHP Warning: mkdir(): Permission denied in /usr/share/php/PHPUnit/Util/Filesystem.php on line 209
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:147
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:214
PHP 5. PHPUnit_Util_Report::render() /usr/share/php/PHPUnit/TextUI/TestRunner.php:479
PHP 6. PHPUnit_Util_Filesystem::getDirectory() /usr/share/php/PHPUnit/Util/Report.php:87
PHP 7. mkdir() /usr/share/php/PHPUnit/Util/Filesystem.php:209
Warning: mkdir(): Permission denied in /usr/share/php/PHPUnit/Util/Filesystem.php on line 209
Call Stack:
0.0003 322324 1. {main}() /usr/bin/phpunit:0
0.0521 4658252 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
0.0521 4658716 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:147
0.5944 12773356 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:214
37.1550 24746768 5. PHPUnit_Util_Report::render() /usr/share/php/PHPUnit/TextUI/TestRunner.php:479
37.1550 24746768 6. PHPUnit_Util_Filesystem::getDirectory() /usr/share/php/PHPUnit/Util/Report.php:87
37.1560 24746984 7. mkdir() /usr/share/php/PHPUnit/Util/Filesystem.php:209
Before I installed Xdebug, running phpunit without any arguments worked just fine.
I presume this is just a silly permissioning problem stemming from my PECL installation of Xdebug, but it looks like everything in /usr/share/php/phpunit is supposed to be permissioned as root, soooooo...any ideas?
The error message just tells you that mkdir can't create a folder somewhere but not where it is trying to do so.
I would assume you have an phpunit.xml.dist in which a <logger> of the type coverage-html is defined with a target that doesn't exist on your machine which your current user doesn't have write access too.
PHPUnit doesn't try to generate a coverage report without somneone telling it do and if you don't do it on the cli a phpunit.xml is the only option left.