phpunit not recognise curl while its activated on wamp server - php

hi i'am using phpunit with selenium webdriver.
when i make this cmd
phpunit myfile
i get this error message
Call to undefined function curl_init().4.3\pear\PHPUnit\Extensions\Selenium2TestCase\Driver.php
my code is
<?php
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://www.google.com/');
}
public function testTitle()
{
$this->url('http://www.google.com/');
$this->assertEquals('google', $this->title());
}
}
?>
some says to check my curl i have to cmd this
php --ini
but the response outed in many line ,there are some line outed before but hidden
how te see the previous line on the DOS ?

Enable curl by clicking on wamp server icon on the task bar and click php then select php extension and select curl and also verify that u have this line in your php.ini
php extension=php_curl.dll
for more refer this php.net/manual/en/book.curl.php

Remember that phpunit is probably run in the command line and the command line uses a different php.ini
If you want to find out, which one would be the correct php.ini, just run this command in the command line:
php -i | find /i "Configuration File"

I solved the problem by copying php.ini from apache to my php folder.

Related

Php artisan serve require fatal error after upgrading php7

After upgrading php from 7.0.14 to 7.0.26 php artisan serve throws this error
Warning: Unknown: failed to open stream: No such file or directory in
Unknown on line 0
Fatal error: Unknown: Failed opening required '/Applications/XAMPP/xamppfiles/htdocs/school-dashboard/public/server.php'
(include_path='.:') in Unknown on line 0
Ok, after hours of pulling my hair out I finally found out what the issue was.
In laravel 4 php artisan serve does this under the hood
<?php
namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
class ServeCommand extends Command {
public function fire()
{
$this->checkPhpVersion();
chdir($this->laravel['path.base']);
$host = $this->input->getOption('host');
$port = $this->input->getOption('port');
$public = $this->laravel['path.public'];
$this->info("Laravel development server started on http://{$host}:{$port}");
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" server.php");
}
}
That is essentially this in plain php:
php -S 127.0.0.1:8000 -t public serve.php - see the docs for php built in server for more info.
And this worked well and dandy before php 7.0.26, where the last parameter for the php -S built in server was changed to a flag as well, so you have to call it like this php -S 127.0.0.1:8000 -t public -f serve.php.
If you want to serve it with php artisan serve you will have to override the ServeCommand and change the last line of the fire() method to this:
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" -f server.php");
Or you can change it directly in the ServeCommand, but if you do a composer update or install you will have to do it again.
That's what it happened to me today running a Laravel project. After i have tried all the possible solutions finally i got one that it's work for me . So first of all check that your anti-virus block your server.php and it also deleting it . Then check if you server.php is missing from your project, and I think that is probably yes . Just copy it (server.php) from other project (build also from laravel) but before that just turn off your anti-virus until your next restart and make you sure that you will stop it every time before running. I hope that it helps you.

Reset PHP cache via command line

When I try to reset cache from command line with:
php -r "opcache_reset();"
I get the following error message:
Call to undefined function opcache_reset() in Command line code on
line 1
Is there a way to add the opcache_reset function to PHP via php.ini or something like this?
Thanks for help.
You need to check your php.ini config files.
Option 1)
Enable the following flag in your opcache config, likely under mods-available
opcache.enable_cli
Option 2)
If you have different config for CLI and apache2/fpm then check the CLI version has enabled opcache

yaml_emit_file() not working. Call to undefined function yaml_emit_file()

The php function yaml_emit_file() is not working. I have installed and included the php_yaml.dll in my php.ini file restarted the server but still when I use this function, I get this error (when I run composer):
Call to undefined function RS\composer\yaml_emit_file()
Okay so a little about the background:
PHP version 7.1.7 & Composer version 1.5.1
I am using this function in a ScriptHandler.php file which is invoked when Composer is run. In this script I have a function buildModuleList which is called on post-update-cmd event of Composer. Everything else in the code is working fine.
I am in doubt that maybe I am using this function in wrong context or something like that.
Here is the code snippet where I am using yaml_emit_file() (Providing this just for reference, tell me if am using it the wrong way!):
if (!$fs->exists($moduleListFile)) {
$fs->touch($root.'/profiles/thunder/modulelist.yml');
$fs->chmod($root . '/profiles/thunder/modulelist.yml', 0666);
if(!empty($moduleList)){
$createyml= yaml_emit_file($moduleListFile, $moduleList);
if (!$createyml){
$io->writeError('<error>Cannot create modulelist.yml</error>');
}
}
$io->write('Success: Created new modulelist.yml', $newline= TRUE);
}
else{
$fs->file_put_contents($moduleListFile, $installedPackage, FILE_APPEND);
$io->write('Success: Module entry in modulelist.yml', $newline= TRUE);
}
i hope this help someone i test it on
Windows 10
XAMPP v3.2.4
PHP 8.0.2
Download the latest YAML DLL Package from : https://pecl.php.net/package/yaml
Unzip the files
Move the php_yaml.dll file to xampp/php/ext folder
Open your php.ini in xampp/php add a new line extension=php_yaml.dll, save and exit
Restart your XAMPP Servers
make a PHP file put into
<?php
phpinfo();
?>
Search the string yaml on the page. If it says Enabled then your YAML Extension is working.

When I call controller action using cronjob. It's give fatal error like "Call to undefined function mysqli_init()"

When I am calling controller action using cronjob. It gives me error like
Here, Is My controller:
class CronCount extends CI_Controller {
public function index() {
$this->load->model('LogFunctionModel');
$todayActive = $this->LogFunctionModel->activeCompany(date('Y-m-d'));
$company_count = $this->LogFunctionModel->otherCount('company');
$employee_count = $this->LogFunctionModel->otherCount('employee');
$user_count = $this->LogFunctionModel->otherCount('user_logins');
$dollars_on_account = $this->LogFunctionModel->userDollar();
//log entry
$this->load->library('logfunction');
$this->logfunction->logCountRecord("Companies Active", $todayActive->active);
$this->logfunction->logCountRecord("Company Count", $company_count->total);
$this->logfunction->logCountRecord("Employee Count", $employee_count->total);
$this->logfunction->logCountRecord("User Count", $user_count->total);
$this->logfunction->logCountRecord("Dollars on Account", $dollars_on_account->balance);
}
}
System Configuration
OS : Linux mint
Database : Mysqli
PHP Version : 7.1.1
Project Directory : /opt/lampp/htdocs/
When I am run controller directly from browser Its work fine. But When I am run using the terminal then it gives me above error you can show in above image. How can I solve that?
PHP CLI and PHP FPM/php_mod have different configuration (php.ini files). You must to check if the mysqli extension is enabled in the PHP CLI.
Just run php -i | grep mysqli and check if mysqli is in the output.
Always use a full path to PHP (/opt/lampp/bin/php) when you are using XAMPP, because in other way you will use the PHP which is installed directly in your OS (not from XAMPP package). Try to run /opt/lampp/bin/php /opt/lampp/htdocs/PayrollCommand/index.php croncount

oci_pconnect error when ran in windows task scheduler

I'm trying to run a script that imports data from an Oracle table into a Mysql table. I'm using oci_pconnect to connect to Oracle. Everything is running fine when the script is executed in the browser but i'm getting the following error when the script is run in cmd under Windows
Fatal Error: Call to undefined function oci_pconnect()
I'm calling the php script in cmd by the following code
#echo off
php C:\wamp\www\somefile.php
echo Done!
pause > nul
Thanks in advance!!
To avoid having this error, just go to php.ini located in your PHP folder and uncomment the line of the oci function in the extensions section:
;extension=php_oci8.dll
problem solved!

Categories