there4/slim-unit-testing-example

View on GitHub
pakefile

Summary

Maintainability
Test Coverage
<?php

pake_desc('Run the application with local php server');
pake_task('server');

pake_desc('Check the code for psr2 standards');
pake_task('sniff');

pake_desc('Update the contributors in the README');
pake_task('contributors');

pake_desc('Run syntax and unit tests');
pake_task('test');
pake_alias('default', 'test');

function run_server()
{
    $host = 'localhost:8008';
    pake_echo_comment('Now serving site from http://' . $host);
    pake_sh('php -S ' . $host . ' -t public', true);
}

function run_test()
{
    pake_echo_comment('Running unit suite');
    pake_sh('./vendor/bin/phpunit', true);
}

function run_sniff()
{
    pake_echo_comment('Checking files for PSR2');
    pake_sh("./vendor/bin/phpcs -p --standard=PSR2 ./public/index.php ./app ./lib");
}

function run_contributors()
{
    $startPoint   = '## Contributors';
    $endPoint     = '## Changelog';
    $readme       = file_get_contents("README.md");
    $contributors = explode("\n", shell_exec("git shortlog -s -n"));
    $table        = "| Author | Commits\n| --- | ---\n";
    foreach ($contributors as $contributor) {
        if (!trim($contributor)) { continue; }
        $contributor = explode("\t", $contributor);
        $table .= sprintf(
            "| %s | %s |\n",
            trim($contributor[1]),
            trim($contributor[0])
        );
    }
    $output = preg_replace(
        '/('.preg_quote($startPoint).')(.*)('.preg_quote($endPoint).')/si',
        "$1\n\n$table\n$3",
        $readme
    );
    file_put_contents("README.md", $output);
}

/* End of file pakefile */