Skip to content

Commit

Permalink
Merge pull request #116 from zf1s/loader-overhauled-again
Browse files Browse the repository at this point in the history
zend-loader and autoloader overhaul - cont.
falkenhawk authored Oct 4, 2022
2 parents fa84d41 + b54c84a commit 23b93f4
Showing 26 changed files with 343 additions and 60 deletions.
5 changes: 1 addition & 4 deletions packages/zend-currency/library/Zend/Currency.php
Original file line number Diff line number Diff line change
@@ -800,10 +800,7 @@ public function setService($service)
if (is_string($service)) {
// require_once 'Zend/Loader.php';
if (!class_exists($service)) {
$file = str_replace('_', DIRECTORY_SEPARATOR, $service) . '.php';
if (Zend_Loader::isReadable($file)) {
Zend_Loader::loadClass($service);
}
Zend_Loader::loadClass($service);
}

$service = new $service;
4 changes: 3 additions & 1 deletion packages/zend-file-transfer/library/Zend/File/Transfer.php
Original file line number Diff line number Diff line change
@@ -67,7 +67,9 @@ public function setAdapter($adapter, $direction = false, $options = array())
if (class_exists('Zend_File_Transfer_Adapter_' . ucfirst($adapter))) {
$adapter = 'Zend_File_Transfer_Adapter_' . ucfirst($adapter);
} elseif (!class_exists($adapter)) {
Zend_Loader::loadClass($adapter);
if (!Zend_Loader::tryLoadClass('Zend_File_Transfer_Adapter_' . ucfirst($adapter), null, true)) {
Zend_Loader::loadClass($adapter);
}
}

$direction = (integer) $direction;
5 changes: 2 additions & 3 deletions packages/zend-filter/library/Zend/Filter/Compress.php
Original file line number Diff line number Diff line change
@@ -100,10 +100,9 @@ public function getAdapter()
$adapter = 'Zend_Filter_Compress_' . ucfirst($adapter);
} elseif (!class_exists($adapter)) {
// require_once 'Zend/Loader.php';
if (Zend_Loader::isReadable('Zend/Filter/Compress/' . ucfirst($adapter) . '.php')) {
$adapter = 'Zend_Filter_Compress_' . ucfirst($adapter);
if (!Zend_Loader::tryLoadClass('Zend_Filter_Compress_' . ucfirst($adapter))) {
Zend_Loader::loadClass($adapter);
}
Zend_Loader::loadClass($adapter);
}

$this->_adapter = new $adapter($options);
4 changes: 3 additions & 1 deletion packages/zend-filter/library/Zend/Filter/Encrypt.php
Original file line number Diff line number Diff line change
@@ -92,7 +92,9 @@ public function setAdapter($options = null)
if (class_exists('Zend_Filter_Encrypt_' . ucfirst($adapter))) {
$adapter = 'Zend_Filter_Encrypt_' . ucfirst($adapter);
} elseif (!class_exists($adapter)) {
Zend_Loader::loadClass($adapter);
if (!Zend_Loader::tryLoadClass('Zend_Filter_Encrypt_' . ucfirst($adapter))) {
Zend_Loader::loadClass($adapter);
}
}

$this->_adapter = new $adapter($options);
9 changes: 2 additions & 7 deletions packages/zend-gdata/library/Zend/Gdata/App.php
Original file line number Diff line number Diff line change
@@ -828,7 +828,7 @@ public static function importString($string,

if (!$doc) {
$err = error_get_last();
$phpErrormsg = $err['message'];
$phpErrormsg = isset($err['message'][0]) ? $err['message'] : null;
// require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
"DOMDocument cannot parse XML: $phpErrormsg");
@@ -1053,12 +1053,7 @@ public function __call($method, $args)
$foundClassName = null;
foreach ($this->_registeredPackages as $name) {
try {
// Autoloading disabled on next line for compatibility
// with magic factories. See ZF-6660.
Zend_Loader_Autoloader::setDisabled();
$found = class_exists($name . '_' . $class);
Zend_Loader_Autoloader::setDisabled(false);
if (!$found) {
if (!class_exists($name . '_' . $class)) {
// require_once 'Zend/Loader.php';
@Zend_Loader::loadClass($name . '_' . $class);
}
7 changes: 1 addition & 6 deletions packages/zend-gdata/library/Zend/Gdata/Gapps.php
Original file line number Diff line number Diff line change
@@ -859,12 +859,7 @@ public function __call($method, $args) {
$foundClassName = null;
foreach ($this->_registeredPackages as $name) {
try {
// Autoloading disabled on next line for compatibility
// with magic factories. See ZF-6660.
Zend_Loader_Autoloader::setDisabled();
$found = class_exists($name . '_' . $class);
Zend_Loader_Autoloader::setDisabled(false);
if (!$found) {
if (!class_exists($name . '_' . $class)) {
// require_once 'Zend/Loader.php';
@Zend_Loader::loadClass($name . '_' . $class);
}
59 changes: 40 additions & 19 deletions packages/zend-loader/library/Zend/Loader.php
Original file line number Diff line number Diff line change
@@ -46,13 +46,13 @@ class Zend_Loader
* @param string $class - The full class name of a Zend component.
* @param string|array $dirs - OPTIONAL Either a path or an array of paths
* to search.
* @return void
* @return boolean
* @throws Zend_Exception
*/
public static function loadClass($class, $dirs = null)
{
if (class_exists($class, false) || interface_exists($class, false)) {
return;
return true;
}

if ((null !== $dirs) && !is_string($dirs) && !is_array($dirs)) {
@@ -61,6 +61,7 @@ public static function loadClass($class, $dirs = null)
}

$file = self::standardiseFile($class);
$fileLoaded = false;

if (!empty($dirs)) {
// use the autodiscovered path
@@ -77,14 +78,36 @@ public static function loadClass($class, $dirs = null)
}
}
$file = basename($file);
self::loadFile($file, $dirs, true);
$fileLoaded = self::loadFile($file, $dirs, true);
} else {
self::loadFile($file, null, true);
$fileLoaded = self::loadFile($file, null, true);
}

if (!$fileLoaded) {
throw new Zend_Loader_Exception_FileNotFoundException("File \"$file\" could not be found within configured include_path.");
}

if (!class_exists($class, false) && !interface_exists($class, false)) {
// require_once 'Zend/Exception.php';
throw new Zend_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file");
throw new Zend_Loader_Exception_ClassNotFoundException("Class \"$class\" was not found in the file \"$file\".");
}
return true;
}

/**
* Try to load a class from a PHP file.
* Similar to `loadClass` but it will not throw when a file matching class name is not found.
*
* @param string $class - The full class name of a Zend component.
* @param string|array $dirs - OPTIONAL Either a path or an array of paths
* to search.
* @return boolean
*/
public static function tryLoadClass($class, $dirs = null)
{
try {
return self::loadClass($class, $dirs);
} catch (Zend_Loader_Exception_FileNotFoundException $e) {
return false;
}
}

@@ -127,6 +150,16 @@ public static function loadFile($filename, $dirs = null, $once = false)
set_include_path($dirs . PATH_SEPARATOR . $incPath);
}

/**
* Bail early when file is not readable - avoid throwing file not found warnings
*/
if (!self::isReadable($filename)) {
if ($incPath) {
set_include_path($incPath);
}
return false;
}

/**
* Try finding for the plain filename in the include_path.
*/
@@ -175,19 +208,7 @@ public static function isReadable($filename)
return false;
}

foreach (self::explodeIncludePath() as $path) {
if ($path == '.') {
if (is_readable($filename)) {
return true;
}
continue;
}
$file = $path . '/' . $filename;
if (is_readable($file)) {
return true;
}
}
return false;
return stream_resolve_include_path($filename) !== false;
}

/**
3 changes: 3 additions & 0 deletions packages/zend-loader/library/Zend/Loader/Autoloader.php
Original file line number Diff line number Diff line change
@@ -106,6 +106,9 @@ public static function getInstance()
*/
public static function resetInstance()
{
if (null !== self::$_instance) {
spl_autoload_unregister(array(__CLASS__, 'autoload'));
}
self::$_instance = null;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Loader
* @subpackage Exception
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

// require_once dirname(__FILE__) . '/../Exception.php';

/**
* @category Zend
* @package Zend_Loader
* @subpackage Exception
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Loader_Exception_ClassNotFoundException extends Zend_Loader_Exception
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Loader
* @subpackage Exception
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

// require_once dirname(__FILE__) . '/../Exception.php';

/**
* @category Zend
* @package Zend_Loader
* @subpackage Exception
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Loader_Exception_FileNotFoundException extends Zend_Loader_Exception
{

}
4 changes: 3 additions & 1 deletion packages/zend-translate/library/Zend/Translate.php
Original file line number Diff line number Diff line change
@@ -130,7 +130,9 @@ public function setAdapter($options = array())
if (class_exists('Zend_Translate_Adapter_' . ucfirst($options['adapter']))) {
$options['adapter'] = 'Zend_Translate_Adapter_' . ucfirst($options['adapter']);
} elseif (!class_exists($options['adapter'])) {
Zend_Loader::loadClass($options['adapter']);
if (!Zend_Loader::tryLoadClass('Zend_Translate_Adapter_' . ucfirst($options['adapter']))) {
Zend_Loader::loadClass($options['adapter']);
}
}

if (array_key_exists('cache', $options)) {
4 changes: 3 additions & 1 deletion packages/zend-validate/library/Zend/Validate/Barcode.php
Original file line number Diff line number Diff line change
@@ -134,7 +134,9 @@ public function setAdapter($adapter, $options = null)
if (class_exists('Zend_Validate_Barcode_' . $adapter)) {
$adapter = 'Zend_Validate_Barcode_' . $adapter;
} elseif (!class_exists($adapter)) {
Zend_Loader::loadClass($adapter);
if (!Zend_Loader::tryLoadClass('Zend_Validate_Barcode_' . $adapter)) {
Zend_Loader::loadClass($adapter);
}
}

$this->_adapter = new $adapter($options);
4 changes: 2 additions & 2 deletions tests/Zend/Barcode/FactoryTest.php
Original file line number Diff line number Diff line change
@@ -239,7 +239,7 @@ public function testBarcodeObjectFactoryWithNamespaceButWithoutExtendingObjectAb
}

/**
* @expectedException PHPUnit_Framework_Error
* @expectedException Zend_Loader_Exception_FileNotFoundException
*/
public function testBarcodeObjectFactoryWithUnexistantBarcode()
{
@@ -338,7 +338,7 @@ public function testBarcodeFactoryWithNamespaceButWithoutExtendingRendererAbstra
}

/**
* @expectedException PHPUnit_Framework_Error
* @expectedException Zend_Loader_Exception_FileNotFoundException
*/
public function testBarcodeRendererFactoryWithUnexistantRenderer()
{
2 changes: 1 addition & 1 deletion tests/Zend/Db/Adapter/StaticTest.php
Original file line number Diff line number Diff line change
@@ -327,7 +327,7 @@ public function testDbFactoryWillThrowExceptionWhenAssumingBadBehavior()
);
} catch (Exception $e) {
set_include_path($oldIncludePath);
$this->assertContains('failed to open stream', $e->getMessage(), '', true);
$this->assertContains('could not be found', $e->getMessage());
return;
}

12 changes: 8 additions & 4 deletions tests/Zend/Db/Table/Relationships/TestCommon.php
Original file line number Diff line number Diff line change
@@ -158,7 +158,8 @@ public function testTableRelationshipMagicException()
}

/**
* @expectedException PHPUnit_Framework_Error
* @expectedException Zend_Db_Table_Row_Exception
* @expectedExceptionMessage could not be found
*/
public function testTableRelationshipFindParentRowErrorOnBadString()
{
@@ -265,7 +266,8 @@ public function testTableRelationshipMagicFindManyToManyRowsetSelect()
}

/**
* @expectedException PHPUnit_Framework_Error
* @expectedException Zend_Db_Table_Row_Exception
* @expectedExceptionMessage could not be found
*/
public function testTableRelationshipFindManyToManyRowsetErrorOnBadClassNameAsString()
{
@@ -280,7 +282,8 @@ public function testTableRelationshipFindManyToManyRowsetErrorOnBadClassNameAsSt
}

/**
* @expectedException PHPUnit_Framework_Error
* @expectedException Zend_Db_Table_Row_Exception
* @expectedExceptionMessage could not be found
*/
public function testTableRelationshipFindManyToManyRowsetErrorOnBadClassNameAsStringForIntersection()
{
@@ -425,7 +428,8 @@ public function testTableRelationshipMagicFindDependentRowsetSelect()
}

/**
* @expectedException PHPUnit_Framework_Error
* @expectedException Zend_Db_Table_Row_Exception
* @expectedExceptionMessage could not be found
*/
public function testTableRelationshipFindDependentRowsetPhpError()
{
24 changes: 22 additions & 2 deletions tests/Zend/Loader/AutoloaderTest.php
Original file line number Diff line number Diff line change
@@ -331,12 +331,18 @@ public function testAutoloadShouldReturnFalseWhenNamespaceIsNotRegisteredButClas
$this->assertFalse(Zend_Loader_Autoloader::autoload('ZendLoaderAutoloader_Foo'));
}

public function testAutoloadShouldReturnFalseWhenClassIsNotDefinedInClassfile()
{
$this->addTestIncludePath();
$this->autoloader->registerNamespace('ZendLoaderAutoloader');
$this->assertFalse(Zend_Loader_Autoloader::autoload('ZendLoaderAutoloader_ClassNonexistent'));
}

public function testAutoloadShouldLoadClassWhenNamespaceIsRegisteredAndClassfileExists()
{
$this->addTestIncludePath();
$this->autoloader->registerNamespace('ZendLoaderAutoloader');
$result = Zend_Loader_Autoloader::autoload('ZendLoaderAutoloader_Foo');
$this->assertFalse($result === false);
$this->assertTrue(Zend_Loader_Autoloader::autoload('ZendLoaderAutoloader_Foo'));
$this->assertTrue(class_exists('ZendLoaderAutoloader_Foo', false));
}

@@ -348,6 +354,20 @@ public function testAutoloadShouldNotSuppressFileNotFoundWarningsWhenFlagIsDisab
set_error_handler(array($this, 'handleErrors'));
$this->assertFalse(Zend_Loader_Autoloader::autoload('ZendLoaderAutoloader_Bar'));
restore_error_handler();

// Zend_Loader does not issue "file not found warnings" anymore because files are now checked for being readable before include call
//$this->assertNotNull($this->error);
$this->assertNull($this->error);
}

public function testAutoloadShouldNotSuppressErrorsWhenFlagIsDisabled()
{
$this->addTestIncludePath();
$this->autoloader->suppressNotFoundWarnings(false);
$this->autoloader->registerNamespace('ZendLoaderAutoloader');
set_error_handler(array($this, 'handleErrors'));
$this->assertTrue(Zend_Loader_Autoloader::autoload('ZendLoaderAutoloader_SomethingWrong'));
restore_error_handler();
$this->assertNotNull($this->error);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

/**
* A file not containing a class
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* A class containing a parse error
*/
class ZendLoaderAutoloader_SomethingWrong
{
}

trigger_error('Something is wrong here', E_USER_WARNING);
57 changes: 55 additions & 2 deletions tests/Zend/LoaderTest.php
Original file line number Diff line number Diff line change
@@ -131,7 +131,8 @@ public function testLoaderClassValid()
{
$dir = implode(DIRECTORY_SEPARATOR, array(__DIR__, '_files', '_testDir1'));

Zend_Loader::loadClass('Class1', $dir);
$this->assertTrue(Zend_Loader::loadClass('Class1', $dir));
$this->assertTrue(class_exists('Class1', false));
}

public function testLoaderInterfaceViaLoadClass()
@@ -173,13 +174,65 @@ public function testLoaderLoadClassWithDotDir()
*/
public function testLoaderClassNonexistent()
{
$this->setErrorHandler();
$dir = implode(DIRECTORY_SEPARATOR, array(__DIR__, '_files', '_testDir1'));

try {
Zend_Loader::loadClass('ClassNonexistent', $dir);
$this->fail('Zend_Exception was expected but never thrown.');
} catch (Zend_Exception $e) {
$this->assertRegExp('/file(.*)does not exist or class(.*)not found/i', $e->getMessage());
$this->assertEquals('Class "ClassNonexistent" was not found in the file "ClassNonexistent.php".', $e->getMessage());
$this->assertNull($this->error);
}
}

/**
* Tests that an exception is thrown when a file is not found
*/
public function testLoaderFileNonexistent()
{
$this->setErrorHandler();
$dir = implode(DIRECTORY_SEPARATOR, array(__DIR__, '_files', '_testDir1'));

try {
Zend_Loader::loadClass('FileNotexistent', $dir);
$this->fail('Zend_Exception was expected but never thrown.');
} catch (Zend_Exception $e) {
$this->assertRegExp('/file "(.*)" could not be found within configured include_path/i', $e->getMessage());
// "file not found" warning is not emitted anymore
$this->assertNull($this->error);
}
}

/**
* Tests that an exception is not thrown
* using `tryLoadClass` to silently fail when file is not found
*/
public function testLoaderTryLoadFileNonexistent()
{
$this->setErrorHandler();
$dir = implode(DIRECTORY_SEPARATOR, array(__DIR__, '_files', '_testDir1'));

$this->assertFalse(Zend_Loader::tryLoadClass('FileNotexistent', $dir));
// "file not found" warning is not emitted anymore
$this->assertNull($this->error);
}

/**
* Tests that an exception is still thrown when class in a file does not exist
* while using `tryLoadClass`
*/
public function testLoaderTryLoadClassNonexistent()
{
$this->setErrorHandler();
$dir = implode(DIRECTORY_SEPARATOR, array(__DIR__, '_files', '_testDir1'));

try {
Zend_Loader::tryLoadClass('ClassNonexistent', $dir);
$this->fail('Zend_Exception was expected but never thrown.');
} catch (Zend_Exception $e) {
$this->assertEquals('Class "ClassNonexistent" was not found in the file "ClassNonexistent.php".', $e->getMessage());
$this->assertNull($this->error);
}
}

4 changes: 2 additions & 2 deletions tests/Zend/Navigation/PageFactoryTest.php
Original file line number Diff line number Diff line change
@@ -155,8 +155,8 @@ public function testShouldFailForNonExistantType()
);
} catch(Zend_Exception $e) {
$this->assertEquals(
'File "My' . DIRECTORY_SEPARATOR . 'NonExistant' . DIRECTORY_SEPARATOR . 'Page.php" does not exist or class '
. '"My_NonExistant_Page" was not found in the file',
'File "My' . DIRECTORY_SEPARATOR . 'NonExistant' . DIRECTORY_SEPARATOR . 'Page.php" '
. 'could not be found within configured include_path.',
$e->getMessage()
);
}
2 changes: 1 addition & 1 deletion tests/Zend/RegistryTest.php
Original file line number Diff line number Diff line change
@@ -187,7 +187,7 @@ public function testRegistryExceptionClassNotFound()
$registry = @Zend_Registry::setClassName('classdoesnotexist');
$this->fail('Expected exception, because we cannot initialize the registry using a non-existent class.');
} catch (Zend_Exception $e) {
$this->assertRegExp('/file .* does not exist or .*/i', $e->getMessage());
$this->assertRegExp('/file .* could not be found/i', $e->getMessage());
}
}

3 changes: 1 addition & 2 deletions tests/Zend/Service/StrikeIron/StrikeIronTest.php
Original file line number Diff line number Diff line change
@@ -50,8 +50,7 @@ public function testFactoryThrowsOnBadName()
$this->strikeIron->getService(array('class' => 'BadServiceNameHere'));
$this->fail();
} catch (Zend_Service_StrikeIron_Exception $e) {
$this->assertRegExp('/could not be loaded/i', $e->getMessage());
$this->assertRegExp('/not found/i', $e->getMessage());
$this->assertRegExp('/could not be found/i', $e->getMessage());
}
}

2 changes: 2 additions & 0 deletions tests/Zend/Translate/Adapter/AllTests.php
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
require_once 'Zend/Translate/Adapter/TmxTest.php';
require_once 'Zend/Translate/Adapter/XliffTest.php';
require_once 'Zend/Translate/Adapter/XmlTmTest.php';
require_once 'Zend/Translate/Adapter/CustomAdapterTest.php';

/**
* @category Zend
@@ -62,6 +63,7 @@ public static function suite()
$suite->addTestSuite('Zend_Translate_Adapter_TmxTest');
$suite->addTestSuite('Zend_Translate_Adapter_XliffTest');
$suite->addTestSuite('Zend_Translate_Adapter_XmlTmTest');
$suite->addTestSuite('Zend_Translate_Adapter_CustomAdapterTest');

return $suite;
}
92 changes: 92 additions & 0 deletions tests/Zend/Translate/Adapter/CustomAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Translate
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/

if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Zend_Translate_Adapter_CustomAdapterTest::main');
}

/**
* @category Zend
* @package Zend_Translate
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Translate
*/
class Zend_Translate_Adapter_CustomAdapterTest extends PHPUnit_Framework_TestCase
{
/**
* Runs the test methods of this class.
*
* @return void
*/
public static function main()
{
$suite = new PHPUnit_Framework_TestSuite("Zend_Translate_Adapter_CustomAdapterTest");
$result = PHPUnit_TextUI_TestRunner::run($suite);
}

public function setUp()
{
// Store original include_path
$this->includePath = get_include_path();
}

public function tearDown()
{
// Restore original include_path
set_include_path($this->includePath);

// Reset autoloader instance so it doesn't affect other tests
Zend_Loader_Autoloader::resetInstance();
}

public function testCreate()
{
$this->addTestIncludePath();

$translate = new Zend_Translate('My_CustomAdapter', array('test' => 'translated'), 'en');
$this->assertTrue(true);
}

public function testCreateWithZendAutoloaderEnabled()
{
$this->addTestIncludePath();

// register zend autoloader
Zend_Loader_Autoloader::getInstance();

$translate = new Zend_Translate('My_CustomAdapter', array('test' => 'translated'), 'en');
$this->assertTrue(true);
}

public function addTestIncludePath()
{
set_include_path(__DIR__ . '/_files/' . PATH_SEPARATOR . $this->includePath);
}

}

// Call Zend_Translate_Adapter_CustomAdapterTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_Translate_Adapter_CustomAdapterTest::main") {
Zend_Translate_Adapter_CustomAdapterTest::main();
}
13 changes: 13 additions & 0 deletions tests/Zend/Translate/Adapter/_files/My/CustomAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

class My_CustomAdapter extends Zend_Translate_Adapter {
protected function _loadTranslationData($data, $locale, array $options = array())
{
return array($locale => $data);
}

public function toString()
{
return "My_CustomAdapter";
}
}
2 changes: 1 addition & 1 deletion tests/Zend/Validate/BarcodeTest.php
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ public function testNoneExisting()
$barcode = new Zend_Validate_Barcode('Zend_Validate_BarcodeTest_NonExistentClassName');
$this->fail("'Zend_Validate_BarcodeTest_NonExistentClassName' is not a valid barcode type'");
} catch (Exception $e) {
$this->assertRegExp('#not found|No such file#', $e->getMessage());
$this->assertRegExp('#could not be found#', $e->getMessage());
}
}

0 comments on commit 23b93f4

Please sign in to comment.