I am using PHPUnit to test my project running in PHP 7.0.2, but it seems to have issues with the group use statement. For example, this is an example file using a group use statement:
test.php
<?php
namespace MyFramework;
use \OtherFramework\{
AwesomeClass,
OtherAwesomeClass
};
// do ALL the things
When I run
php test.php
it works fine as expected. Now I was using PHPUnit 4.8.21, but when I tried
phpunit test.php
I got the error
Parse error: parse error, expecting `"identifier (T_STRING)"' in test.php on line 4
Mind you, I am using other PHP 7 features such as the null coalesce operator (??) just fine in other tests, so I know that PHPUnit is running PHP 7. Next I tried upgrading to the preferred stable version (5.1.4) and got this response:
This version of PHPUnit requires PHP 5.6; using the latest version of PHP is highly recommended.
And even my old tests without a group use statement won't run.
How can I run PHPUnit with PHP 7 and get the group use statements to work?
Related
OS: macOS Big Sur
PHP version: 7.4.1
Package name and version: google/apiclient: ^2.12.3
Whenever I switch the PHP version to 7.4.1 I get this error
Parse error: syntax error, unexpected 'static' (T_STATIC) in /Users/webtechstreet4/Local Sites/fvtest/app/public/wp-content/plugins/form-vibes-pro/vendor/psr/cache/src/CacheItemInterface.php on line 75
The library works great on PHP 8 but gives the above error when switching to PHP 7.
Screenshot
Actually, I sorted it out by changing the system PHP version and running composer update.
I thought I needed to change the site PHP version but it was actually the system PHP version.
here is the GitHub issue link: https://github.com/googleapis/google-api-php-client/issues/2246
it is because, static return type is available only for PHP 8, I have same issue, just for temporary you can change
.\vendor\psr\cache\src\CacheItemInterface.php
line number 75 just remove return type static like this
public function set($value);
I am compiling a UFront application which worked prior to Haxe 3.4. After upgrading it started generating this error when using remoting:
PHP Fatal error: Class 'haxe__Unserializer_DefaultResolver' not found…site/ufront/www/lib/haxe/Unserializer.class.php on line 554
As a temporary fix I inserted this statement at the top of that file:
require '_Unserializer/DefaultResolver.class.php';
Obviously that will disappear the next time I compile. How can I ensure that PHP finds the DefaultResolver class?
I solved this by putting these lines in my Server class:
#if php
untyped __php__("require 'haxe/_Unserializer/DefaultResolver.class.php'; ");
#end
I am installed yii2 advanced template using composer all are working fine.
System have php7.1.5. Whenever i copy advanced folder in another system it throw syntax error in TestCase.php like below
Parse error: syntax error, unexpected '?' in \advanced\vendor\phpunit\phpunit\src\Framework\TestCase.php on line 822
line 822 is $configurationFilePath = $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] ?? '';
That another system have php5.6.8
So, i am directly install yii2 advanced in that system and it is working fine.
I am check TestCase.php the file have lot of differences and the particular line also changed like below
$configurationFilePath = (isset($GLOBALS['__PHPUNIT_CONFIGURATION_FILE']) ? $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] : '');
So i want to know what is going here.My question is not clear please let me know.Thanks in advance
PHP operator ?? is available since PHP7, so u can't expect, that code from PHP7 will work on server with PHP5.
PHP 7 - Null coalescing operator
I have an application that will run an Artisan command via a controller:
Artisan::call('myCommand');
The problem is that my production server doesn't have their Terminal PHP version up to speed, so they needed to put in a fix for my running of composer and artisan commands ( I now use /usr/bin/php55 ).
Now, when I try to to call the Artisan command via my controller, I am getting this error:
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in on line 54
This error is due to the PHP version being wrong, which agrees with previous issues I have had on my production server.
Does anyone know how I can change the version of PHP used by the Artisan Facade? Preferably without changing any core Laravel code :)
Thanks
When you run a command via Artisan::call() you are not creating a separate process. The command code is executed with the same process that handles the request and uses the same PHP version. There is no way to make it use another PHP version when calling it via Artisan facade.
In order to use different PHP version you need to run the command in a separate process. You can use Symfony's Process class for that - it's bundled with Laravel, so there is no need to install anything.
This should work for you:
$process = new Process('/usr/bin/php55 artisan command:name');
$process->run();
I just pulled in the latest version of Codeception using Composer and ran vendor/bin/codecept bootstrap and received the error when it tried to the Build Inital Guy Classes:
PHP InvalidArgumentException: Given expression is not a regex. In:
vendor/symfony/finder/Symfony/Component/Finder/Expression/Regex.php on line 77
It actually does seem to complete, but whenever I run vendor/bin/codecept run I also get this same error.
For reference i'm using:
Laravel Latest
Composter Latest
PHP 5.4.25
Thanks for the assistance.
As a workaround, you can disable xdebug for php5-cli.