A rake/make clone for PHP 5.3

Related tags

Testing phake
Overview

phake - Rake/Make for PHP 5.3 Build Status

© 2010 Jason Frame [ [email protected] / @jaz303 ]
Released under the MIT License.

A wee clone of Ruby's rake for PHP 5.3. Uses closures for ultimate coolness.

Questions abut phake? Come and chat in #phake on Freenode!

Usage

  • Download
  • Create a Phakefile in the current directory or a parent directory
  • Invoke ./phake task:name to invoke task or ./phake -T to list defined tasks

Defining Tasks

Define tasks like this:

task('dependency1', function() {
    echo "i will run first!\n";
});

task('dependency2', function() {
    echo "i will run second!\n";
});

task('task_name', 'dependency1', 'dependency2', function() {
    echo "i will run last!\n";
});

This task would be invoked from the command line by ./phake task_name

Task bodies are optional if you want to create some sort of "super-task" that just invokes a bunch of others:

task('foo', 'dep1', 'dep2');

And multiple bodies can be added to tasks, all of which will be executed when the task is invoked:

task('foo', function() { echo "task work item 1\n"; });
task('foo', function() { echo "task work item 2\n"; });

Grouping Tasks

Like Rake, we can group tasks:

group('db', function() {
    task('init', function() {
        echo "i'm initialising the database\n";
    });
});

This would be invoked by ./phake db:init

Describing Tasks

Call desc() immediately before defining a task to set its description:

desc("Initialises the database");
task('db_init', function() { echo "oh hai it's a database\n"; });

Output from ./phake -T:

db_init    Initialises the database

After/Before Blocks

Sometimes you may want to specify that some code should run before or after a task (distinct from dependencies), a bit like Capistrano. Phake supports this:

before('foo', function() { ... });
after('baz:bar', function() { ... });

Task Arguments

Phake allows arguments to specified on the command line:

# Execute task `quux` with the given args
./phake quux name=Jason city=Glasgow

This format must be matched exactly; do not put spaces between = and the argument name/value. If you need to put spaces in the argument value, place the entire assignment in quotes.

Arguments are made available to tasks by the application object's ArrayAccess implementation:

task('task_with_args', function($app) {
    $name = $app['name'];
    $city = $app['city'];
    // do some stuff...
});

Aborting Execution

To abort execution of a task sequence, simply throw an exception.

desc('Demonstrate failure');
task('fail', function() {
    throw new Exception;
});

Running phake fail will yield:

- jason@disco phake % ./bin/phake fail
(in /Users/jason/dev/projects/phake)
aborted!
Exception 

(See full trace by running task with --trace)

A Somewhat More Complete Example

This is what a complete Phakefile might look like. It also highlights some of the more complex name resolution issues arising when dealing with groups.

">

Here's the output from ./phake (implied task to run is default):

jason@ratchet phake [master*] $ ./phake
(in /Users/jason/dev/projects/phake)
I am the outer environment. I should run first.
I am the inner environment. I should run second.
I am initialising the database...
Running unit tests...
Running a second batch of unit tests...
All tests complete! (
   
    )

   

And the corresponding output from phake -T:

jason@ratchet phake [master*] $ ./phake -T
(in /Users/jason/dev/projects/phake)
database        Initialises the database connection
environment     Load the application environment
test:all:run    Run absolutely every test everywhere!
test:units      Run the unit tests

Bash Autocompletion

Bashkim Isai has created phake-autocomplete, a bash-completion script for phake task names.

Comments
  • Cyclic dependency checking

    Cyclic dependency checking

    Managing tasks in the environment of a distributed team can be tough, and sometimes cyclic dependencies between tasks happen by accident. This pull request implements Tarjan's algorithm, with tests, to find all cycles in a task graph. It also adds a command-line option that will output all cycles found along with the task names in a given cycle.

    Hopefully this is as helpful for others as it is for us. Phake is a great addition to the PHP ecosystem, and we'd like to support it. Please, feel free to offer up any comments or concerns. Thanks!

    opened by denzel-morris 10
  • Phake packaged as composer package for easy installation.

    Phake packaged as composer package for easy installation.

    I am using Phake in a framework that I am currently developing and would like it packaged in an easier to deal with manor.

    Composer seems to handle this pretty well.

    opened by trq 10
  • New release?

    New release?

    Would love to introduce some new Pomander code that uses the latest Phake stuff.

    Having to depend on the master branch is a pain with Composer. Can someone cut a release or is it not ready?

    maintenance 
    opened by tamagokun 9
  • Added support to bash color codes

    Added support to bash color codes

    I've added some extra helper functions to colorize outputs and I'd like to share with the community. I've tested the scripts in a Ubuntu 12.10 setup. Please poke me if there's some kind of incompatibility problem you know or some reason to not to use them ;)

    opened by darlanalves 9
  • Return all tasks in task listing

    Return all tasks in task listing

    Currently, running phake -T only returns all tasks that have a description assigned. This might be a bit misleading as one might expect to receive a listing of all (executable) task names.

    ~~This PR changes it so that every task that has at least one closure is listed. Obviously, this is subject to discussion and likely subject to change. Marking this as work-in-progress for now.~~

    After discussion about this issue, we instead decided to list every task that has at least a task body (task()) or any dependencies assigned. In the future we might add an additional hidden() helper to explicitly hide certain tasks.

    ~~Also related to #24, should we consider being able to run whole groups of tasks.~~

    ~~Depends on #22, actual changeset in 4cfcc89.~~

    opened by clue 8
  • Organize code according to PSR-0

    Organize code according to PSR-0

    This PR re-organizes the code to adhere to PSR-0. This is a required to include this project as a dependency into other projects (more PRs to follow to give some more insight). It also vastly simplifies working with the source code, because each class is in an independent file.

    It does NOT change any of the existing code.

    opened by clue 6
  • Consistent task names and resolving

    Consistent task names and resolving

    This PR vastly simplifies working with Nodes and Tasks internally, by making accessing single and/or multiple tasks consistent.

    The public API towards Phakefiles is left unchanged.

    It replaces most of the "resolving" logic with the two simple methods Node::get_task($task_name) and Node::get_tasks(). Both work in a recursive manner for grouped task names (foo:bar:baz). The Node::get_task() method now also implements the fallback behaviour to search the name either in the current group or fall back to the root node. To be consistent, each Node::get_name() method now returns the fully-qualified name instead of only the local name within its group.

    Any thoughts? Marking this as a work-in-progress for now.

    Depends on #20, so its diff is a bit difficult to check.

    opened by clue 5
  • task listing is completely broken

    task listing is completely broken

    Running bin/phake -T from master branch:

    PHP Notice:  Undefined property: phake\Node::$tasks in /Users/mkruk/Sites/php/phake/lib/phake/Node.php on line 118
    
    Notice: Undefined property: phake\Node::$tasks in /Users/mkruk/Sites/php/phake/lib/phake/Node.php on line 118
    PHP Fatal error:  Call to undefined method phake\Node::dependencies() in /Users/mkruk/Sites/php/phake/lib/phake/Node.php on line 114
    
    Fatal error: Call to undefined method phake\Node::dependencies() in /Users/mkruk/Sites/php/phake/lib/phake/Node.php on line 114
    
    opened by tamagokun 4
  • [WIP] Consider invoking child tasks when invoking a group

    [WIP] Consider invoking child tasks when invoking a group

    This PR is a suggestion to consider also invoking child tasks when invoking a group.

    Example Phakefile:

    group('build', function() {
      task('documentation', function() {
        // exec phpdoc/apigen/..
      });
      task('phar', function() {
        // exec box/phar-composer/..
      });
      task('deb', 'phar', function() {
        // bundle above phar as debian package
      });
    });
    
    // the default is to invoke all build:* tasks
    task('default', 'build');
    

    The actual order of when to execute the child tasks is of course open to discussion. In my option it makes sense to execute "before", "closure", "children", "after" in this order. But then again maybe I'm overlooking some edge case.

    Depends on #23, see 22b9bc4 for the actual changeset.

    opened by clue 4
  • Documentation on how to abort tasks

    Documentation on how to abort tasks

    I was playing around with Phake, trying to abort a sequence of tasks if one failed.

    Noticed that returning false does nothing to the super-task sequence. However, thrown exceptions become nice error messages in the console, but this is not documented in the README :(

    opened by igorsantos07 4
  • Add semver compatible tags (e.g. v1.0.0)

    Add semver compatible tags (e.g. v1.0.0)

    Makes the packagist integration a bit nicer and allows composer to cache the repository making updating packages a lot faster (in the context of a build server this can save several minutes).

    opened by phindmarsh 4
  • Running `group` should run `group:default` if it exists and no `group` task exists

    Running `group` should run `group:default` if it exists and no `group` task exists

    Ideally phake would use the following order of precedence to determine which task to run:

    1. A task with the exact name within the current or named group
    2. The default task in the current group
    3. Error

    That means if I have tasks for default, build, run, test, deploy, db:init, db:update, db:delete and db:default, test:init, test:run, and test:default, the following behaviour is expected:

    1. Running phake run would execute run
    2. Running phake default would execute default
    3. Running phake would execute default
    4. Running phake db:init would execute db:init
    5. Running phake db:default would execute db:default
    6. Running phake db would execute db:default
    7. Running phake test:init would execute test:init
    8. Running phake test:default would execute test:default
    9. Running phake test would execute test (there's a named task called test which has higher precedence than test:default)

    As far as I can tell, that mimics the behaviour of the root :default task fairly closely without breaking compatibility with existing Phakefiles.

    opened by kitgrose 0
  • [WIP] Load external phakefiles

    [WIP] Load external phakefiles

    This is a work-in-progress to add support for loading external phakefiles.

    Closes #16 (Define tasks in tasks directory with separate files). Also refs #31 (Do not chdir() to phakefile directory)

    new feature 
    opened by clue 0
  • Use echo() instead of fwrite() to support output buffering

    Use echo() instead of fwrite() to support output buffering

    This really simple patch changes the write() and writeln() function to use echo instead of fwrite(). This is done in order to be able to intercept the output using output buffering and for fetching during unit tests.

    maintenance 
    opened by clue 0
Owner
Jason Frame
Yarr!
Jason Frame
The modern, simple and intuitive PHP unit testing framework.

atoum PHP version atoum version 5.3 -> 5.6 1.x -> 3.x 7.2 -> 8.x 4.x (current) A simple, modern and intuitive unit testing framework for PHP! Just lik

atoum 1.4k Nov 29, 2022
Full-stack testing PHP framework

Codeception Modern PHP Testing for everyone Codeception is a modern full-stack testing framework for PHP. Inspired by BDD, it provides an absolutely n

Codeception Testing Framework 4.6k Jan 7, 2023
Faker is a PHP library that generates fake data for you

Faker Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in

FakerPHP 2.7k Dec 27, 2022
Mock HTTP requests on the server side in your PHP unit tests

HTTP Mock for PHP Mock HTTP requests on the server side in your PHP unit tests. HTTP Mock for PHP mocks the server side of an HTTP request to allow in

InterNations GmbH 386 Dec 27, 2022
AST based PHP Mutation Testing Framework

Infection - Mutation Testing framework Please read documentation here: infection.github.io Twitter: @infection_php Discord: https://discord.gg/ZUmyHTJ

Infection - Mutation Testing Framework for PHP 1.8k Jan 2, 2023
:heavy_check_mark: PHP Test Framework for Freedom, Truth, and Justice

Kahlan is a full-featured Unit & BDD test framework a la RSpec/JSpec which uses a describe-it syntax and moves testing in PHP one step forward. Kahlan

Kahlan 1.1k Jan 2, 2023
Event driven BDD test framework for PHP

The highly extensible, highly enjoyable, PHP testing framework. Read more at peridot-php.github.io or head over to the wiki. Building PHAR Peridot's p

Peridot 327 Jan 5, 2023
PHP Mocking Framework

Phake Phake is a framework for PHP that aims to provide mock objects, test doubles and method stubs. Phake was inspired by a lack of flexibility and e

Phake 469 Dec 2, 2022
BDD test framework for PHP

BDD test framework for PHP, inspired by Jasmine and RSpec. Features a familiar syntax, and a watch command to automatically re-run specs during develo

Daniel St. Jules 286 Nov 12, 2022
Mock built-in PHP functions (e.g. time(), exec() or rand())

PHP-Mock: mocking built-in PHP functions PHP-Mock is a testing library which mocks non deterministic built-in PHP functions like time() or rand(). Thi

null 331 Jan 3, 2023
A MySQL engine written in pure PHP

PHP MySQL Engine PHP MySQL Engine is a library for PHP that allows you to test database-driven applications with an in-memory simulation of MySQL 5.6.

Vimeo 529 Jan 4, 2023
SpecBDD Framework for PHP

phpspec The main website with documentation is at http://www.phpspec.net. Installing Dependencies Dependencies are handled via composer: wget -nc http

PHPSpec Framework 1.8k Dec 30, 2022
The PHP Unit Testing framework.

PHPUnit PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. Installat

Sebastian Bergmann 18.8k Jan 4, 2023
Highly opinionated mocking framework for PHP 5.3+

Prophecy Prophecy is a highly opinionated yet very powerful and flexible PHP object mocking framework. Though initially it was created to fulfil phpsp

PHPSpec Framework 8.5k Jan 3, 2023
PHP unit testing framework with built in mocks and stubs. Runs in the browser, or via the command line.

Enhance PHP A unit testing framework with mocks and stubs. Built for PHP, in PHP! Quick Start: Just add EnhanceTestFramework.php and you are ready to

Enhance PHP 67 Sep 12, 2022
A PHP Module, that help with geneting of task script for playwright and send it node.js

A PHP Module, that help with geneting of task script for playwright and send it node.js

LuKa 13 Dec 7, 2022
Library that provides collection, processing, and rendering functionality for PHP code coverage information.

phpunit/php-code-coverage Provides collection, processing, and rendering functionality for PHP code coverage information. Installation You can add thi

Sebastian Bergmann 8.5k Jan 5, 2023
A PHP library for mocking date and time in tests

ClockMock Slope s.r.l. ClockMock provides a way for mocking the current timestamp used by PHP for \DateTime(Immutable) objects and date/time related f

Slope 44 Dec 7, 2022