Why cant I run bin/behat? - php

I am trying to run behat on my vendor folder. I have installed composer globally, have installed the behat package, but every time I run bin/behat I keep getting this message from composer
You must set up the project dependencies, run the following commands:
curl -s http://getcomposer.org/installer | php
php composer.phar install
I am not sure how to fix this. I see the files are in the vendor folder, and when I type "composer" on the terminal, I see the manual.
If anyone can help me resolve this I would really appreciate it. Thanks!

There are several possible problems leading to this situation:
Make sure that composer is installed in your $PATH. That is, running composer at a command prompt should work, and you shouldn't need to run an explicit path like ~/Downloads/composer.phar
Execute the composer install instruction as the error message suggests. A common error is the message
Mcrypt PHP extension required
in which case you need to install the specified extension. For example, brew install php56-mcrypt on a Mac or sudo apt-get install php5-mcrypt on Ubuntu.

Related

How do I fix the following phpcs error in Visual Studio Code?

I am new to VS code. I am trying to work with PHP, but I keep getting this notification.
phpcs: Request workspace/configuration failed with message:unable to
locate phpcs. please add phpcs to your global path or use composer
dependency manager to install it in your project locally.
Intellisense doesn't work for PHP too.
I am using a Windows system. I tried to download and install Composer, but I am still getting the problem as shown in the screenshot.
]1
I have some extensions installed which are visible in the screenshot, but the issue persists.
The easiest way is to use composer to install phpcs globally and symlink the binary into your path;
Assuming you have composer installed and are using osx or linux (if not, follow instructions from here: composer) then install phpcs globally: open your terminal and type:
composer global require "squizlabs/php_codesniffer=*"
You will then need to make sure phpcs is in your path. The easiest way is to symlink into /usr/local/bin. open your terminal and type:
sudo ln -s ~/.composer/vendor/bin/phpcs /usr/local/bin/phpcs

Running composer in a different directory than current

I don't know if this question has been asked, because searching finds results mostly about moving the libraries installation directory.
I have a globally installed composer command. Is there a way to run, for example, composer install in a different directory than current, i.e. to specify the directory in which I would like tu run the command?
E.g. being in /home/someuser, I would like to acquire the same result as in running composer install it inside /home/someuser/myproject. Of course, one way would be to simply change the current directory, run composer and go back.
Try composer install -h. There you'll find an option --working-dir (or -d). And that's what you're looking for.
Then run:
composer install --working-dir=/home/someuser/myproject
You can find more in composer docs.
Depending on your operating system, the = might need to be removed:
composer install --working-dir /home/someuser/myproject
In addition to the above answer from Tomáš Votruba i had to append the = charachter on OSX. So the full command would be:
composer install -d=/home/someuser/myproject
My first post on SO so was unable to simply add this as a comment.
This works for me, PHP 7.3 on ubuntu 18.04
Install
composer install --working-dir=/your_composer_dir
Update
composer update --working-dir=/your_composer_dir
I tried what others said, but it was giving me: Invalid working directory specified 'PATH' does not exist. Although it was my working dir that contained composer.json!
I don't know why anyway, but this worked for me (only for gnu/linux users):
composer --working-dir=$(pwd)
And by the way, if you had run composer -h, it would've told you the solution:
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
I am using a Windows machine with PHPStorm (terminal) and this worked for me.
composer install --working-dir /home/someuser/myproject
My Linux OS machines require me to use
composer install --working-dir=/home/someuser/myproject
Note: You may be able to substitute ~/ for /home/someuser/ if your path is super long.
Run:
cd /home/mysites/google.com
Then run:
composer require facebook/graph-sdk
Above steps will open up the directory named (google.com) and install facebook Graph SDK there.

Composer could not find a composer.json

I tried to install composer via brew per:
In usr/local/bin (which was not on Mavricks and I had to make personally) I did.
brew tap josegonzalez/homebrew-php
brew install josegonzalez/php/composer
I can run php composer.phar, but when I do php composer.phar install, I get the error:
Composer could not find a composer.json file in /usr/local/bin
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section
So I go to the https://getcomposer.org/doc/00-intro.md. CTRL+F ".json" and nothing's there. Seriously composer?
EDIT:
What I was trying to do was to have composer executable vs php composer.phar. This works at this point from this now.
To install composer and add to your global path:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
run these in terminal. It does say if you get an error that usr doesn't exist, you do need to manually make it. I know an answer was selected, so this is for anyone who may see this in the future, as i am sometimes, and don't want to be advised to visit yet another site. Its simple just two lines, might have to be in sudo if you have permission error
You are in wrong directory. cd to your project directory then run composer update.
In my case, I did not copy all project files to the folder where I was running composer install. So do:
Copy your project files (including the composer.json) to folder
open CMD (I am using ConEmu), navigate to the new folder, run composer install from there
It should work or throw errors in case the json file is not correct.
If you just want to make composer run, create a new composer.json file with for example:
{
"require": {
"php": ">=5.3.2"
}
}
Then run composer install.
The "Getting Started" page is the introduction to the documentation. Most documentation will start off with installation instructions, just like Composer's do.
The page that contains information on the composer.json file is located here - under "Basic Usage", the second page.
I'd recommend reading over the documentation in full, so that you gain a better understanding of how to use Composer. I'd also recommend removing what you have and following the installation instructions provided in the documentation.
I encountered the same error, and was able to solve it as follows:
composer diagnose to see if something is wrong with the version of composer installed
composer self-update to install the latest version
composer update to update your composer.json file.
Simple solution is install via this command :
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
To install package it's very simple :
composer global require "phpunit/php-invoker=1.1.*"
Ref : composer web site.
In my case, I am using homestead. cd ~/Homesteadand run composer install.
You could try updating the composer:
sudo composer self-update
If that doest works remove composer files & then use:
SSH into terminal & type :
$ cd ~
$ sudo curl -sS https://getcomposer.org/installer | sudo php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo ln -s /usr/local/bin/composer /usr/bin/composer
If you face an error that says: PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1
To install package use:
composer global require "package-name"
In my case I'm in wrong directory,
My directory Path
eCommerce-shop/eCommerce
I am in inside eCommerce-shop and executing this command composer intsall so that't it throwing this error.
If you forget to run:
php artisan key:generate
You would be face this error : Composer could not find a composer.json
2 things to notice; (i did mistake and corrected with step2)
might be wrong path of compose.json in docker file. ex; if your compose.json file is not in root of repo.
OR
if using any tools to build image, specify relevant path in context.
Create a file called composer.json
Make sure the Composer can write in the directory you are looking for.
Update your composer.
This worked for me

Composer install cant find composer.json

I am trying to just install composer, I am on mac osx. I have done it before using the terminal lines from their site and it worked just fine. I got a clean install on my mac now, and it won't install properly.
I tried to:
cd ~
curl -sS https://getcomposer.org/installer | php
and and:
cd /Applciations/MAMP/htdocs
curl -sS https://getcomposer.org/installer | php
and neither works. (I saw a post saying I should cd to a directory before trying to install it. But no matter what, I keep hitting this error:
Composer could not find a composer.json file in /Applications/MAMP/htdocs
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section
when trying to install composer.
I think your question arises from a slight misunderstanding. Composer installs itself when you run the script provided on their Web site. No additional work to install Composer is necessary.
$ php composer.phar install is used to install packages with Composer, which are almost always listed in a JSON file named composer.json. Without this file, Composer doesn't know which packages to install and fails.
See "Declaring Dependencies" in Composer's Getting Started guide for how to generate a composer.json for your project.
In my case, I had a deprecated error being output from PHP. Apparently that causes composer to fail detecting the composer.json file.

Note: PHPUnit is required in order to generate controller test stubs

Here is my command on the terminal and I got a notice message
Note: PHPUnit is required in order to generate controller test stubs.
volition#volition-H61M-DS2:/var/www/register$ zf create action root Authentication
Note: PHPUnit is required in order to generate controller test stubs.
Creating an action named root inside controller at /var/www/register/application/controllers/AuthenticationController.php
Updating project profile '/var/www/register/.zfproject.xml'
Creating a view script for the root action method at /var/www/register/application/views/scripts/authentication/root.phtml
Updating project profile '/var/www/register/.zfproject.xml'
This is my include_path:
include_path .:/usr/share/php:/usr/share/pear
I don't know what I'm doing wrong here.
and also I want to know what is the use of phpUnit ??
It just is what it says. If you want to create test stubs, you need to have PHPUnit installed. Zend can automatically create tests for you when you generate code. It's not an error or a notice (as in E_NOTICE), it's simply a Note.
PHPUnit is a unit testing framework that helps you to test your code. If you don't know what that means, by all means go read the PHPUnit documentation.
First, install PEAR.
sudo apt-get install php-pear
Next, tell PEAR to update its own channel.
sudo pear channel-update pear.php.net
Then, tell PEAR to upgrade itself to the newest version.
sudo pear upgrade-all
You should now have the newest version of PEAR installed.
To install PHPUnit, let PEAR know where to find PHPUnit.
sudo pear channel-discover pear.phpunit.de
Then install PHPUnit. (the -a makes sure all dependency packages are also installed)
sudo pear install -a phpunit/PHPUnit
Update:
At Last Restart Apache
sudo /etc/init.d/apache2 restart
ohh You are using zend Framework
phpunit is installed in
C:\Zend\ZendServer\bin\PEAR
Add this line
include_path=".:/usr/share/php:/usr/share/pear:/usr/share/php/PHPunit:/usr/share/php/PEAR"

Categories