Skip to content

Commit

Permalink
Travis is not ready for PSR4 yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremeamia committed Jan 14, 2014
1 parent 87170b1 commit 9cadee5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
28 changes: 28 additions & 0 deletions autoload.php
@@ -0,0 +1,28 @@
<?php
/**
* PSR-4 compliant autoloader.
*
* This will be removed when Composer supports PSR-4 natively.
*
* @param string $fqcn The fully-qualified class name.
*
* @return void
* @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md
* @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
*/
spl_autoload_register(function ($fqcn) {
$prefix = 'Jeremeamia\\SuperClosure\\';
$baseDir = __DIR__ . '/src/';

$prefixLength = strlen($prefix);
if (strncmp($prefix, $fqcn, $prefixLength) !== 0) {
// Class doesn't match prefix
return;
}

$className = substr($fqcn, $prefixLength);
$filePath = $baseDir . str_replace('\\', '/', $className) . '.php';
if (is_readable($filePath)) {
require $filePath;
}
});
5 changes: 1 addition & 4 deletions composer.json
Expand Up @@ -21,11 +21,8 @@
"phpunit/phpunit": "~3.7"
},
"autoload": {
"psr-4": {
"Jeremeamia\\SuperClosure\\": "src/",
"Jeremeamia\\SuperClosure\\Test\\": "tests/"
},
"files": [
"autoload.php",
"src/functions.php"
]
}
Expand Down
20 changes: 19 additions & 1 deletion tests/bootstrap.php
@@ -1,4 +1,22 @@
<?php

date_default_timezone_set('America/Los_Angeles');
date_default_timezone_set('UTC');
require __DIR__ . '/../vendor/autoload.php';

// Register another PSR-4-compliant autoloader for loading test classes
spl_autoload_register(function ($fqcn) {
$prefix = 'Jeremeamia\\SuperClosure\\Test\\';
$baseDir = __DIR__ . '/';

$prefixLength = strlen($prefix);
if (strncmp($prefix, $fqcn, $prefixLength) !== 0) {
// Class doesn't match prefix
return;
}

$className = substr($fqcn, $prefixLength);
$filePath = $baseDir . str_replace('\\', '/', $className) . '.php';
if (is_readable($filePath)) {
require $filePath;
}
});

2 comments on commit 9cadee5

@GrahamCampbell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just run composer self-update before running tests on travis?

@jeremeamia
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a good idea. I'll give that a shot.

Please sign in to comment.