How to set up phpUnit alias for laravel project? - phpunit

I installed phpunit using composer to project.
composer require --dev phpunit/phpunit ^7
It is installed correctly. But how to set up aliases to use
~$ phpunit
to run all tests.
I found that ~$ vendor/bin/phpunit works. Where and how to set up alias for that in Ubuntu 18.04?

You could just set up an alias in your ~/bash_profile
alias phpunit='vendor/bin/phpunit'
Now you can enter
~$ phpunit
in your project and the local phpunit from vendor/bin/phpunit will be executed.

An alias you talk about is for global use, the phpunit inside the vendor folder is for that project only.
Install PHPunit globally
Install PHPunit globally if you want to use $ phpunit everywhere (more info).
$ wget https://phar.phpunit.de/phpunit-6.5.phar
$ chmod +x phpunit-6.5.phar
$ sudo mv phpunit-6.5.phar /usr/local/bin/phpunit
$ phpunit --version

Related

Compiling: conflicting types for 'sigset_t'

I'm trying to compile the wazuh manager. I've done the following:
$ sudo apt-get install gcc make git libc6-dev
$ mkdir ossec_tmp && cd ossec_tmp
$ git clone -b stable https://github.com/wazuh/wazuh.git ossec-wazuh
$ cd ossec-wazuh
$ sudo ./install.sh
This gives me an error as such:
In file included from /usr/include/asm/signal.h:26:0,
from /usr/include/linux/signal.h:5,
from /usr/include/linux/aio_abi.h:32,
from engines/afalg/e_afalg.c:43:
/usr/include/asm-generic/signal.h:92:3: error: conflicting types for 'sigset_t'
} sigset_t;
I then went and tried compiling without shared library only the agent by running:
sudo make -C src DISABLE_SHARED=1 TARGET=agent
This seem to give the exact same error. Anyone able to assist me here to debug?
I can recommend you to follow the manager installation guide of our documentation.
As I can see you want to install the server in a folder called 'ossec_tmp', I recommend you to create the folder and after that following the guide, when you launch
./install
It will ask you for the path where you want to install the service.
Here is a link to the documentation:
https://documentation.wazuh.com/current/installation-guide/installing-wazuh-server/sources_installation.html
Hope it helps.

I want to use Python Fabric with my custom Operator, how should I install fabric on workers?

At this point I'm thinking about calling bash command pip install fabric2 each time my operator executed, but this does not looke like a good idea.
Create a requirements.txt file similar and pass that as a variable while creating the cloud composer enviroment.
Sample requirements.txt file:
scipy>=0.13.3
scikit-learn
nltk[machine_learning]
Pass the requirements.txt file to the environments.set-python-dependencies command to set your installation dependencies.
gcloud beta composer environments update ENVIRONMENT_NAME \
--update-pypi-packages-from-file requirements.txt \
--location LOCATION
Turns out you can use: PythonVirtualenvOperator it supports pip deps.
Another option that is available for the Composer users is to install deps via the composer itself: https://cloud.google.com/composer/docs/how-to/using/installing-python-dependencies

Use local phpunit if installed otherwise fall back to global

I have PHPUnit version 5.3.2 installed via composer globally, and version 5.7.19 installed locally in my project. I can run global PHPUnit just by typing phpunit and local by vendor/bin/phpunit.
Is there a way to configure PHPUnit to by default run local installation if it exists, or otherwise fall back to global installation so I don't have to use vendor/bin/phpunit each time?
The only solution I came up so far is creating a bash script phpunit in project directory:
#!/bin/bash
vendor/bin/phpunit $#
But then I have to type ./phpunit anyway.
Looks like I wasn't that far. So I added following to my .bashrc
original_phpunit=$(which phpunit)
phpunit() {
if [ -f vendor/bin/phpunit ]; then vendor/bin/phpunit $#
else eval "'$original_phpunit' $#"
fi
}
And now it works as I wanted. Hope someone will find it useful!

Symfony2 Assetic: Path to node executable could not be resolved

When running app/console assetic:dump, I am getting:
Path to node executable could not be resolved
What does it mean and how to fix this?
When trying to browse project via app_dev.php, I am getting an HTTP 500 errors when browser tries to download css and js files.
First make sure you have node installed and find the path to node. You can usually find this by using which node which will return something like /usr/local/bin/node. If it returns something like /usr/bin/which: no node in ... you need to install node.
Next configure symfony. Open your config.yml (./app/config/config.yml) and the path to node to you assetic config, i.e.:
# app/config/config.yml
assetic:
node: /usr/local/bin/node
This worked for me
sudo apt-get remove nodejs
sudo apt-get remove npm
sudo curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install nodejs
I add the exact same error while doing
php app/console assetic:dump --env=prod
On Ubuntu there is a confusion between node and nodejs binary.
To solve this you need to install node binary.
In my case the binary was nodejs, so it didn't work.
On Ubuntu the command which node will tell you if node is instaled.
Try which node and if it doesn't work try which nodejs.
So to be sure there is no confusion I did :
sudo apt-get remove nodejs
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
Check on node website for the correct url in the curl command. You might want node 5.X.
Now when you do
which node
/usr/bin/node
You have the correct binary name (node instead of nodejs).
After this it should work. If not check the node path in config.yml (check that there is no other declaration in config_prod and config_dev )
I've found that even if you specify /usr/bin/node in your config.yml you might still find assetic is trying to use /usr/local/bin/node.
The quick and dirty way to fix this is:
ln -sf /usr/bin/node /usr/local/bin/node
If you are in doubt, temporarily edit vendor/kriswallsmith/assetic/src/Assetic/Filter/UglifyJs2Filter.php
Edit near line 136:
if (127 === $code) {
throw new \RuntimeException('Path to node executable could not be resolved.');
}
->
if (127 === $code) {
throw new \RuntimeException('Path to node executable could not be resolved.' . $this->nodeBin);
}
This will tell you where assetic expects node to be next time assetic fails.
I found in my set up assetic was configured to look to /usr/local/bin in dev mode but /usr/bin in prod mode.
So it's worth checking config.yml, config_dev.yml and config_prod.yml.
Are you using some filters like uglify ?
If this is the case, Assetic raises this error because the process exists with code 127, which means the node executable was unable to run.
Check the path in your config.yml :
# app/config/config.yml
assetic:
filters:
uglifyjs2:
bin: /path/to/uglifyjs
And make sure it is executable :
chmod +x /path/to/uglifyjs
Just make a composer update (php composer.phar update) then try dumping your assets.
It may not work the first time, so update composer again.

Installing PHPUnit on MAMP 2.1.3 (Mountain Lion)

I'm struggling with this issue.
Here's what I've tried :
$ cd /Applications/MAMP/bin/php/php5.4.10/bin/
$ sudo ./pear channel-update pear.php.net
$ sudo ./pear upgrade pear
$ sudo /Applications/MAMP/bin/php/php5.4.10/bin/pear channel-discover pear.phpunit.de
$ sudo /Applications/MAMP/bin/php/php5.4.10/bin/pear channel-discover pear.symfony-project.com
$ sudo /Applications/MAMP/bin/php/php5.4.10/bin/pear install phpunit/PHPUnit
So it seems to work, but phpunit is actually installed in
/Applications/MAMP/bin/php3/bin/
If I tried to launch it from there, it doesn't work (no output, no log). If I move it to the php 5.4.10 folder, it still doesn't work.
I've replaced the Mac OS php cli with MAMP's :
$ which php
/Applications/MAMP/bin/php/php5.4.10/bin/php
As suggested on some website, I've also tried to remove
/Applications/MAMP/bin/php/php5.4.10/conf/pear.conf
But nothing seems to help.
Any idea ?
I'd recommend using composer. It's becoming a standard.
To start with, go to your project's root directory first and create a composer.json file there:
{
"require-dev": {
"phpunit/phpunit": "*"
},
"autoload": {
"psr-0": {"": "src"}
},
"config": {
"bin-dir": "bin"
}
}
You can tune it to your needs later. You'll probably want to configure the autoloading if you'd like to leverage composer's autoloader (which I recomend).
Next download the composer:
curl -sS https://getcomposer.org/installer | php
The above script will not only download it but also verify your environment if it's suitable to run composer binary.
If everything goes well install your dependencies:
./composer.phar install --dev
PHPUnit binary will be installed in the bin directory (configured in composer.json):
./bin/phpunit --version
I've met this problem this morning and find this topic but no answer is helpful. After a couple of hours google search, I found this link, it helped me solve my problem
http://www.startupcto.com/server-tech/macosx/installing-phpunit-on-mamp
My MAMP php version is 5.5.3
First, you'll probably need to update PEAR:
sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear channel-update pear.php.net
sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear upgrade pear
After that, add the appropriate PEAR channels for PHPUnit:
sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear channel-discover pear.phpunit.de
sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear channel-discover pear.symfony.com
sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear channel-discover components.ez.no
Finally, install PHPUnit:
sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear install phpunit/PHPUnit
Test phpunit to make sure it was installed correctly:
/Applications/MAMP/bin/php/php5.5.3/bin/phpunit --version
Link phpunit to your path
sudo ln -s /Applications/MAMP/bin/php/php5.5.3/bin/phpunit /usr/local/bin/phpunit
Hope this help you and anyone meet this problem in the future!
You could try this solution from this site
The php bin could vary from installation.
/Applications/MAMP/bin/php5/bin/pear channel-discover pear.phpunit.de
/Applications/MAMP/bin/php5/bin/pear channel-discover pear.symfony-project.com
/Applications/MAMP/bin/php5/bin/pear channel-discover components.ez.no
/Applications/MAMP/bin/php5/bin/pear install phpunit/PHPUnit

Resources