XMLdiff for php installation - php

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).

Related

PHP error calling a function from a package

I am new to php and have just installed my first package via composer. I'm now trying to call a function from the package I installed as follows:
<?php
require_once 'vendor/autoload.php';
$value = 1;
$aws = AmazonGiftCode::make()->buyGiftCard($value);
echo $aws;
?>
But I get the following error:
PHP Fatal error: Uncaught Error: Class 'AmazonGiftCode' not found in
/public_html/php/test.php:4 Stack trace:
#0 {main} thrown in /public_html/php/test.php on line 4
Based on my (albeit limited) experience with other languages, I'm guessing I have to load the package that contains the class first. The package folder is in the same directory as the test.php file, in the subfolder vendor/kamerk22/AmazonGiftCode/. But I think this is where I don't know enough to troubleshoot it based on the information I could find.
Your directory structure should look like this.
test.php
composer.json
vendor
└───autoload.php
└───kamerk22
└───AmazonGiftCode
Make sure you installed the package using composer, and not by downloading it.
I'm guessing I have to load the package that contains the class first.
Unlike what you would normally expect when importing stuff, when using composer you only have to import the autoload.php file, and composer will take care of loading other packages as needed. By as needed what I mean is that as soon as composer sees you use the AmazonGiftCode class it will import the AmazonGiftCode package, but if one of your REST endpoints doesn't use anything from the AmazonGiftCode package it won't ever load it. This allows you to not have to worry about slowing down the entire application when you want to use a composer package for only a few endpoints. At least that's the way I understand how composer works.
Just run composer dump-autoload once and the class should known then.
You could also get verbose and use kamerk22\AmazonGiftCode\AmazonGiftCode;
But that AmazonGiftCode looks quite Laravel specific... that's why it may still fail, even if it may be found by auto-load. One needs to setup Laravel framework in the first place; just see this query (just in case if you may wonder where all these missing classes may come from).

Travis-CI: Class not found even when using autoloader

Im kind of new with Travis, and I am expreimenting with it right now. I uploaded have my PHP Project on Github and when I let it test via Travis it fails and gives me this error.
PHP Fatal error: Class 'controllers\Welcome' not found in /home/travis/build/ezylot/PHPSkeleton/tests/controllers/welcomeTest.php on line 4
I use a autoloader to load the classes, and it is no problem on my local machine. I include the autoloader in bootsrap.php with the bootstrap in the PHPUnit Konfiguration-XML File.
<?php
if (!#include __DIR__ . '/../vendor/autoload.php') {
die('You must set up the project dependencies, run the following commands:
wget http://getcomposer.org/composer.phar
php composer.phar install');
}
?>
You are most likely developing on OSX which has case insensitive filesystem and tests pass. Travis uses case sensitive file system. Try renaming app/controllers/welcome.php to app/controllers/Welcome.php.
In general it is good idea to follow PSR-1 standard to avoid autoloading issues.
I had a short php open tag at the top of the class file.
<?
as opposed to
<?php
This broke it on the remote, but not on my local. Which is weird, because I would've expected it to break locally too.
Putting this out there in case someone else is in the same odd situation.

PHPUnit failed opening required file

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

Can't require mage.php from an interactive shell

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.

PHPUnit code coverage report generation fails

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 (:::)

Categories