Using janrain's OpenId php libs' test scripts. (PHPUnit) - php

I'm trying to run the test scripts that come with JanRain's php openid libraries. I've installed PHPUnit using pear. When I try to run the scripts I get:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /var/www/localhost/htdocs/openid/openid/Tests/Auth/OpenID/StoreTest.php on line 72
I'm sure this is a really simple issue. I just can't figure out what's wrong.
I don't see anywhere that the PHPUnit files get included, so do I need to make them automatically included somewhere?
server info: http://info.theunlink.com/info.php
I'm using the latest git sources: http://github.com/openid/php-openid
(I'm trying to run the test stuff because I get "OpenID authentication failed: Nonce already used or out of range" every other time I try to login and I'm trying to find where the issue is.)

What PHPUnit version do you have? There is a really ancient one in PEAR, you need a recent one - 3.4
With that out of the way, how exactly are you running the tests? I did a git clone and then executed command:
php admin/texttest.php
This did run at least part of the test suite.

Related

Running PHPUnit from eclipse PHPUnitLogger error and a port 7478 error

I can run phpunit effortlessly from commandline, no hitches there, but I thought it might be easier if I can run it directly from eclipse. I have never set up eclipse PHPUnit before so I followed a youtube video to set up PHPunit.
That one fails just as bad as the default php unit run the PDT enviroment provides.
But when I set up PHPUnit I get two errors and 0 hits on Google where to start resolving the issues.
I'm using php 7.2 TS on a windows 7 64bit system with Eclipse Oxygen.
When I try to run the tests I get the following error as a popup
Cannot launch PHPUnit tests (port address 7478): Accept timed out
And in the console I get:
PHPUnit 6.2.4 by Sebastian Bergmann and contributors.
Could not use "PHPUnitLogger" as printer.
I'm trying to run the tests under OctoberCMS, which is based upon Laravel. And as I said, the unit tests work as they should in the console.
What do I need to change to get PHPUnit working in eclipse?
I stumbled over this question since I had the same problem with Eclipse. In case someone else finds this problem, here is my solution:
In the "plugins" folder of your Eclipse installation you can find the File PHPUnitLogger.php. On Linux you can find it with the "locate" command, but it should be something like
<your_eclipse_folder>/plugins/org.eclipse.php.phpunit_<some_version>/resources/printer/PHPUnitLogger.php
Load this file in your bootstrap.php via require_once.

Can't run tests provided in Slim Framework

I'm trying to make a simple rest client for my android app. I would like to do than in TDD way, but for that I need simple working configuration for all actions (GET, POST, and so on). After some struggling I was able to make test work with get requests. Unfortunately with Post routes things didn't go well. When testing (netbeans 8.0.2 + phpunit) on local server (xampp 5.6.3) all I get is 404 error. Same thing if I run method being tested with Advanced Rest Client Application (chrome extension). When I send my rest files to live hosting then method in question works as it should.
After searching for some days (read about everything with 404 errors on Slim Framework) I decided to start with something which should work right of the box. Slim framework comes with simple demo app and some tests. Here I have another error which prevents start of tests:
Fatal error: Class 'Slim\Middleware' not found in C:\xampp\htdocs\web\local\codeguy-Slim-04958a1\tests\MiddlewareTest.php on line 3
As far I can tell I have something wrong with my xampp server but I don't have any more ideas how to fix this. So If somebody could show me correct way to setup Netbeans, Xampp, Slim and phpunit(I'm running it from IDE (ALT + F6)) then I would be able to build my rest api on top of that.
I just tried the following, maybe it might suggest a different route to try?
git clone https://github.com/codeguy/Slim.git
cd Slim
// Edit composer.json to include "phpunit/phpunit": "4.3.*"
curl -sS https://getcomposer.org/installer | php
php composer.phar install
./vendor/bin/phpunit
A few tests failed for me, surprisingly - so that would need digging into. But all classes were found.
Everything should work though, as the project seems to be building OK over on Travis CI.
I've found out what was wrong with my tests and with test provided with framework. I didn't know that I had to set bootstrap.php file in Project configuration of Netbeans.

How do I successfully create a project with Zend Framework and PHPUnit?

Let me just start by saying that I've posted this to multiple forums and even tried to get help on the ZF IRC channel. I've been Googling for a straight week and still no results. I've read a lot of Q's and A's on this site in the past, so I figured I'd make an account and try asking you.
(Yes, I've searched previously asked questions, but none of the answers helped me.)
I'm trying to learn how to use Zend Framework for a new project that I've joined. For compatibility reasons they are using Zend 1 (and not the newer Zend 2). I have found and followed a number of online and physical book tutorials but I've the same results over and over again.
So here goes (this are the instructions that all the tutorials give). I went to framework.zend.com and downloaded the full version of ZF 1.12.
I unzipped the contents
I moved the library folder to a safe directory where it won't be modified
I moved the contents of the bin folder to same directory as my PHP executable
I changed the include_path in my php.ini file to include the library directory
I updated my Windows PATH variable to make sure it included the path to the PHP executable
I ran
zf --help
This command worked as intended. I also successfully ran zf show version (Zend Framework Version 1.12.7).
I ran the command
zf create project myproject
Upon doing this, I receiving the following error message:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in D:\Zend\library\Zend\Test\PHPUnit\ControllerTestCase.php on line 48
That particular line in question is a class declaration that extends PHPUnit_Framework_TestCase. I don't know where PHPUnit_Framework_TestCase is defined. It is not in any of the files or directories that came in the single ZIP file that I downloaded from Zend. I even ran grep on all files and folders searching for the string "class PHPUnit_Framework_TestCase" but it printed no results.
Some have suggested that I don't have PHPUnit installed (which is obvious to me now). The part that bugs me is that absolutely none of the tutorials that I read mention anything about installing PHPUnit before hand or how to install it or what dependencies Zend has on it. Many of these were beginner tutorials that assumed you only had a basic knowledge of PHP, and it's pretty shocking to me that none even mentioned PHPUnit. If PHPUnit was that important I would think that the file I downloaded from Zend would have included it. I guess not.
So I went online again and got the PHAR file for PHPUnit, but now what? I tried putting it in multiple different directories but I still get the same error. Am I not supposed to use a PHAR file? Should I be using the actual files instead?
What do I have to do to get ZF to recognize PHPUnit, resolve this error and create my first ZF project?
Additional Info:
Windows 7, XAMPP Server (running on localhost), PHP 5.5.6
Assuming you have PHPUnit installed and it is on your include path (Bearing in mind that ZF1 only officially supports PHPUnit 3.4.x and definitely doesn't support anything above PHPUnit 3.5.x, so if you're using XAMPP you may have to downgrade PHPUnit as described here). The problem is most probably due to this commit, where the require calls for PHPUnit were stripped out in favour of using an autoloader. The ZF tool over CLI doesn't set up an autoloader though, so PHPUnit is not found because it is simply not required! To fix you can return these lines to the start of Zend/Test/PHPUnit/ControllerTestCase.php
/** #see PHPUnit_Runner_Version */
require_once 'PHPUnit/Runner/Version.php';
/**
* Depending on version, include the proper PHPUnit support
* #see PHPUnit_Autoload
*/
require_once (version_compare(PHPUnit_Runner_Version::id(), '3.5.0', '>=')) ? 'PHPUnit/Autoload.php' : 'PHPUnit/Framework.php';
It's worth noting that even with the error you mention, ZF tool should still work correctly when setting up a project, it just won't produce unit test actions (you'll have to make them yourself). If you don't want to downgrade your XAMPP PHPUnit version you should be able to add the correct version locally to your project using composer as described here.
Update Jan 2015:
Downgrading PHPUnit for XAMPP is no longer necessary as ZF1 has supported at least version 4.1 of PHPUnit since 1.12.7 (I've not tested above 4.1). This is helpful as PHPUnit has completely removed their deprecated Pear repository as of December 2014, which means you can't download versions older than 3.7 anymore anyway! (Currently XAMPP ships with PHPUnit 3.6). These days though it's probably worth chucking XAMPP for Vagrant and globally installing PHPUnit 4.1 via Composer during Vagrant provisioning.
I recommend using Composer to load both ZF and PHPUnit. Then make sure to include the Composer autoload.php file as your/in your phpunit boostrap file.
I had the same problem when I set up my laptop as a second development machine and downloaded the newest version of Zend Framework 1 (1.12.9). Whenever I tried to create a new action in a controller, I got the same error. Yet on my main computer, it worked fine.
I realized it was because the version of ZF1 I had in my php includes path was actually 1.11.11. So I went and got 1.11.14 from the ZF archives page, put it in the includes directory, and it worked fine.
Not entirely sure if this is the best way to make it work, since it is an older version, but at least it does work. And until someone actually comes on here and offers a better solution, that's what I intend to stick with.
You can create or edit a .zf.ini file in your home directory (~/.zf.ini or C:\Users\YOUR_ACCOUNT\.zf.ini on Windows)
php.include_path = "PATH_TO_THE_LIBRARY_FOLDERS_CONTAINING_ZEND_AND_PHPUnit"
basicloader.classes.0 = "PHPUnit_Framework_SelfDescribing"
basicloader.classes.1 = "PHPUnit_Framework_Test"
basicloader.classes.2 = "PHPUnit_Framework_Assert"
basicloader.classes.3 = "PHPUnit_Framework_TestCase"
If you are using Netbeans on Windows it could looks like this (you can put several library folder, just separate them with a semicolon ;) :
php.include_path = "C:\Users\romain\dev\ZendFramework-1.12.17\library;C:\Program Files\NetBeans 8.1\php\zend;C:\xampp\php\pear"
basicloader.classes.0 = "NetBeansCommandsProvider"
basicloader.classes.1 = "PHPUnit_Framework_SelfDescribing"
basicloader.classes.2 = "PHPUnit_Framework_Test"
basicloader.classes.3 = "PHPUnit_Framework_Assert"
basicloader.classes.4 = "PHPUnit_Framework_TestCase"

proc_open Too many open files in long running Symfony Console app

I built a console app with Symfony Console component. It supposed to be run for 5 hours. But after running 2 hours i have a proc_open(): unable to create pipe Too many open files error in Symfony\Component\Console\Application.php on line 985.
I tried gc_collect_cycles in my loop, but got the same error.
Is this a Symfony Console component bug or i should not run an app for this long (but i have to)?
I had this same error with a Symfony web-app, and restarting PHP resolved it.
I appreciate that you can't do that in the midst of your command's 5-hour run, but maybe doing it immediately beforehand will get PHP in a clean enough state to give you the full 5 hours?
(Also, this post is the only one I found about my problem, so I wanted to add this here in case others have the same issue as me!)
This issue is related to:
https://bugs.php.net/bug.php?id=47396
Apparently you're working on a lot of resources in your app. It's not a Symfony Console bug, it's a PHP bug.
You can use another programming language or modify your program in order to open less files.

Symfony2.0.15 Doctrine-Fixtures Windows Command Line Fatal Error

Recently started playing around with S2, amazing stuff! A while ago started an online Symfony2 Blog tutorial, however I got stuck on the page with Doctrine Data Fixtures generation,
Here is the message I'm getting when executing php app/console doctrine:fixtures:load in the console:
Fatal error: Class 'Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand' not found in C:\xampp\htdocs\blog-sf2\vendor\bundles\Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand.php on line 40
I am really stuck on it and I am running Windows 7, so can't really use deps file to pull dependencies from older versions (OR CAN I somehow??),
I've downloaded the newest versions of FixtureBundles and DoctrineFixtures.
Really appreciate any help on this one!
I think you need to read the installation documentation of this bundle for the 2.0 branch
You don't really "use the deps" file. The bin/vendors script uses it, and uses git. So what you need to do to "use the deps" is install git (and btw, install git-bash, you'll get a far better terminal).

Categories