Skip to content
This repository was archived by the owner on Nov 24, 2017. It is now read-only.

Commit 0179238

Browse files
Make autoloader function anonymous.
1 parent 4c94963 commit 0179238

File tree

3 files changed

+47
-65
lines changed

3 files changed

+47
-65
lines changed

PHPUnit/Extensions/Story/Autoload.php

+24-36
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,31 @@
4343
* @since File available since Release 1.0.0
4444
*/
4545

46-
function phpunit_story_autoload($class = NULL) {
47-
static $classes = NULL;
48-
static $path = NULL;
46+
spl_autoload_register(
47+
function ($class) {
48+
static $classes = NULL;
49+
static $path = NULL;
4950

50-
if ($classes === NULL) {
51-
$classes = array(
52-
'phpunit_extensions_story_given' => '/Extensions/Story/Given.php',
53-
'phpunit_extensions_story_resultprinter' => '/Extensions/Story/ResultPrinter.php',
54-
'phpunit_extensions_story_resultprinter_html' => '/Extensions/Story/ResultPrinter/HTML.php',
55-
'phpunit_extensions_story_resultprinter_text' => '/Extensions/Story/ResultPrinter/Text.php',
56-
'phpunit_extensions_story_scenario' => '/Extensions/Story/Scenario.php',
57-
'phpunit_extensions_story_step' => '/Extensions/Story/Step.php',
58-
'phpunit_extensions_story_testcase' => '/Extensions/Story/TestCase.php',
59-
'phpunit_extensions_story_then' => '/Extensions/Story/Then.php',
60-
'phpunit_extensions_story_when' => '/Extensions/Story/When.php'
61-
);
51+
if ($classes === NULL) {
52+
$classes = array(
53+
'phpunit_extensions_story_given' => '/Extensions/Story/Given.php',
54+
'phpunit_extensions_story_resultprinter' => '/Extensions/Story/ResultPrinter.php',
55+
'phpunit_extensions_story_resultprinter_html' => '/Extensions/Story/ResultPrinter/HTML.php',
56+
'phpunit_extensions_story_resultprinter_text' => '/Extensions/Story/ResultPrinter/Text.php',
57+
'phpunit_extensions_story_scenario' => '/Extensions/Story/Scenario.php',
58+
'phpunit_extensions_story_step' => '/Extensions/Story/Step.php',
59+
'phpunit_extensions_story_testcase' => '/Extensions/Story/TestCase.php',
60+
'phpunit_extensions_story_then' => '/Extensions/Story/Then.php',
61+
'phpunit_extensions_story_when' => '/Extensions/Story/When.php'
62+
);
6263

63-
$path = dirname(dirname(dirname(__FILE__)));
64-
}
64+
$path = dirname(dirname(dirname(__FILE__)));
65+
}
6566

66-
if ($class === NULL) {
67-
$result = array(__FILE__);
67+
$cn = strtolower($class);
6868

69-
foreach ($classes as $file) {
70-
$result[] = $path . $file;
71-
}
72-
73-
return $result;
74-
}
75-
76-
$cn = strtolower($class);
77-
78-
if (isset($classes[$cn])) {
79-
$file = $path . $classes[$cn];
80-
81-
require $file;
82-
}
83-
}
84-
85-
spl_autoload_register('phpunit_story_autoload');
69+
if (isset($classes[$cn])) {
70+
require $path . $classes[$cn];
71+
}
72+
}
73+
);

PHPUnit/Extensions/Story/Autoload.php.in

+16-28
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,23 @@
4343
* @since File available since Release 1.0.0
4444
*/
4545

46-
function phpunit_story_autoload($class = NULL) {
47-
static $classes = NULL;
48-
static $path = NULL;
46+
spl_autoload_register(
47+
function ($class) {
48+
static $classes = NULL;
49+
static $path = NULL;
4950

50-
if ($classes === NULL) {
51-
$classes = array(
52-
___CLASSLIST___
53-
);
51+
if ($classes === NULL) {
52+
$classes = array(
53+
___CLASSLIST___
54+
);
5455

55-
$path = dirname(dirname(dirname(__FILE__)));
56-
}
56+
$path = dirname(dirname(dirname(__FILE__)));
57+
}
5758

58-
if ($class === NULL) {
59-
$result = array(__FILE__);
59+
$cn = strtolower($class);
6060

61-
foreach ($classes as $file) {
62-
$result[] = $path . $file;
63-
}
64-
65-
return $result;
66-
}
67-
68-
$cn = strtolower($class);
69-
70-
if (isset($classes[$cn])) {
71-
$file = $path . $classes[$cn];
72-
73-
require $file;
74-
}
75-
}
76-
77-
spl_autoload_register('phpunit_story_autoload');
61+
if (isset($classes[$cn])) {
62+
require $path . $classes[$cn];
63+
}
64+
}
65+
);

build.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<project name="phpunit-selenium" default="phpab" basedir=".">
22
<target name="phpab">
33
<exec executable="phpab">
4-
<arg line='-o PHPUnit/Extensions/Story/Autoload.php -c -t PHPUnit/Extensions/Story/Autoload.php.in --indent " " PHPUnit' />
4+
<arg value="--output" />
5+
<arg path="PHPUnit/Extensions/Story/Autoload.php" />
6+
<arg value="--template" />
7+
<arg path="PHPUnit/Extensions/Story/Autoload.php.in" />
8+
<arg value="--indent" />
9+
<arg value=" " />
10+
<arg path="PHPUnit" />
511
</exec>
612
</target>
713
</project>

0 commit comments

Comments
 (0)