I use the latest version of Netbeans on Windows, and connect to a remote Ubuntu Apache server to a Zend Framework project. I installed on that server PHPUnit, but I didn't know what is the absolute path to the phpunit.bat (I need th absolute path in NetBeans Option->Php->Unit Testing). I installed XAMPP on my computer and tried to use PHPUnit within XAMPP and the project from the remote server, but I have problems with the include paths, for example I get this error:
'Warning: include_once(PHP\Invoker.php): failed to open stream: No
such file or directory in Y:\mos\public_html\library\Zend\Loader.php
on line 146'.
Here is my bootstrap.php file:
<?php
error_reporting( E_ALL | E_STRICT );
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
define('APPLICATION_PATH', realpath('Y:/mos/public_html' . '/application'));
define('APPLICATION_ENV', 'development');
define('LIBRARY_PATH', realpath('Y:/mos/public_html' . '/library'));
define('TESTS_PATH', realpath(dirname(__FILE__)));
$_SERVER['SERVER_NAME'] = 'http://mos.loc';
$includePaths = array(LIBRARY_PATH, get_include_path());
set_include_path(implode(PATH_SEPARATOR, $includePaths));
require_once "Zend/Loader/Autoloader.php";
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);
Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();
?>
Can I set somehow the absolute path to the PHPUnit on the remote server from Netbeans, or can I make it work using the project from the remote server, and PHPUnit from my XAMPP?
Perhaps your mapped network drive isn't mapped under whatever account is running the web server.
Under your own account, check what the mapping is for your Y drive:
C:\>net use
The output should be something like this:
New connections will not be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
OK Y: \\server\share Microsoft Windows Network
Then modify your PHP script to attempt to map the drive for your scripting purposes:
<?php system("net use Y: \\server\share password /user:username /persistent:no >nul 2>&1"); ?>
Related
I have a very simple PHP/Composer application with the following structure:
- src
- content
- test
- Sandbox.php
Sandbox.php has only a static function to print "test" and its namespace is
namespace MyApplication\Content\Test;
My autoload.php has MyApplication an "autoload" property.
"autoload" : {
"psr-4": {"MyApplication\\": "src/"}
},
I run composer install --no-dev in an Windows environment with XAMPP and in a test.php file I do (for the sake of a very simple test):
$autoloadFile = __DIR__ . '/wp-content/plugins/sandbox/vendor/autoload.php';
require $autoloadFile;
echo 'autoload = ' . file_exists($autoloadFile);
echo '<br />';
echo 'class_exists = ' . class_exists('MyApplication\Content\Test\Sandbox');
When I run this test.php file locally, it works perfectly. MyApplication is loading Sandbox class.
However, when I release this to my server which is a Linux based server but running on the same PHP version, Sandbox class is not found.
I made sure my /vendor/ folder is properly uploaded as well.
I'm wondering if the problem is happening because I'm running composer install on a Windows environment while it should be running the same command in my server (which I can't at the moment). Shouldn't the /vendor/ folder upload be enough to make the autoload classes work well?
Path to your file is src/content/test/Sandbox.php and according to PSR-4 it should be src/Content/Test/Sandbox.php - on Windows it does not matter, but on Linux it does.
I have an error that happens only on my host server, on my local environment not:
Fatal error: require_once() [function.require]: Failed opening required '\Audero\Loader\AutoLoader.php' (include_path='.:/usr/share/pear:/usr/share/php:/home/httpd/vhosts/webox-it.com/ofrom.webox-it.com/modules/Concordancier....\lib') in /home/httpd/vhosts/webox-it.com/ofrom.webox-it.com/modules/Concordancier/data_manager.php on line 1670
Here is my code:
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/../../lib/');
require_once 'Audero\Loader\AutoLoader.php';
spl_autoload_register('Audero\Loader\AutoLoader::autoload');
// Extract the chunk and save it on the hard disk
try {
$extractor = new \Audero\WavExtractor\AuderoWavExtractor($inputFile);
$extractor->saveChunk($start, $end, $outputFile);
...
Files structure:
/lib/Audero/Loader/Autoloader.php
Calling file emplacement:
/modules/Concordancier/data_manager.php
In my local environment there's no problem, php can load the autoloader, but in the prod server it does not.
The source files structure is exactly the same as the local one, and the relative path looks correct. The php version in prod is 5.3.27 so it should work ?
Any idea ?
I'm experiencing a problem with my 'include' path on my fresh install of Zend framework. i'm running Ubuntu and using Netbeans. I installed Zend via the terminal and I have copied the appropriate files to my new project.
I am currently getting this while attempting to access localhost/demoZend/public
Warning: require_once(Zend/Application.php): failed to open stream: No such file or directory in /home/mastered/public_html/demoZend/public/index.php on line 18
Fatal error: require_once(): Failed opening required 'Zend/Application.php' (include_path='/home/mastered/public_html/demoZend/library:.:/opt/lampp/lib/php') in /home/mastered/public_html/demoZend/public/index.php on line 18
I have copied the 'Zend' folder with the framework into my project/library folder so the folder structure is /demoZend/library/Zend/
I have also changed the 'include' path in my php.ini from the advice of a tutorial. however this is where I have things confused.
The path reads:
include_path = ".:/usr/share/php:/usr/share/php/libzend-framework-php/"
in my apache2/php.ini aswell as my /etc/php5/cli/php.ini file.
My index.php file in my project reads as thus:
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
I haven't changed that as the file paths seem ok.
I should also point out I have my web documents stored in my '~/public_html' directory, I have checked the permissions on my 'demoZend/library' folder and they have all restrictions off.
It sounds like you're following a tutorial for Zend Framework 1, but you've downloaded Zend Framework 2. There is no Zend/Application.php in ZF2, so that's why PHP isn't finding the file.
You can either head back to the ZF downloads page and grab the latest release of ZF1 (currently 1.12.3), or find a ZF2 tutorial and learn ZF2 instead. If you're just getting started with ZF, I'd go with the latter option.
I am having a hard time trying making PHPUnit work. My Directory is for php is C:/wamp/bin/php/php5.4.3 Now, I read PHPUnit does not work without PEAR, so I got the go-pear.phar file and placed it in C:/wamp/bin/php/php5.4.3/PEAR/ ran the go-pear.phar file and installed in on the system. third, I installed PHPUnit using Git Bash and put it in C:/wamp/www/local/unit-testing/ (Not sure if the directories are correct)
Now, I created a simple UserTest file
<?php
require_once "phpunit/PHPUnit/Autoload.php";
require_once "User.php";
class UserTest extends PHPUnit_Framework_TestCase
{
protected $user;
// test the talk method
protected function setUp() {
$this->user = new User();
$this->user->setName("Tom");
}
protected function tearDown() {
unset($this->user);
}
public function testTalk() {
$expected = "Hello world!";
$actual = $this->user->talk();
$this->assertEquals($expected, $actual);
}
}
And tried to require this file and run it from the command line in Windows. But, due to lack of instructions on where this files should exactly be, I can't seem to run it.
As of now the problem is command line does not recognize the PEAR command. Even though, I had run PEAR_ENV.reg file to add PATH variables to the file.
secondly, I am not sure where exactly PEAR & PHPUnit should be installed in my current structure. I keep all my php pages/project in C:/wamp/www/local/<-- I need to test files in this directory.
The PHPUnit batch file should be in your path. Then running PHPUnit from the command line would be done in a shell, with the current directory being where you have installed everything, and it assumes that your User.php file is there as well.
I sue a bootstrap.php file to run from my source code directory.
<?php
/**
* This file is used to configure the basic environment for testing in PHPUnit.
*/
// PHP and Web server settings
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set("America/Toronto"); // Set the default timezone
$_SERVER['SERVER_NAME'] = 'http://xxx'; // Set Web Server name
// Process the Include Path to allow the additional applications to be set.
$IncludePaths = explode( PATH_SEPARATOR, get_include_path() );
$NewIncludePaths = array_merge( $IncludePaths, array(dirname(__FILE__) ));
set_include_path( implode( PATH_SEPARATOR, array_unique($NewIncludePaths))); // Update Include Path
//define('PHPUNIT_RUNNING', 1); // Indicate to the code that Automated Testing is running.
?>
I was able to follow the PEAR Installation Instructions for PHPUnit and get things up and running once the directory where PHPUnit.bat existed was in my DOS Path.
These are code of my PHP applications myApp.phpand mypartsA/main.php.
myApp.php
<?php
echo ("##### myApp is starting now !!! </br>");
require_once('/parts/mypartsA/main.php');
?>
mypartsA/main.php
<?php
echo ("#### mypartsA is required </br>");
?>
And myApp.php and mypartsA/main.php are in following structure.
Document_root
|
+--- test
| |
| +--- myApp.php
|
+--- parts
|
+--- mypartsA
|
+---main.php
I’ve used this application on Windows+Apache for a year with no problem but recently I migrate this to CentOS+Apache then I get fatal error related to include_path
PHP Warning: require_once(/parts/mypartsA/main.php)
[<a href='function.require-once'>function.require-once</a>]
: failed to open stream
: No such file or directory
in /var/www/html/test/myApp.php on line 12
PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]
: Failed opening required (/parts/mypartsA/main.php’
(include_path='.:/php/includes:/usr/share/pear:/usr/share/pear/PEAR:/var/www/html')
in /var/www/html/test/myAPP.php on line 12
According to PHP.net if a path is defined the include_path will be ignored.
http://www.php.net/manual/en/function.include.php
I think in my case PHP tries to find parts directory from C:\ or / not from include_path.
require_once(/parts/mypartsA/main.php);
Therefore result of myAPP.php must be fatal error whether on Windows or on CentOS.
But my application has been working for a year with no error on Windows. PHP can find parts directory correctly.
Can sameone try those codes above on Windows and see..
##### myApp is starting now !!!
#### mypartsA is required
or get error?
Now,I want to know is why results of same code are different between running on Windows and running on CentOS.
What dirctive in PHP.ini do I have to check ?
I know if I change this code to add absolute path with $ _SERVER['DOCUMENT_ROOT'].
require_once($_SERVER['DOCUMENT_ROOT']./parts/mypartsA/main.php);
It’ll work well. But there are many applications with same style of coding and I don’t want to change all of them.
These are additional information.
include_path values phpinfo() shows on Windows
.;C:\PHP;C:\PHP\pear;C:\Apache2.2.22\htdocs
include_path values phpinfo() shows on CentOS
.:/php/includes:/usr/share/pear:/usr/share/pear/PEAR:/var/www/html
$path = realpath(dirname(__FILE__)) . "/../../parts/mypartsA/main.php";
require_once($path);
try with this path
$path = "../parts/mypartsA/main.php";
the second path should work with document root.