I've been reading up on TDD using PHP and i'm ready to install PHPUnit, however...
I'm on Win7/64 running WampServer
I'm reading all these PEAR/PHPUnit install nightmare stories which are making me very leery.
So I'm considering using Composer to install PHPUNit (to skip the whole PEAR thing, for now).
Either way, it seems that it's best to have PHP in the PATH, which is not the case for default wampserver setup I suppose (since it's NOT already in my PATH)
I'm a bit confused about exactly which php file I should be adding to the PATH, as my directory (C:\wamp\bin\php\php5.3.10) has the following files:
php.exe
php-win.exe
I was planning on using number 1.
Finally, are there any other caveats that I should be aware of.
I'm using NetBeans (and SublimeText2 for front end stuff) and WampServer 2.2
Thanks!
sleeper
I Solved it. I just add the directory (C:\wamp\bin\php\php5.3.10), not an individual file. See my comment.
Related
I've just imported a largish php project into NetBeans. Under the top directory I have "app1", "app2", "app3", etc. (each of which are mapped to a domain name), then a "shared" directory for (you guessed it) files used by all the apps.
In app1/route/Search.inc it has:
include_once "../shared/lib/search.inc";
But ctrl-B on this line does nothing. Makes sense, from NetBeans point of view of this as one large application, it should be "../../shared/lib/search.inc". But, for the way the apps are configured, the above is correct, and NetBeans is wrong.
How do I tell NetBeans it needs to go one extra directory up?
Under Include Path, I tried adding "/full/path/to/app1" (so then "../shared/lib/" would be found) (I tried Private tab, then Shared tab, with same results.) But it rejects that, telling me the app1 directory is already part of the application. There is no "Do what I say, and don't think about it, slap!" button.
Adding symbolic links in the file system, just for NetBeans, feels a bit ugly.
I'm wondering if I should make one NetBeans project per app? (I actually tried that first, but as all apps are in the same git repository it gave a lot of noise, so I assumed that was the wrong way.)
ADDITIONAL: I'm most interested in the answer to my last question - is it standard practice to keep each app as a separate NetBeans project, even if they are all in the same git repository?
Product Version: NetBeans IDE 8.0.2 (Build 201411181905)
Updates: NetBeans IDE is updated to version NetBeans 8.0.2 Patch 1
Java: 1.7.0_79; OpenJDK 64-Bit Server VM 24.79-b02
Runtime: OpenJDK Runtime Environment 1.7.0_79-b14
(on linux Mint 17)
Make shure that all files of your project are in the project's include path (righ click project -> properties -> include path). Usually there is only the "global include path", which you configure in the NetBeans settings (e.g. to point to your PEAR directory). Add all directories which contain source code you want auto completion for to this include path. Hint: This include path has nothing to do with the include_path used in PHP itself.
I'm wondering if I should make one NetBeans project per app? (I actually tried that first, but as all apps are in the same git repository it gave a lot of noise, so I assumed that was the wrong way.)
Yes you should have different NetBeans projects if your apps are separate, and since they are on different domains, it sounds like they are pretty distinct.
One way you can reduce the noise level of this approach is to right click the other app directories and find the option to Mark directory as > excluded and it should disappear (and the files won't be indexed for autocomplete / search / etc).
I have no problems with such a scenario, if I only select the filename. Then NetBeans search for a file with this name in the whole project directory.
If I select the filename and the path, it does not work. Maybe that is your problem?
I have changed nothing else and it works like a charm.
there is a alternative way to set path i.e. via php.ini
add the following line in php.ini set path of
include_path = ".:c:\xampp\htdocs\project_name\your_include_folder_name"
restart the apache server
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"
I am trying to get PHPUnit working on my cakePHP application.
I have downloaded and setup all the necessary files
In my php.ini file , I put
include_path = ".;c:\wamp\bin\php\php5.4.12\pear\PHPUnit"
But I do not think this is correct.
When running cakePHP's app/test.php, I get 2 warnings to include PHPUnit\Autoload.php
Ok, so for whatever reason, no one here decided to hep me out on this one.. Which is a little bit frustrating.. But no matter! I'm going to provide the solution for others whom like me, are new to PHP and PHPUnit, and want to get into unit testing
Steps I followed :
Install PEAR, download from the PEAR website
If you find yourself having trouble, follow this guy's tutorial
Download PHPUnit
Put PHPUnit in local file.. (www or equivalent)
Install PHPUnit with PEAR (If integration with cake, make sure you follow these steps)
If you already installe v.4, you can downgrade using the command
pear uninstall phpunit/PHPUnit
and install PHPUnit-3.7.32
Finally visit php.ini and make sure that path included points to the pear directory
In my case include_path = ".;c:/wamp/bin/php/php5.4.12/pear"
Cheers and happy coding
This may be more of a systems question, but as I need it for a Vagrant development environment, I thought I would ask it here.
I am using Vagrant and Chef to create a PHP development environment. It's working correctly, but the setup takes forever because I'm installing PHP from source because I need some custom configurations.
Is there a way to install PHP through Vagrant once, capture all changes made by the build in an archive, so I can just unpack the archive?
It is worth considering building the custom-configured PHP into a deb (or any other) package, so you actually install already compiled PHP with your custom stuff inside.
It still depends how customizable you still want your build to be - I have no idea what you're actually trying to achieve as you haven't mentioned specifics of your custom PHP build.
I'm trying to fix a bug in a more complex PEAR package (CodeCoverage). So I'd like to have the development version that exists not within my PEAR path:
c:\Programme\PHP\PEAR\PHP
with one on another location, here exemplary:
c:\Dokumente und Einstellungen\hakre\PhpstormProjects\php-code-coverage\PHP\
Is there a common way in PEAR to temporarily switch from the installed package to just the files on another location of the disk?
I tried with placing a symbolic link, but that does not work because I need to link CodeCoverage.php as well which is not possible on Windows XP.
Is there some kind of development switch for this kind of scenario in PEAR or is it just that it's the business of each package to take care of that?
I'm using the CodeCoverage package together with PHPUnit.
I could get it to work by adding it to PHP's include path before the PEAR dir:
include_path = ".;c:\path\to\php-code-coverage;C:\programme\php\pear"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Invoking PHPUnit now uses the standard package but the development version of CodeCoverage. No symbolic linking required, editing php.ini is enough.
The "Contributing" section of the PHPUnit github project has a runner script included to make that task easier for you.
You can ether check out all the repositories from there or, if you only need one, still use the runner script:
#!/bin/bash
php -d include_path='.:../phpunit/:../dbunit/:../php-code-coverage/:../php-file-iterator/:../php-invoker/:../php-text-template/:../php-timer:../php-token-stream:../phpunit-mock-objects/:../phpunit-selenium/:../phpunit-story/:/usr/local/lib/php' ../phpunit/phpunit.php $*
(intentially not formatted as code so the whole thing is shown)
You can adapt the pathes to an absolute one by replacing .. with /path/to/your/dev/folder/ and put the script in /usr/local/bin/ and call it phpunit-dev.
Then it will automatically pick up all the existing folders and fall back to the pear path at the end for everything it can't find.
Another way to get a dev setup quickly would be to install it from composer with minimum-stability: dev and change the remote on one of the repos :)