Skip to content

Commit 318b869

Browse files
committed
Update optimized autoloader
- update readme - add testing (100% covered on new methods!) - remove classmap_generator test (it's covered by Autoload tests) - add a bootstrap file for misc functions
1 parent d6cf067 commit 318b869

File tree

5 files changed

+61
-45
lines changed

5 files changed

+61
-45
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ The two methods of describing the vendor root directory are:
3838

3939
## Optimizing the Autoloader
4040

41-
**WARNING: WIP**
42-
43-
Aside from `composer dump -o`, running `php shell/classmap_generator.php` when deploying new code to production is recommended. That script generates a classmap file to be used by composer to speed autoloading of files in Magento's code pools.
41+
Normally, `composer dump -o` is all one does to optimize a composer autoloader. However, running `php shell/classmap_generator.php` when deploying new code to production is recommended. The script generates a classmap file to be used by composer to speed autoloading of files in Magento's code pools.
4442

4543
To enable use of the generated classmap, include `define('OPTIMIZED_COMPOSER', true)` in `includes/config.php`.

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true">
2+
<phpunit bootstrap="tests/bootstrap.php" colors="true">
33
<testsuites>
44
<testsuite name="magento-composer-autoloader">
55
<directory>./tests</directory>

tests/AutoloadTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function testInstance()
1717
$this->assertInstanceOf('Varien_Autoload', Varien_Autoload::instance());
1818
}
1919

20+
2021
public function testRegisterStandard()
2122
{
2223
Varien_Autoload::register();
@@ -97,4 +98,34 @@ public function testRegisterComposer()
9798
$expectedPaths, $loader->getFallbackDirs());
9899
}
99100

101+
public function testRegisterClassmap()
102+
{
103+
define('OPTIMIZED_COMPOSER', true);
104+
105+
$testClassname = 'c'.uniqid();
106+
$testClassfilename = BP.'/lib/'.$testClassname.'.php';
107+
108+
$testClass = <<<CLASS
109+
<?php
110+
class {$testClassname} {}
111+
CLASS;
112+
113+
114+
testfuncs\create_structure();
115+
file_put_contents($testClassfilename, $testClass);
116+
117+
// Generate the classmap
118+
require BP . '/../src/classmap_generator.php';
119+
120+
Varien_Autoload::register();
121+
$loader = require __DIR__ . '/../vendor/autoload.php';
122+
123+
$classMap = $loader->getClassMap();
124+
125+
$this->assertArrayHasKey($testClassname, $classMap);
126+
127+
unlink($testClassfilename);
128+
testfuncs\destroy_structure();
129+
}
130+
100131
}

tests/bootstrap.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
namespace testfuncs;
3+
4+
function create_structure()
5+
{
6+
if (!defined('BP')) {
7+
define('BP', __DIR__);
8+
}
9+
10+
// Set recursive = true for the first app/code pool
11+
mkdir(BP . '/app/code/local', 0777, true);
12+
mkdir(BP . '/app/code/community');
13+
mkdir(BP . '/app/code/core');
14+
mkdir(BP . '/lib');
15+
mkdir(BP . '/includes');
16+
}
17+
18+
function destroy_structure()
19+
{
20+
rmdir(BP . '/app/code/local');
21+
rmdir(BP . '/app/code/community');
22+
rmdir(BP . '/app/code/core');
23+
rmdir(BP . '/app/code');
24+
rmdir(BP . '/app');
25+
rmdir(BP . '/lib');
26+
unlink(BP . '/includes/optimized_map.php');
27+
rmdir(BP . '/includes');
28+
}

tests/classmap_generatorTest.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)