Skip to content

Commit

Permalink
Made phing files match coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlbarnes committed Nov 5, 2011
1 parent 81abbcf commit 3b0c099
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -43,7 +43,7 @@ Once you have installed you can either run tests through the browser or via comm
* Command Link - `$ php unit_test.php`
* XML Results - `$ php unit_test_xml.php`

### NOTES:
## NOTES:

Inside the "tests" directory I include two example test files. The test_users_model.php will not run on its own because your application would not include the same users model as the example file. It is supplied just as a guide.

Expand Down
2 changes: 1 addition & 1 deletion phing/README.md
Expand Up @@ -7,7 +7,7 @@ Frank Hmeidan - <http://twitter.com/frankhmeidan>

Place the TestRunnerTask.php file in the following location: "phing/tasks/ext/TestRunnerTask.php"

Next create this in your Phing build file:
Next create this in your Phing build file:

<target name="unit_test">
<taskdef classname="phing.tasks.ext.TestRunnerTask" name="unit-test" />
Expand Down
81 changes: 41 additions & 40 deletions phing/TestRunnerTask.php
@@ -1,63 +1,64 @@
<?php

require_once "phing/Task.php";


/**
*
* Runs the unit tests
*
*
* @package phing.tasks.ext
*/
class TestRunnerTask extends Task {

protected $url = NULL;



public function init() { }

/**
* Invoking this task will cause the unit tests to be executed.
*/
public function main() {
public function main()
{
if (empty($this->url) || filter_var($this->url, FILTER_VALIDATE_URL) === FALSE) {
throw new BuildException('Invalid URL: You must specify a valid URL.');
}

echo "Running unit tests...\n";

$testResults = $this->doPOST($this->url, 'all', '1');

if ($testResults == NULL || $testResults == '' || !isset($testResults)){
throw new BuildException('No results page returned from POST request on $url');
}

/* Check if there is the string 'FAILED' anywhere in the output - if not, we've succeeded. */
if (strpos($testResults, 'FAILED') != FALSE){
throw new BuildException("There were test case failures - build terminated.");
} else {
echo "\n ----- all tested PASSED ----- \n";
}

return;
throw new BuildException('Invalid URL: You must specify a valid URL.');
}

echo "Running unit tests...\n";

$testResults = $this->doPOST($this->url, 'all', '1');

if ($testResults == NULL || $testResults == '' || !isset($testResults))
{
throw new BuildException('No results page returned from POST request on $url');
}

/* Check if there is the string 'FAILED' anywhere in the output - if not, we've succeeded. */
if (strpos($testResults, 'FAILED') != FALSE)
{
throw new BuildException("There were test case failures - build terminated.");
}
else
{
echo "\n ----- all tested PASSED ----- \n";
}

return;
}

public function setURL($url){
public function setURL($url)
{
$this->url = $url;
}

function doPOST($url, $key, $value) {

function doPOST($url, $key, $value)
{
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query(array($key => $value)),
)));

$ret = file_get_contents($url, false, $context);

return $ret;
}
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query(array($key => $value)),
)));

$ret = file_get_contents($url, false, $context);

return $ret;
}
}

0 comments on commit 3b0c099

Please sign in to comment.