installing PHPUnit

installing PHPUnit

Created:18 Feb 2017 15:10:51 , in  Host development,  Web development

Install PHPUnit with a BASH script.

PHPUnit installing and executing script

The script below, called install_phpunit.sh, can be run with no arguments, in such circumstances it installs current stable release of PHPUnit. It checks for root privileges before it begins installation process. In the case install_phpunit.sh is invoked with an argument, which is PHPunit version, it makes a check for existence of PHPUnit in that version on Sebastian's Bergman website before it embarks on downloading and installing the software. The version bit is important here because not every PHPUnit version is compatible with every PHP version. For example, PHPUnit version 6.0 is not compatible with PHP in a version below 7.0. So make sure you know your PHP version before you begin. For PHP 5.6 you would want PHPUnit in version 5.7

.

#!/usr/bin/env bash

# This script installs PHPunit PHP testing framework by Sebastian Bergmann
# author : Sylwester Wojnowski
# www : wojnowski.net.pl

# Usage: install_phpunit.sh [phpunit_version]
# When invoked with no parameter, installs the latest version (latest stable release) of PHPUnit
# If passed a version of PHPunit will try to install it. 
# Versions of PHPUnit can be found at https://phpunit.de/

check_privileges(){
  [[ $(id -u) -ne 0 ]] && {
    echo "This script requires root privileges! Exiting ..."
    exit 1
  } 
}  

begin(){
  echo "installing phpunit ..."
}

download_and_install(){
  local puv=$1
  puv=${puv:+"-${1}"}
  
  # download from https://phpunit.de/
  wget -qO /dev/null -o /dev/null "https://phar.phpunit.de/phpunit${puv}.phar" 
  
  [[ $? -ne 0 ]] && {
    echo "Error!" 
    echo "Incorrect version of PHPunit given. Check https://phpunit.de/ for PHPunit versions."
    echo "Exiting ..."
    exit 1
  }
  
  wget "https://phar.phpunit.de/phpunit${puv}.phar"
  chmod +x "phpunit${puv}.phar"
  mv "phpunit${puv}.phar" /usr/local/bin/phpunit
  return
}

end(){
  [[ $? -eq 0 ]] && {
    echo "PHPunit installation process complete!"
  } || {
    echo "PHPunit installation process failed!"
  }
}

check_privileges
begin
download_and_install $1
end

Now, what you need to do to make install_phpunit.sh work for you are the usual steps you carry out before executing a script on the command line. That is, you save the code above in a file called install_phpunit.sh. Then you make install_phpunit.sh executable by changing its mode with chmod command. Finally, you execute the script as a privilaged user. It will install PHPUnit in /usr/local/bin with executable being PHPUnit.

 
chmod +x ./install_phpunit.sh
./install_phpunit.sh 

The code above installs the latest stable version of PHPUnit. If, for example you need version 5.7, to supports PHP in version 5.6 or 7.x, then you would execute code below:


chmod +x ./install_phpunit.sh
./install_phpunit.sh 5.7

To confirm that the installation process worked, execute:


phpunit --version

This post was updated on 06 Oct 2021 21:15:36

Tags:  BASH ,  php ,  PHPUnit 


Author, Copyright and citation

Author

Sylwester Wojnowski

Author of the this article - Sylwester Wojnowski - is a sWWW web developer. He has been writing computer code for the websites and web applications since 1998.

Copyrights

©Copyright, 2024 Sylwester Wojnowski. This article may not be reproduced or published as a whole or in parts without permission from the author. If you share it, please give author credit and do not remove embedded links.

Computer code, if present in the article, is excluded from the above and licensed under GPLv3.

Citation

Cite this article as:

Wojnowski, Sylwester. "installing PHPUnit." From sWWW - Code For The Web . https://swww.com.pl//main/index/installing-phpunit

Add Comment

Allowed BB Code - style tags: [b][/b], [i][/i], [code=text][/code],[code=javascript][/code],[code=php][/code],[code=bash][/code],[code=css][/code],[code=html][/code]


I constent to processing my data given through this form for purposes of a reply by the administrator of this website.

Recent Comments

Nobody has commented on this post yet. Be first!