Drupal Testing: PHP: 01: cmder & composer setup ( for composer.json )

phpunit7

cmder

  • CMDER is a linux/windows console hybrid that simplifies environment setup
  • also makes environment portable by encapsulating the shell & environment variables

install to:

c:\cmder

cmder/bin

Curl

  • curl is a http get ( and post? ) library ( tool ) to request files/pages/text/anything from internet resources.
  • place the windows executable in cmder's 'bin' directory to be in the PATH's scope
  • can really put these anywhere, they will just require explicit PATH entries
C:\cmder\bin\curl.exe

C:\cmder\bin\libcurl-x64.dll

C:\cmder\bin\curl-ca-bundle.crt

 

CMDER config/user-profile.cmd

  •  
:: use this file to run your own startup commands
:: use  in front of the command to prevent printing the command

:: uncomment this to have the ssh agent load when cmder starts
:: call "%GIT_INSTALL_ROOT%/cmd/start-ssh-agent.cmd"

:: uncomment this next two lines to use pageant as the ssh authentication agent
:: SET SSH_AUTH_SOCK=/tmp/.ssh-pageant-auth-sock
:: call "%GIT_INSTALL_ROOT%/cmd/start-ssh-pageant.cmd"

:: you can add your plugins to the cmder path like so
:: set "PATH=%CMDER_ROOT%\vendor\whatever;%PATH%"

@echo off

 

CMDER config/user-aliases.cmd

  • these are essentially environment variables
;= @echo off
;= rem Call DOSKEY and use this file as the macrofile
;= %SystemRoot%\system32\doskey /listsize=1000 /macrofile=%0%
;= rem In batch mode, jump to the end of the file
;= goto:eof
;= Add aliases below here
e.=explorer .
gl=git log --oneline --all --graph --decorate  $*
ls=ls --show-control-chars -F --color $*
pwd=cd
clear=cls
history=cat "%CMDER_ROOT%\config\.history"
unalias=alias /d $1
vi=vim $*
cmderr=cd /d "%CMDER_ROOT%"
php=C:\xampp\php\php.exe $*  

 

 

composer

  • composer is a dependency manager for PHP
  • acts much like a java mavan POM
  • composer.json enumerates dependencies
  • composer.lock declares dependency versions & prevents composer from pulling the 'tip' version of these dependencies

 

composer.json

Monolog

{
    "require": {
        "monolog/monolog": "1.0.*"
    }
}

 

PHPUnit V7


    "autoload": {
        "classmap": [
            "src/"
        ]
    },
    "require-dev": {
        "phpunit/phpunit": "^7"
    }

 

composer.lock

{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "bef20e1ca06eac6c027a5bc95193a923",
    "packages": [
        {
            "name": "monolog/monolog",
            "version": "1.0.2",
            "source": {
                "type": "git",
                "url": "https://github.com/Seldaek/monolog.git",
                "reference": "b704c49a3051536f67f2d39f13568f74615b9922"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/Seldaek/monolog/zipball/b704c49a3051536f67f2d39f13568f74615b9922",
                "reference": "b704c49a3051536f67f2d39f13568f74615b9922",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.0"
            },
            "type": "library",
            "autoload": {
                "psr-0": {
                    "Monolog": "src/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Jordi Boggiano",
                    "email": "j.boggiano@seld.be",
                    "homepage": "http://seld.be",
                    "role": "Developer"
                }
            ],
            "description": "Logging for PHP 5.3",
            "homepage": "http://github.com/Seldaek/monolog",
            "keywords": [
                "log",
                "logging"
            ],
            "time": "2011-10-24T09:39:02+00:00"
        }
    ],
    "packages-dev": [],
    "aliases": [],
    "minimum-stability": "stable",
    "stability-flags": [],
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": [],
    "platform-dev": []
}

 

Using CMDER to GET & BUILD Composer(composer.phar)

https://getcomposer.org/doc/00-intro.md

;curl https://getcomposer.org/installer > composer-setup.php

php composer-setup.php

composer.phar will be created and used like:

php composer.phar update

php composer.phar install
  • place composer.phar in the SAME FOLDER as the project's composer.json file

 

 

CMDER Session For Get & Build Composer

Using curl To Get Composer Installer Stub

C:\cmder\tools
λ ;curl https://getcomposer.org/installer > composer-setup.php
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  257k  100  257k    0     0   359k      0 --:--:-- --:--:-- --:--:--  359k

Directory Listing After CURL

C:\cmder\tools
λ ls
composer-setup.php

Run Newly Built Composer-Setup.php

C:\cmder\tools
λ php composer-setup.php
All settings correct for using Composer
Downloading...

Composer (version 1.7.2) successfully installed to: C:\cmder\tools\composer.phar
Use it: php composer.phar

Running Composer the First Time

C:\cmder\tools
λ php composer.phar
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.7.2 2018-08-16 16:57:12

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about                Shows the short information about Composer.
  archive              Creates an archive of this composer package.
  browse               Opens the package's repository URL or homepage in your browser.
  check-platform-reqs  Check that platform requirements are satisfied.
  clear-cache          Clears composer's internal package cache.
  clearcache           Clears composer's internal package cache.
  config               Sets config options.
  create-project       Creates new project from a package into given directory.
  depends              Shows which packages cause the given package to be installed.
  diagnose             Diagnoses the system to identify common errors.
  dump-autoload        Dumps the autoloader.
  dumpautoload         Dumps the autoloader.
  exec                 Executes a vendored binary/script.
  global               Allows running commands in the global composer dir ($COMPOSER_HOME).
  help                 Displays help for a command
  home                 Opens the package's repository URL or homepage in your browser.
  i                    Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  info                 Shows information about packages.
  init                 Creates a basic composer.json file in current directory.
  install              Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses             Shows information about licenses of dependencies.
  list                 Lists commands
  outdated             Shows a list of installed packages that have updates available, including their latest version.
  prohibits            Shows which packages prevent the given package from being installed.
  remove               Removes a package from the require or require-dev.
  require              Adds required packages to your composer.json and installs them.
  run-script           Runs the scripts defined in composer.json.
  search               Searches for packages.
  self-update          Updates composer.phar to the latest version.
  selfupdate           Updates composer.phar to the latest version.
  show                 Shows information about packages.
  status               Shows a list of locally modified packages, for packages installed from source.
  suggests             Shows package suggestions.
  u                    Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  update               Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  upgrade              Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate             Validates a composer.json and composer.lock.
  why                  Shows which packages cause the given package to be installed.
  why-not              Shows which packages prevent the given package from being installed.

Checking Composer Version

C:\cmder\tools
λ php composer.phar --version
Composer version 1.7.2 2018-08-16 16:57:12

 

 


 

CMDER Session For Update & Install

Site Root Listing

C:\xampp\htdocs
λ ls
applications.html  composer.json   dashboard/   img/       phpunit-7.3.5.phar*  xampp/
bitnami.css        composer.phar*  favicon.ico  index.php  webalizer/

Running Composer Update

C:\xampp\htdocs
λ php composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing monolog/monolog (1.0.2): Downloading (100%)
Writing lock file
Generating autoload files

Vendor Folder Is Now Present

C:\xampp\htdocs
λ ls
applications.html  composer.json  composer.phar*  favicon.ico  index.php            vendor/     xampp/
bitnami.css        composer.lock  dashboard/      img/         phpunit-7.3.5.phar*  webalizer/

Running Composer Install

C:\xampp\htdocs
λ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files

 


 

 

 

 

 

Tags