Composer


Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
https://getcomposer.org/doc

Table of contents

  1. Installation
  2. Usage
    1. Init project
    2. Install dependency

🔲 → Optional
✅ → Required
🔘 → Pick One
ℹī¸ → Information


Installation


✅ Installation

brew install composer

ℹī¸ Location

usr/local/Cellar/composer/{VERSION}

Usage


Init project

composer init
This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>): ngoanh2n/example
Description []: Demo Automation Test in PHP
Author [ngoanh2n <ngoanh2n@gmail.com>, n to skip]: 
Minimum Stability []: 
Minimum Stability []: 
Package Type (e.g. library, project, metapackage, composer-plugin) []: 
License []: 

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? no
Would you like to define your dev dependencies (require-dev) interactively [yes]? no
Add PSR-4 autoload mapping? Maps namespace "Ngoanh2n\Example" to the entered relative path. [src/, n to skip]: 
Do you confirm generation [yes]? yes
Composer could not detect the root package (ngoanh2n/example) version, defaulting to '1.0.0'. See https://getcomposer.org/>> root-version
Generating autoload files
Generated autoload files
PSR-4 autoloading configured. Use "namespace Ngoanh2n\Example;" in src/
Include the Composer autoloader with: require 'vendor/autoload.php';

Install dependency

Visit https://packagist.org to search desired packages.

composer require --dev phpunit/phpunit
composer require php-webdriver/webdriver