mcrypt and PHPUnit - php

I am using PHPUnit to test a project where mcrypt is heavily used. I have installed phpunit using this SO answer.
Whenever I try and run phpunit, I get the following error:
Fatal error: Call to undefined function mcrypt_create_iv() in
/files/file/using/mcrypt/thing.php on line 20
How can I fix this error? Do I have to install mcrpyt especially for PHPUnit?

You can either install MCrypt (which you should do anyway) or mark that specific test as one requiring MCrypt. The latter will cause the test to be skipped if you don't have MCrypt installed.

Related

Getting an PHP Deprecated error : ReflectionParameter::getClass() [duplicate]

after updating my mac to php 8 laravel app stopped working, this is the error I'm getting:
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945
I've tried to fix the issue by investigating the code with no luck
THE SOLUTION
As explained here latest version of laravel 6, 7 and 8 has made changes required for php 8. all you have to do is:
1- add php 8 to your composer.json (I've kept v7.4 just in case production server does not support php 8 yet)
"php": "^7.4|^8.0",
2- to run composer update to update your laravel to the latest version
composer update
3- make sure update the following libraries since they exist in all laravel applications
PHP to php:^8.0
Faker to fakerphp/faker:^1.9.1
PHPUnit to phpunit/phpunit:^9.3
4- check for any other library which needs to be updated, contribute if they haven't supported php 8. but you should be good to go with most of the libraries since they have active contributors.
EXPLAINING THE PROBLEM
as described here
PHP 8 introduces several improvements in PHP type systems such as the introduction of Union Types, mixed type, and a few more.
With these changes, certain methods in Reflection API's
ReflectionParameter yield incorrect results.
In PHP 8, the following methods from ReflectionParameter class is
deprecated:
ReflectionParameter::getClass()
ReflectionParameter::isArray()
ReflectionParameter::isCallable()
ReflectionParamter::getType() is the recommended way to replace the
deprecated methods. This method is available in PHP 7.0 and later.
Check your php version in your virtual machine(xampp or server).
php --version
Is that version PHP 8 ? Am I right? That's the cause of the problem:
PHP 8 introduces several improvements in PHP type systems such as the introduction of Union Types, mixed type, and a few more.
With these changes, certain methods in Reflection API's ReflectionParameter yield incorrect results.
In PHP 8, the following methods from ReflectionParameter class is deprecated:
ReflectionParameter::getClass()
ReflectionParameter::isArray()
ReflectionParameter::isCallable()
ReflectionParamter::getType()
Downgrade your php version to 7.4 and your Laravel app works like a charm!
I had similar issue. But I had already run brew update and brew cleanup before I noticed the issue. What I did:
I noticed this error from brew cleanup:
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/node
Target /usr/local/bin/node
already exists. You may want to remove it:
rm '/usr/local/bin/node'
To force the link and overwrite all conflicting files:
brew link --overwrite heroku-node
I ran the commands:
brew link --overwrite composer
composer upgrade
composer update
That's what worked for me
If you're using valet you should do the followings:
Downgrade from php8+ to php7.4 valet isolate php#7.4
Then run composer update using valet valet composer update

Call to undefined function simplexml_load_string()

Call to undefined function simplexml_load_string()
I am getting this error on all the sites located on our server. Everything was working correctly until today and all of sudden this error poped up.
I have checked Simplexml and it is already installed on the server. Here is the error:
Fatal error: Call to undefined function simplexml_load_string() in
.../lib/Varien/Simplexml/Config.php on line 510
Had the same problem today. I tried to check whether extension is loaded and I was getting true (from command line) Then I found that I was using multiple php versions and the site in question was using php5.4 which for some reason was failing for simplexml
Since I am in a cPanel/WHM environment I ran
yum install ea-php54-php-simplexml
which fixed the issue. This is for EasyApache4. Perhaps you can just update simplexml sepending on your flavour of linux.
Installing latest extension resolved the issue.
yum install ea-php56-php-simplexml

Magento2 backend fatal error after backup recovery

After a backup recovery on my magento2 website I get this error:
Backend fatal error: PHP Fatal error: Uncaught Error: Class
'DOMDocument' not found in
/home/arredeom/public_html/vendor/magento/framework/Config/Dom.php:364\nStack
trace:\n#0
/home/arredeom/public_html/vendor/magento/framework/Config/Dom.php(109):
Magento\Framework\Config\Dom->_initDom('__construct('_createConfigMerger('Magento\\Framewo...',
'_readFiles(Object(Magento\Framework\Config\FileIterator))\n#4
/home/arredeom/public_html/vendor/magento/framework/App/ObjectManagerFactory.php(269):
Magento\Framework\Config in
/home/arredeom/public_html/vendor/magento/framework/Config/Dom.php on
line 364\n
I've checked on cpanel config and on PHP Selector | extensions it says: Current PHP version: 7.0 and Dom is enabled (flag is on)
is there any way to fix it? thanks
PHP told you
Class 'DOMDocument' not found ...
The DomDocument class is a fundamental part of PHP's XML handling. If the DomDocument class is not present, that means whomever updated your backend server didn't include this fundamental part of PHP. This is common in some Linux package management features that slice up core PHP functionality so users can install only what they need.
The way to fix this is to install PHP's XML/DOM functionality. The way you do that will depend on which linux distribution you're using.
You need php-xml :
sudo apt-get install php-xml

What's the best way to install a PECL extension (libsodium) for unit testing with Travis CI?

I'm trying to add continuous integration to a project called Halite, which uses libsodium to encrypt cookies before storing them on the end-user's device.
However, I can't seem to get my travis.yml right. These were the issues I encountered:
Adding extension=libsodium.so did not lead to the extension being loaded (thus, class Sodium not found fatal errors).
Changing it to extension=/path/to/libsodium.so caused a fatal error where the PHPAPI versions mismatched.
I can run the tests locally, but I'd like to use Travis CI to help diagnose issues in pull requests.
Run pecl install without sudo. PECL should automatically enable the extension so you shouldn't need a config file and extension= line to enable it.

PHP 5.3.20: undefined function hash()

I'm trying to install Magento on FreeBSD with PHP 5.3.20, but the install script fails with
Fatal error: Call to undefined function hash() in /var/www/.../magento/lib/Zend/Cache/Backend/File.php on line 894
As it's cleared in another StackOverflow question it requires PHP 5.1.2, so that's a different problem. I installed the php5-mhash extension from ports and added mhash.so and hash.so to the extensions.ini. Also, there is no --disable-hash in the configure command. And it's the same in CLI too.
Probably because open_basedir? Any ideas?
Try installing it from security and see if this will work for you.
cd /usr/ports/security/php5-hash
make install clean

Categories