Netbeans and PHPUnit Skeletion Generator: No such file or directory - netbeans

I use netbeans 7.2.1 and newest phpunit. When I want to generate a unit test in netbeans by right-clicking on the php class then Tools-> Create phpUnit test the Skeleton generator throws an error: No such file or directory.
require_once(/sharedResources/connection.inc.php): failed to open stream: No such file or directory
The issue is that the path displayed in require_once is wrong. It is generatedliek this:
$sharedResources = getenv("DOCUMENT_ROOT") . "/sharedResources";
and should resolve to the absolute file path. This works fine when application is running in apache. However it seems that getenv("DOCUMENT_ROOT") is just wrong when running from netbeans. My question is how I can set it correctly? My application is under
getenv("DOCUMENT_ROOT") . "/MyApp";
and the file I'm creating a test for is in
"MyApp/services"
Under Project properties there is an option web root but it is greyed out and it is impossible to set it to a folder one level higher than your application.
How can I solve this?
EDIT:
Further clarification:
I initially had a relative filepath to sharedResources which did not work also. the I changed to this one and of coruse ti makes sense it is not working as DOCUMENT_ROOT is set by apache and hence not set when running in netbeans. So a temprary fix is to add
$docRoot = getenv("DOCUMENT_ROOT");
if(empty($docRoot)){
putenv("DOCUMENT_ROOT=C:/xampp/htdocs");
}
to the head of every class. of course that is not a very practical or good solution. I would need to tell netbeans to set this environment variable or to use correct relative path.

Well here is my solution. It's not ideal but simple and works. The issue is that DOCUMENT_ROOT is obviously empty when script is not called by Apache but by netbeans. Hence it must somehow be set. To do that I edited the php file phpunit-skelgen(it does not have a file ending but it's a php file).
Below the license text as first php line I added
putenv("DOCUMENT_ROOT=C:/xampp/htdocs");
That did the trick.

Related

Netbeans, phpdocumentor, and custom phpdoc.dist.xml by project

I am using Netbeans 8.0.2 and phpdocumentor 2.8.2 on a windows 7 platform.
I would like to use custom phpdoc.dist.xml config files by project so I can specify framework directories and etc. to exclude from the generated doc. I also want to keep my Netbeans PHPDOC plugin config as generic as possible, without specific output directories, ignore options, config path parameters, etc., so on, so that that the config will apply to all my projects.
The phpdoc.dist.xml file works great. The doc generated is exactly what I want.
The problem or feature, and it seems to be a phpdocumentor one as it also applies from plain command line, is that the phpdoc.bat command (without a specific config parm) has to be run from the same root directory as the phpdoc.dist.xml file, or it ignores it. No problem if I'm using command line as I can change into that directory first, but I would like to use Netbeans. I have searched on this extensively and cannot find an answer.
I considered whether to modify the phpdocumentor files to insert cd /D path/to/myproject/dir to change the directory using some Netbeans variable to represent myproject/dir, but I could not find the right place in the code or the variable to use. Plus, then I'm supporting a custom mod to phpdocumentor.
I did find these directions for a PHPStorm setup, where the author specified a PHPStorm variable for the --config command line option to point to his custom phpdoc.dist.xml.
--config="$ProjectFileDir$/phpdoc.dist.xml"
If I could do the same in Netbeans like maybe "${BASE_DIR}/phpdoc.dist.xml" it would be great, but so far I haven't hit on anything Netbeans will recognize/pay attention to in the PhpDoc script: box.
I have also tried writing a wrapper .bat file to capture my own command line variable %1 and do the directory change to that before calling phpdoc.bat, but Netbeans throws and error and says that's not a valid .bat file. I cannot find any phpdocumentor parameter to configure by specific Netbeans project but the output directory. And I would prefer not to be defining a bunch of projects on subdirectories in Netbeans, just to address phpdocumentor.
Now I am out of ideas. Can anyone point me to a solution?

Using zftool in a more efficient manner

I'm new to Zend and noticed there's something called ZFtool. So I installed it via this tutorial: http://framework.zend.com/manual/2.1/en/modules/zendtool.introduction.html. With some hassle and editting I finally got it to work in my htdocs folder of xampp.
Whenever I now run php vendor/zendframework/zftool/zf.php create project testproject it actually creates a project in my htdocs called testproject. But whenever I now want to add a module I'd have to do php vendor/zendframework/zftool/zf.php create module some_module c:/xampp/htdocs/testproject.
Now; I've got the feeling that this can(or atleast SHOULD) be more efficient than how I'm going at it now. Is there a way I can make the zf.php file universally reachable or anything to make the command line a little easier?
Download zftool.phar from : https://packages.zendframework.com/zftool.phar
Place it on:
C:\bin\zftool.phar
Create zftool.bat on:
C:\bin\zftool.bat
zftool.bat
#ECHO OFF
php "%~dp0zftool.phar" %*
Add this path to your Environment Variable:
Now you are able to use zftool from anywhere in your command prompt like this:

pydev directory django shell

I'm using PyDev in a django project of mine.
When I start the django sheel, the os.getcwd() command returns my home folder.
This is bad, since my code points to some resources by relative paths, assuming as current directory the directory containing the manage.py.
In this post (http://stackoverflow.com/questions/2746342/pydev-and-django-pydev-breaking-django-shell) someone recommended to use absolute paths to avoid this problem.
But I think it is a very bad practice, since things will not work when other people checkout the code into their computers.
The closest hint I found here:
http://old.nabble.com/-pydev---Users--how-to-set-working-directory-for-console--td25328455.html
It seems we can use "Run/Debug Settings" to set the current directory associated to a "runnable module". However, in this way we cannot associate the setting to the django console. I have tried to associate it with the manage.py, but it did not work.
So, the question: how to define the working directory of django shell?
Thank you,
Leonardo

$_SERVER['ZEND_PHPUNIT_TESTS_LOCATION'] not set correctly in Zend Studio

I set up unit testing in Zend Studio last week, and it was working fine.. until suddenly after some refactoring, I got an error that the following file was not found in ZendPHPUnit.php:
/var/folders/Td/Tdnh++2KEdWAsk8Y0O4N0k+++TI/-Tmp-/zend.phpunit.UserMapperTest.php.2428213892936827201.php
The file path is stored in $_SERVER['ZEND_PHPUNIT_TESTS_LOCATION'] in ZendPHPUnit.php
I checked the folder and I found
zend.phpunit.UserrMapperTest.php.6031927106542896607.php (the number is different)
I was a little desperate so I made it work by forcing
$_SERVER['ZEND_PHPUNIT_TESTS_LOCATION'] = '/var/folders/Td/Tdnh++2KEdWAsk8Y0O4N0k+++TI/-Tmp-/zend.phpunit.UserMapperTest.php.6031927106542896607.php';
Eventually, after I worked with a few other test cases, the problem fixed itself. Now, I refactored some code again, and the problem is back. None of my testcases work.
Restarting the comp doesnt help, Project -> Clean doesnt help. I am on a mac running Snow Leopard.
Any insights on what is causing this?
Thanks!
The problem is that PHPUnit doesn't work with the files themselves but with copies of the files that it creates on the fly and stores on directories that are also created on the fly. These files are modified to include PHPUnit logic. This goes for the test files themselves as well as for the php.ini (which forces you to load extensions in the main php.ini file for the tests, since additional .ini files are ignored). Every time you run the tests these files will be re-created with a new unique name (original name plus unique identifier).
The best way that I've found to work around this issue is to create launch configurations for the tests and save them as .launch files in your project (right click -> run as -> create new PHPUnit config -> select "shared file" in the common tab). Once you have the launch configs you can just run this by opening on the editor and clicking the Run button. You will see that after every time you run them there will be a line like the following on each launch file that has changed (easy to see if the configs are in version control):
<mapEntry key="ZEND_PHPUNIT_TESTS_LOCATION" value="/var/folders/my/ph9spb0s45z5_11l9tqw256r0000gn/T/DefaultWorkspace.phpunit.AssignmentRequestControllerDateCriteriaTest.php.4951739174960507380.php"/>
I usually just commit this change together with whatever other changes I've been working on at that time.
It's still kind of annoying that the file changes and thus the launch config, but at least in this way your tests will always run and you don't have to worry about having to re-run the manually, or clean the project, or anything like that.

Zf Tool cannot find Zend Framework

Just started working with the Zend Framework Zf Tool and I've already come across a problem I've spent hours trying to figure out.
For some reason when I run the Zf show version command I get a ZF ERROR indicating it cant find the Zend Framework a to add it to my php.ini include_directory.
Here is my setup. I'm currently have WAMP installed on my local machine.
c:\wamp
I copied the zf.bat and zf.php files into the servers php directory. The path to the php directory has been added to the path environment variable. I'm pretty sure it works because I run the zf show version command in the console and get a ZF ERROR.
I keep my copy of the Zend Framework inside
c:\wamp\includes
So I added this to the php.ini include_path. include_path = ".;c:\wamp\includes"
I checked that this setting was set correctly by checking phpinfo() function. Which shows
include_path .;c:\wamp\includes .;c:\wamp\includes
So I think I have everything setup correctly. I can't work out what I'm missing.
I also tried setting the ZEND_TOOL_INCLUDE_PATH with no success.
Any help would be appreciated. PS I did check other posts here but none of the suggested
I have worked it out! Finally. The way I have my local wamp setup there is 2 php.ini files I have to edit.
The one that made the different is the php.ini inside the Apache2 directory.
Thanks everyone for their help. I appreciate it.
Well im not sure how you downloaded installed the framework but my guess is that you dont have enough of you include path based on the way Zend release packages are constructed. The Zend folder contained in the Zend Framework installation needs its parent folder to be on the include path so typically you would add something like:
c:\wamp\includes\ZF_BASE_DIR\library
This is because the zf package structure looks like:
ZendFramework-VERSION/
README.txt
INSTALL.txt
LICENSE.txt
bin/
library/
If you extracted ZF from the archive you will get a Zend-some_version folder, but the actual ZF is in
"include_path\Zend-some_version\library\Zend", so your include path should point include_path\Zend-some_version\library\
Just to add to what Tjorriemorrie said and to explain in detail how I got my installation on win 7 to work as simply as possible:
Download your preferred Zend package from "http://framework.zend.com/downloads/latest" to "C:\wamp\www\"
unzip your zip file so that you have the extracted Zend folder (with version name) under "C:\wamp\www\".
Rename your folder by removing the version so that you end up with "C:\wamp\www\ZendFramework"
Run a simple php file with phpinfo() in your browser. Note the entries for: "_SERVER["PATH"]" under PHP Variables
"Path" under Environment
"Loaded Configuration File" at the top
"include_path" under Core and
"extension_dir" under Core as well.
"_SERVER["PATH"]" and "Path" must be identical (no brainer)
There should be only one listing for your apache server and that should be the listing under "Loaded Configuration File" but without the "php.ini". So, if your "Loaded Configuration File" is "C:\wamp\bin\apache\apache2.2.22\bin\php.ini" you must have "C:\wamp\bin\apache\apache2.2.22\bin" in your path and that must be the ONLY reference to an apache server. If you have multiple references to apache servers Windows may pick the wrong one depending on your PATH order and use the wrong php.ini file.
Your "extension_dir" will tell you the version and location of php you are using. It is common to have different php folders lying around such as "C:\php", "C:\wamp\bin\php\php5.4.3", "C:\wamp\bin\php\php5.3....", etc. The extension directory will tell you which one of these php folders ZF will "reference" when it is looking for its library. For example, if your extension directory says "c:/wamp/bin/php/php5.4.3/ext/", you want to focus on "c:/wamp/bin/php/php5.4.3"
Go back to your PATH and a) add the string for this php version and b) remove all the other references to the other php folders
Now that you know your running and primary php and apache folders, shutdown (do not restart), shut down your computer and boot back up (restart does not always let the PATH completely reset.
Go to BOTH php.ini files at a) "C:\wamp\bin\apache\apache2.x.y\bin" and "C:\wamp\bin\php\php5.4.3" and find the include_path variable for Windows
Replace the default line, which looks like:
;include_path = ".;c:\php\includes;"
with
include_path = ".;c:\php\includes;C:\wamp\www\ZendFramework\library"
ON BOTH FILES just as Tjorriemorrie notes.
Restart All Services by clicking the wamp icon and selecting said option
At this point my zf tool was working. But, just to be safe, shut down and bootup
Smile and grab a beer!