Behat fails runing after updating dependencies - php

Just updated composer on a functioning Behat, and now getting the following messages open running behat.
PHP Deprecated: "Symfony\Component\Console\Helper\DialogHelper" is deprecated since version 2.5 and will be removed in 3.0.
Im using Behat-3 (~3.0#dev).
Any advice will be appreciated :)

I don't know what your composer.json looks like but I would suggest you to use stable versions for packages in require blocks. Try to use specific versions when possible.
"require": {
"hello/world": "1.2.3",
"abc/cde": "~4.3.0",
"php": ">=5.4.0"
},
"require-dev": {
"similar/to-above": "1.11"
},
"require-test": {
"similar/to-above": "3.2.6"
},

Related

Composer not working after specifying platform php version

I am working on a project for a WebApp and I would like to specify types for my class properties. I didn't realise this is a PHP version 7.4.* feature, so I read this and updated my composer.json to include the relevant material:
{
"name": "srmes/shopping-app-test",
"description": "an assignment from `scandiweb.com`. A simple php-based web application to display and inventory a range of products",
"require-dev": {
"phpunit/phpunit":"~9.0",
"squizlabs/php_codesniffer": "~3.0"
},
"require": {
"doctrine/orm": "~2.7",
"php": "7.4.4"
},
"config": {
"platform": {
"php": "7.4.4"
}
},
"autoload" : {
"psr-4": {
"WebApp\\": "src/"
}
},
"autoload-dev" : {
"psr-4": {
"WebApp\\Tests\\" : "tests/"
}
}
}
I then ran composer install and composer update.
No problems seemed to occur with the install, except that now my phpunit tests don't run:
PHPUnit 9.1.1 by Sebastian Bergmann and contributors.
Time: 58 ms, Memory: 4.00 MB
No tests executed!
And all composer commands give the following error:
Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /Users/ScottAnderson/Documents/Tech/commissions/shopping_app_test/vendor/ocramius/package-versions/src/PackageVersions/Installer.php on line 33
Ironically this is syntax exception about the php feature I was trying to utilise! I can't even run composer -vvv to debug which php executable is being used by composer.
In order to resolve this should I use a package like phpbrew to make directory environments of php?
My assumption was that after requiring php 7.4.4 in composer.json that the correct php executable would be installed and used by composer and phpunit
Looks like you are not running php 7.4. and the dependencies installed (here phpunit and PackageVersion) need it.
Sometimes composer runs commands hooked on events and if the command fails everything else can fall.
Delete the vendor folder.
Delete composer.lock
Remove the constraint on php 7.4 version in your composer.json
Run composer update
You should be alright 🤗
Btw composer manages project dependencies, not php versions installed.
If you're starting out in PHP I'd recommend to stick with 7.3 which is widely available. Honestly you don't need the latest syntax additions to the language.

Twig loader crushes with October CMS

When I start fresh october project it says:
Class System\Twig\Loader contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Twig_LoaderInterface::getSourceContext) /home/doctor/web/paintshop/modules/system/twig/Loader.php line 82
Did anyone faced such problem? My php version is 7, and php7 mod is enabled in apache, while php 5.6 mod is disabled. Thank you!
Most of cases if you have a fresh OctoberCMS install it won't be the latest update.
Go to Config/Cms.php and set edgeUpdates to true and try to update the application from backend.
If you still have problems, you can try to switch to pulling from the dev branch instead by setting the require property of your composer.json to the dev branch for the library and then running composer update
"require": {
"php": ">=5.5.9",
"october/rain": "dev-develop",
"october/system": "dev-develop",
"october/backend": "dev-develop",
"october/cms": "dev-develop",
"laravel/framework": "5.1.*",
"wikimedia/composer-merge-plugin": "dev-master",
"guzzlehttp/guzzle": "^6.2"
},
The reason for the problem is that the Twig dependency in the OctoberCMS Library composer.json was recently updated to include v2.0 which the library doesn't officially support yet as Twig v2 doesn't support below PHP 7 while October does still. The reversion back to just Twig v1.30 was just made a couple of hours ago, hence why you might need to update from the dev branch of the library to pull your changes.

How to require package that are compatiable with PHP version?

In composer.json I have dependencies on many PHP packages. I want for dependencies to resolve to packages, that are compatible with PHP 5.5, but still can be ran at PHP 7.
How do I do that?
In general, PHP is backward compatible, so you should be able to run your library on any newer version, so it should be enough for you to specify the lowest required version.
To specify the particular PHP version, use the platform configuration directive:
{
"name": "some/library",
"version": "1.0.0",
"config":
"platform": {
"php": "5.5"
}
}
}

Namespacing issue? or something else?

I am trying to implement the Graphaware\neo4j client in php
neo4j-php-client
I ran composer to download the files to the working directory .www
and tried initiating the client using
require_once(BASEPATH.'vendor/autoload.php');
use GraphAware\Neo4j\Client\ClientBuilder;
$client = ClientBuilder::create()->addConnection('default', 'http://neo4j:myPassword#localhost:7474')->build();
I get this error.
<b>Fatal error</b>: Class 'GraphAware\Neo4j\Client\ClientBuilder' not found in <b>*path_to_my_www_dir\index.php*</b> on line <b>36</b><br />
Why am i seeing this?
I'm the maintainer of GraphAware Neo4j Client.
My bet is that you have been disturbed when reading the README of the repository.
The current master branch contains the code for 4.0#alpha, so if you ran in the command line composer require graphaware/neo4j-php-client chances are high that composer installed the last stable version in the 3.X series and thus the required class doesn't exist there.
I would suggest you try to install the alpha7 version of the client by running :
composer require graphaware/neo4j-php-client:^4.0#alpha
Let me know if you have other issues
We ran into the issue with neo4j-php-client not supporting PHP 5.5 as well. While the "correct" solution is to upgrade to a newer version of PHP, it isn't exactly the most convenient--especially if you just want to start evaluating this library. The only reason that PHP >= 5.6 is required is for Neo4j's bolt protocol, so as long as you stick to using the http protocol instead everything will work fine. In order to get composer to play nice though, you have to make a few changes to neo4j-php-client's composer.json:
Change "php": ">= 5.6" to "php": ">= 5.5"
Replace "graphaware/neo4j-bolt": "^1.5" with "graphaware/neo4j-common": "^3.0"
We ended up forking the library on Github and then updated our composer.json to use our modified version of neo4j-php-client. The relevant parts are:
{
...
"require": {
...
"graphaware/neo4j-php-client": "dev-OptionalBoltSupport"
},
...
"repositories": [
...
{
"type": "vcs",
"url": "https://github.com/wnielson/neo4j-php-client"
}
]
}
After doing this you can run composer update and neo4j-php-client should install fine.
You simply need to require vendor/autoload.php as said in documentation.
So require_once 'vendor/autoload.php'; will solve your problem.
The problem is that, even if you are using use ..., your php file didn't know anything about the php class file you're trying to create.
You need to include that file using include or require function.

Composer dependency constraint

Is there a possibility to let composer install a package only when the PHP version is below a given version.
https://github.com/ircmaxell/password_compat
"ircmaxell/password-compat": "dev-master"
I have found this package to be useful because I have a webserver which runs on PHP 5.4 and I need the password_* functions which are only available >= PHP 5.5.
Yes, there is. You can find the details on the packagist website, but basically, the package/dependency should be defined with this requirement:
{
"name": "ircmaxell/password-compat",
"description": "A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash",
"require": {
"php": "<5.5.*",
"phpunit/phpunit": "4.*"
}
}
As you can see, I've added "php": "<5.5.*" to the requirements for the package. You can add this requirement to your own composer.json file, by adding the dependency to your repositories array in the composer.json file, and add the requirements there:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ircmaxell/password_compat",
"require": {
"php": "<5.5.*",
}
}]
}
Something like that, I only have php5.5 installed, so I was unable to test this, though... but read through the documentation, I'm pretty sure it's possible.

Categories