<?php // Register the Sonata autoloader // Add additional directories for autoloading via 'extend' require_once dirname(__FILE__) . '/../lib/vendor/sonata-framework/src/Autoloader.class.php'; Sonata_Autoloader::register(); Sonata_Autoloader::extend(array(dirname(__FILE__) . '/../lib')); // Bootstap all vendor libraries require_once dirname(__FILE__) . '/../lib/vendor/sf_yaml/lib/sfYaml.php'; require_once dirname(__FILE__) . '/../lib/vendor/sf_container/lib/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); // Custom bootstapping goes here ...
fclose($fh); $fh = fopen(dirname(__FILE__) . '/../../src/Pass.class.php', 'wb'); fputs($fh, '<?php class Sonata_Pass {} ?>'); fclose($fh); mkdir(dirname(__FILE__) . '/../../src/Pass'); $fh = fopen(dirname(__FILE__) . '/../../src/Pass/Nested.class.php', 'wb'); fputs($fh, '<?php class Sonata_Pass_Nested {} ?>'); fclose($fh); $fh = fopen(dirname(__FILE__) . '/../../src/Fail.php', 'wb'); fputs($fh, '<?php class Sonata_Fail {} ?>'); fclose($fh); $fh = fopen(dirname(__FILE__) . '/../fixtures/Extra.class.php', 'wb'); fputs($fh, '<?php class Extra {} ?>'); fclose($fh); // @Before $autoloader = new Sonata_Autoloader(); // @AfterAll unlink(dirname(__FILE__) . '/../../src/Foo.class.php'); unlink(dirname(__FILE__) . '/../../src/Pass.class.php'); unlink(dirname(__FILE__) . '/../../src/Pass/Nested.class.php'); rmdir(dirname(__FILE__) . '/../../src/Pass'); unlink(dirname(__FILE__) . '/../../src/Fail.php'); unlink(dirname(__FILE__) . '/../fixtures/Extra.class.php'); // @Test: ->autoload() loads class files by class name $t->is($autoloader->autoload('Sonata_Pass'), true, 'Returns true if a class can be loaded'); $t->is($autoloader->autoload('Sonata_Pass_Nested'), true, 'Still works for more nested classes'); $t->is($autoloader->autoload('Sonata_Fail'), false, 'Returns false if the class filename does not end with \'.class.php\''); $t->is($autoloader->autoload('Foo'), false, 'Returns false if the class name does not start with \'Sonata\''); $t->is($autoloader->autoload('Sonata_Not_Here'), false, 'Returns false for non-existing classes'); // @Test: ::extend() registers extra directories for autoloading $t->is($autoloader->autoload('Extra'), false, 'The \'Extra\' class cannot be autoloaded because its path isn\'t registered for autoloading');
public static function extend(array $extraDirs) { self::$extraDirs = $extraDirs; }