2017 © Pedro Pelรกez
 

library php-package

A starting point for basic PHP packages. Allows configuration of PHPUnit and TravisCI

image

stillat/php-package

A starting point for basic PHP packages. Allows configuration of PHPUnit and TravisCI

  • Sunday, November 29, 2015
  • by stillat
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

PHP Package

PHP Package is a template for the NewUp package generator. The NewUp generator is a general-purpose tool for creating things from templates; PHP Package is a template that provides you with a starting point for your PHP projects., (*1)

, (*2)

Installation

First, make sure you have NewUp installed and configured. Afterwards, you can run this command:, (*3)

newup template:install stillat/php-package, (*4)

NewUp will then install and configure everything it needs to internally for the php-package template., (*5)

, (*6)

General Usage

After you have installed the php-package template, we are ready to create a new PHP Package:, (*7)

newup a stillat/php-package vendor/package <output_directory>, (*8)

In the above example, replace vendor/package with the vendor and package name of your new package (for example stillat/php-package) and replace <output_directory> with the directory you want the package to be created in., (*9)

Used with no options, PHP Package will create a directory/file structure similar to the following:, (*10)

src/
.gitignore
composer.json

The src/ directory is where you will create your new package/library. It is empty so you have a fresh starting point. This directory will be autoloaded by Composer using the psr-0 autoloader., (*11)

The .gitignore file contains quite a few options set for you by default, with instructions on how to remove configured options and where to find more., (*12)

The composer.json file is your standard composer.json file. If you configured NewUp with your name and email address, the authors field will already be filled in for you., (*13)

, (*14)

Specifying a PHP version

You can specify a PHP version that your package requires by providing an extra parameter when generating your package:, (*15)

newup a stillat/php-package vendor/package <output_directory> <php_version>, (*16)

By default, the PHP version is set to >=5.5.9., (*17)

For example, we could easily state that our package needs at least PHP 5.6 when creating our package (pay special attention to the quotes!):, (*18)

newup a stillat/php-package vendor/package <output_directory> ">=5.6", (*19)

, (*20)

PSR-0 / PSR-4

You can choose which autoloader to use by supplying a value for the --psr option. The following table lists the valid values you can use:, (*21)

Autoloader Value Example
PSR-0 psr0 newup a stillat/php-package <output_dir> vendor/package --psr=psr0
PSR-4 psr4 newup a stillat/php-package <output_dir> vendor/package --psr=psr4

The PSR-4 autoloader is selected by default., (*22)

When choosing to use the PSR-0 autoloader, directory scaffolding will automatically be created for you. For example, if the package name was stillat/test, the following directory structure would be created when using the PSR-0 autoloader:, (*23)

<output_directory>/
โ”‚โ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ Stillat/
โ”‚   โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€ Test/
โ”œโ”€โ”€ composer.json
โ”œโ”€โ”€ .gitignore

This is different that when using the PSR-4 autoloader, as the src/ directory would just be empty., (*24)

, (*25)

PHPUnit Integration

To enable PHPUnit support on your generated package, just add the "--phpunit" switch to the end of the command:, (*26)

newup a stillat/php-package vendor/package <output_directory> --phpunit, (*27)

The following additional directories/files will be created for you:, (*28)

tests/
tests/ExampleTest.php
phpunit.xml

The tests/ directory will be where your tests will live. An example test (tests/ExampleTest.php is already included in this directory (this can be safely deleted)., (*29)

The phpunit.xml file contains the configuration for PHPUnit. It is already configured with sensible defaults and features a customized test suite name., (*30)

In addition to creating new directories and files for you, opting in to PHPUnit integration will also update your generated composer.json file to include mockery/mockery and phpunit/phpunit automatically., (*31)

, (*32)

TravisCI Integration

If you would like to rapidly configure TravisCI for your project, just add the --travis switch to the end of the command:, (*33)

newup a stillat/php-package vendor/package <output_directory> --travis, (*34)

You will see interactive prompts that will guide you through the configuration process. An example session might look something like this:, (*35)

Would you like to add a PHP version to test? [Y/n] Y
Which PHP version would you like to test? 5.5.9
Do you want to allow failures for PHP version 5.5.9? [y/N] N

Would you like to add a PHP version to test? [Y/n] Y
Which PHP version would you like to test? 5.6
Do you want to allow failures for PHP version 5.6? [y/N] N

Would you like to add a PHP version to test? [Y/n] Y
Which PHP version would you like to test? 7.0
Do you want to allow failures for PHP version 7.0? [y/N] Y

Would you like to add a PHP version to test? [Y/n] Y
Which PHP version would you like to test? hhvm
Do you want to allow failures for PHP version hhvm? [y/N] N

Would you like to add a PHP version to test? [Y/n] N

This would generate a .travis.yml file similar to the following:, (*36)

language: php

php:
  - 5.5.9
  - 5.6
  - 7.0
  - hhvm

matrix:
    allow_failures:
        - php: 7.0

sudo: false

install: travis_retry composer install --no-interaction --prefer-source

TravisCI and PHPUnit

If you specify both the --travis and the --phpunit flags, the following script will be added to the end of your .travis.yml file automatically for you:, (*37)

script: vendor/bin/phpunit, (*38)

, (*39)

License

Licensed under the MIT License. Enjoy!, (*40)

The Versions

29/11 2015

dev-master

9999999-dev

A starting point for basic PHP packages. Allows configuration of PHPUnit and TravisCI

  Sources   Download

MIT

by Johnathon Koster

29/11 2015

1.1.1

1.1.1.0

A starting point for basic PHP packages. Allows configuration of PHPUnit and TravisCI

  Sources   Download

MIT

by Johnathon Koster

29/11 2015

1.1.0

1.1.0.0

A starting point for basic PHP packages. Allows configuration of PHPUnit and TravisCI

  Sources   Download

MIT

by Johnathon Koster

28/11 2015

1.0.0

1.0.0.0

A starting point for basic PHP packages. Allows configuration of PHPUnit and TravisCI

  Sources   Download

MIT

by Johnathon Koster