Skip to content
This repository has been archived by the owner on Mar 2, 2019. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Hough committed Apr 30, 2014
2 parents 44de7bf + 1d77d8b commit 84a1693
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 49 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ php:
- 5.3
- 5.4
- 5.5
- 5.6
before_script:
- "mkdir -p ~/.composer"
- cp src/test/resources/travis-composer-config.json ~/.composer/config.json
- wget https://raw.github.com/ehough/throwback/develop/src/main/bash/travis-setup.sh
- chmod a+x travis-setup.sh
- ./travis-setup.sh
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/ehough/pulsar/ApcClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct($prefix, $decorated)
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public function unregister()
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
Expand Down
6 changes: 3 additions & 3 deletions src/main/php/ehough/pulsar/ClassCollectionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ehough_pulsar_ClassCollectionLoader
* @param array $classes An array of classes to load
* @param string $cacheDir A cache directory
* @param string $name The cache name prefix
* @param Boolean $autoReload Whether to flush the cache when the cache is stale or not
* @param Boolean $adaptive Whether to remove already declared classes or not
* @param bool $autoReload Whether to flush the cache when the cache is stale or not
* @param bool $adaptive Whether to remove already declared classes or not
* @param string $extension File extension of the resulting file
*
* @throws InvalidArgumentException When class can't be loaded
Expand Down Expand Up @@ -198,7 +198,7 @@ public static function fixNamespaceDeclarations($source)
*/
public static function enableTokenizer($bool)
{
self::$useTokenizer = (Boolean) $bool;
self::$useTokenizer = (bool) $bool;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/main/php/ehough/pulsar/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function addPrefix($prefix, $paths)
/**
* Turns on searching the include for class files.
*
* @param Boolean $useIncludePath
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
Expand All @@ -112,7 +112,7 @@ public function setUseIncludePath($useIncludePath)
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return Boolean
* @return bool
*/
public function getUseIncludePath()
{
Expand All @@ -122,7 +122,7 @@ public function getUseIncludePath()
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
Expand All @@ -142,7 +142,7 @@ public function unregister()
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/ehough/pulsar/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function findFile($class)
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
* @return bool|null True, if loaded
*
* @throws \RuntimeException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/ehough/pulsar/DebugUniversalClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function enable()
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function loadClass($class)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/ehough/pulsar/MapClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(array $map)
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/ehough/pulsar/Psr4ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function findFile($class)
/**
* @param string $class
*
* @return Boolean
* @return bool
*/
public function loadClass($class)
{
Expand All @@ -75,7 +75,7 @@ public function loadClass($class)
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend
* @param bool $prepend
*/
public function register($prepend = false)
{
Expand Down
8 changes: 4 additions & 4 deletions src/main/php/ehough/pulsar/UniversalClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ehough_pulsar_UniversalClassLoader
* Turns on searching the include for class files. Allows easy loading
* of installed PEAR packages
*
* @param Boolean $useIncludePath
* @param bool $useIncludePath
*/
public function useIncludePath($useIncludePath)
{
Expand All @@ -79,7 +79,7 @@ public function useIncludePath($useIncludePath)
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return Boolean
* @return bool
*/
public function getUseIncludePath()
{
Expand Down Expand Up @@ -227,7 +227,7 @@ public function registerPrefix($prefix, $paths)
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*
* @api
*/
Expand All @@ -250,7 +250,7 @@ public function register($prepend = false)
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/ehough/pulsar/WinCacheClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __construct($prefix, $decorated)
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
Expand All @@ -94,7 +94,7 @@ public function unregister()
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/ehough/pulsar/XcacheClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct($prefix, $classFinder)
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public function unregister()
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
Expand Down
57 changes: 41 additions & 16 deletions src/test/php/ehough/pulsar/ClassCollectionLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@
* file that was distributed with this source code.
*/

require_once dirname(__FILE__).'/../../../resources/Fixtures/ClassesWithParents/GInterface.php';
require_once dirname(__FILE__).'/../../../resources/Fixtures/ClassesWithParents/CInterface.php';
require_once dirname(__FILE__).'/../../../resources/Fixtures/ClassesWithParents/B.php';
require_once dirname(__FILE__).'/../../../resources/Fixtures/ClassesWithParents/A.php';
if (version_compare(phpversion(), '5.3') >= 0) {
require_once dirname(__FILE__).'/../../../resources/Fixtures/ClassesWithParents/GInterface.php';
require_once dirname(__FILE__).'/../../../resources/Fixtures/ClassesWithParents/CInterface.php';
require_once dirname(__FILE__).'/../../../resources/Fixtures/ClassesWithParents/B.php';
require_once dirname(__FILE__).'/../../../resources/Fixtures/ClassesWithParents/A.php';
}

class ehough_pulsar_ClassCollectionLoaderTest extends PHPUnit_Framework_TestCase
{
public function setup()
{
if (version_compare(phpversion(), '5.3', '<')) {
$this->markTestSkipped('Requires PHP > 5.3');

return;
}
}

public function testTraitDependencies()
{
if (version_compare(phpversion(), '5.4', '<')) {
Expand All @@ -26,22 +37,22 @@ public function testTraitDependencies()

require_once dirname(__FILE__).'/../../../resources/Fixtures/deps/traits.php';

$r = new \ReflectionClass('ehough_pulsar_ClassCollectionLoader');
$r = new ReflectionClass('ehough_pulsar_ClassCollectionLoader');
$m = $r->getMethod('getOrderedClasses');
$m->setAccessible(true);

$ordered = $m->invoke('ehough_pulsar_ClassCollectionLoader', array('CTFoo'));

$this->assertEquals(
array('TD', 'TC', 'TB', 'TA', 'TZ', 'CTFoo'),
array_map(function ($class) { return $class->getName(); }, $ordered)
array_map(array($this, '__callbackGetClassName'), $ordered)
);

$ordered = $m->invoke('ehough_pulsar_ClassCollectionLoader', array('CTBar'));

$this->assertEquals(
array('TD', 'TZ', 'TC', 'TB', 'TA', 'CTBar'),
array_map(function ($class) { return $class->getName(); }, $ordered)
array_map(array($this, '__callbackGetClassName'), $ordered)
);
}

Expand All @@ -50,20 +61,31 @@ public function testTraitDependencies()
*/
public function testClassReordering(array $classes)
{
if (version_compare(phpversion(), '5.3', '<')) {
$this->markTestSkipped('Requires PHP > 5.3');

return;
}

$expected = array(
'ClassesWithParents\\GInterface',
'ClassesWithParents\\CInterface',
'ClassesWithParents\\B',
'ClassesWithParents\\A',
);

$r = new \ReflectionClass('ehough_pulsar_ClassCollectionLoader');
$r = new ReflectionClass('ehough_pulsar_ClassCollectionLoader');
$m = $r->getMethod('getOrderedClasses');
$m->setAccessible(true);

$ordered = $m->invoke('ehough_pulsar_ClassCollectionLoader', $classes);

$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
$this->assertEquals($expected, array_map(array($this, '__callbackGetClassName'), $ordered));
}

public function __callbackGetClassName($class)
{
return $class->getName();
}

public function getDifferentOrders()
Expand Down Expand Up @@ -120,13 +142,13 @@ public function testClassWithTraitsReordering(array $classes)
'ClassesWithParents\\E',
);

$r = new \ReflectionClass('ehough_pulsar_ClassCollectionLoader');
$r = new ReflectionClass('ehough_pulsar_ClassCollectionLoader');
$m = $r->getMethod('getOrderedClasses');
$m->setAccessible(true);

$ordered = $m->invoke('ehough_pulsar_ClassCollectionLoader', $classes);

$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
$this->assertEquals($expected, array_map(array($this, '__callbackGetClassName'), $ordered));
}

public function getDifferentOrdersForTraits()
Expand Down Expand Up @@ -201,11 +223,7 @@ public function testCommentStripping()
if (is_file($file = sys_get_temp_dir().'/bar.php')) {
unlink($file);
}
spl_autoload_register($r = function ($class) {
if (0 === strpos($class, 'Namespaced') || 0 === strpos($class, 'Pearlike_')) {
require_once dirname(__FILE__).'/../../../resources/Fixtures/'.str_replace(array('\\', '_'), '/', $class).'.php';
}
});
spl_autoload_register($r = array($this, '__callback_testCommentStripping'));

ehough_pulsar_ClassCollectionLoader::load(
array('Namespaced\\WithComments', 'Pearlike_WithComments'),
Expand Down Expand Up @@ -253,4 +271,11 @@ class Pearlike_WithComments

unlink($file);
}

public function __callback_testCommentStripping($class)
{
if (0 === strpos($class, 'Namespaced') || 0 === strpos($class, 'Pearlike_')) {
require_once dirname(__FILE__).'/../../../resources/Fixtures/'.str_replace(array('\\', '_'), '/', $class).'.php';
}
}
}
13 changes: 11 additions & 2 deletions src/test/php/ehough/pulsar/ClassMapGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class ehough_pulsar_ClassMapGeneratorTest extends PHPUnit_Framework_TestCase
*/
private $workspace = null;

public function setup()
{
if (version_compare(PHP_VERSION, '5.3') < 0) {

$this->markTestSkipped('PHP 5.2');
}
}

public function prepare_workspace()
{
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().rand(0, 1000);
Expand All @@ -29,7 +37,7 @@ public function prepare_workspace()
private function clean($file)
{
if (is_dir($file) && !is_link($file)) {
$dir = new \FilesystemIterator($file);
$dir = new FilesystemIterator($file);
foreach ($dir as $childFile) {
$this->clean($childFile);
}
Expand Down Expand Up @@ -120,7 +128,8 @@ public function testCreateMapFinderSupport()
$this->markTestSkipped('Finder component is not available');
}

$finder = new \Symfony\Component\Finder\Finder();
$ref = new ReflectionClass('Symfony\\Component\\Finder\\Finder');
$finder = $ref->newInstance();
$finder->files()->in(dirname(__FILE__) . '/../../../resources/Fixtures/beta/NamespaceCollision');

$this->assertEqualsNormalized(array(
Expand Down
7 changes: 0 additions & 7 deletions src/test/resources/travis-composer-config.json

This file was deleted.

0 comments on commit 84a1693

Please sign in to comment.