Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Fenton committed Oct 9, 2011
1 parent 313ed78 commit 27b1745
Showing 1 changed file with 19 additions and 44 deletions.
63 changes: 19 additions & 44 deletions EnhanceTestFramework.php
@@ -1,32 +1,11 @@
<?php
// Enhance Unit Testing Framework For PHP
// Copyright 2011 Steve Fenton, Mark Jones
//
// Version 1.9
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// http://www.enhance-php.com/
// http://www.stevefenton.co.uk/
// - Contributors
// - PHP Code: Steve Fenton, Mark Jones
//
ini_set('error_reporting', (string)E_ALL);
ini_set('display_errors', '1');

// Public API
class Enhance
{
/** @var EnhanceTestFramework $Instance */
private static $Instance;

public static function discoverTests($path)
Expand Down Expand Up @@ -76,7 +55,7 @@ class MockFactory
{
public static function createMock($typeName)
{
return new EnhanceMock($typeName, $isMock = true);
return new EnhanceMock($typeName, true);
}
}

Expand All @@ -85,7 +64,7 @@ class StubFactory
{
public static function createStub($typeName)
{
return new EnhanceMock($typeName, $isMock = false);
return new EnhanceMock($typeName, false);
}
}

Expand Down Expand Up @@ -116,6 +95,7 @@ public static function setProperty($propertyName)
// Public API
class Assert
{
/** @var EnhanceAssertions $EnhanceAssertions */
private static $EnhanceAssertions;

private static function GetEnhanceAssertionsInstance()
Expand Down Expand Up @@ -255,8 +235,8 @@ public function EnhanceTestFramework()
$this->FileSystem = new EnhanceFileSystem();
}

public function discoverTests($path, $isResursive = true) {
$phpFiles = $this->FileSystem->getFilesFromDirectory($path, $isResursive);
public function discoverTests($path, $isRecursive = true) {
$phpFiles = $this->FileSystem->getFilesFromDirectory($path, $isRecursive);
foreach ($phpFiles as $file) {
include_once($file);
}
Expand Down Expand Up @@ -337,7 +317,7 @@ private function addTest($class, $method)
private function run()
{
$start = time();
foreach($this->Tests as $test) {
foreach($this->Tests as /** @var EnhanceTest $test */ $test) {
$result = $test->run();
if ($result) {
$message = $test->getTestName() . ' - ' . $this->Text->Passed;
Expand Down Expand Up @@ -375,14 +355,15 @@ public function getFilesFromDirectory($directory, $isRecursive) {
}

public function flattenArray($array) {
$merged = array();
foreach($array as $a) {
if(is_array($a)) {
$tmp = array_merge($tmp, $this->flattenArray($a));
$merged = array_merge($merged, $this->flattenArray($a));
} else {
$tmp[] = $a;
$merged[] = $a;
}
}
return $tmp;
return $merged;
}
}

Expand Down Expand Up @@ -436,8 +417,6 @@ public function getMessage()

public function run()
{
$result = false;

$testClass = new $this->ClassName();

try {
Expand Down Expand Up @@ -527,7 +506,7 @@ public function VerifyExpectations()
);
}

foreach ($this->Expectations as $expectation) {
foreach ($this->Expectations as /** @var EnhanceExpectation $expectation */ $expectation) {
if (!$expectation->verify()) {
$Arguments = '';
foreach($expectation->MethodArguments as $argument) {
Expand Down Expand Up @@ -558,7 +537,7 @@ public function __get($propertyName)

public function __set($propertyName, $value)
{
$Expectation = $this->getReturnValue('setProperty', $propertyName, array($value));
$this->getReturnValue('setProperty', $propertyName, array($value));
}

private function getReturnValue($type, $methodName, $args)
Expand Down Expand Up @@ -628,8 +607,7 @@ class EnhanceScenario
private $FunctionName;
private $Inputs = array();
private $Expectations = array();
private $Output= array();


public function EnhanceScenario($class, $functionName)
{
$this->Class = $class;
Expand Down Expand Up @@ -1047,8 +1025,7 @@ public function get($errors, $results, $text, $duration, $methodCalls)
$cr = "\n";
$tab = " ";
$failCount = count($errors);
$methodCallCount = count($methodCalls);


$message .= '<enhance>' . $cr;
if ($failCount > 0) {
$message .= $tab . '<result>' . $text->TestFailed . '</result>' . $cr;
Expand Down Expand Up @@ -1112,10 +1089,8 @@ public function get($errors, $results, $text, $duration, $methodCalls)
{
$message = '';
$cr = "\n";
$tab = " ";
$failCount = count($errors);
$methodCallCount = count($methodCalls);


if ($failCount > 0) {
$message .= $text->TestFailed . $cr;
} else {
Expand Down Expand Up @@ -1154,10 +1129,10 @@ public static function createOutputTemplate($type)
case EnhanceOutputTemplateType::Cli:
return new EnhanceCliTemplate();
break;
default:
break;
}
}

return new EnhanceHtmlTemplate();
}
}

class EnhanceOutputTemplateType
Expand Down

0 comments on commit 27b1745

Please sign in to comment.