diff --git a/.travis.yml b/.travis.yml index 5b2901df81..18b0af82b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,8 +72,9 @@ before_script: script: - mkdir -p reports/coverage - - if [ ! $COVERAGE ] ; then php data/vendor/bin/phpunit -c phpunit.xml.dist ; fi - - if [ $COVERAGE ] ; then phpdbg -qrr data/vendor/bin/phpunit -c phpunit.xml.dist ; fi + - if [ ! $COVERAGE ] ; then php data/vendor/bin/phpunit -c phpunit.xml.dist --exclude-group classloader ; fi + - if [ ! $COVERAGE ] ; then php data/vendor/bin/phpunit -c phpunit.xml.dist --group classloader ; fi + - if [ $COVERAGE ] ; then phpdbg -qrr data/vendor/bin/phpunit -c phpunit.xml.dist --exclude-group classloader ; fi - if [ ! $COVERAGE ] ; then php data/vendor/bin/codecept run --env chrome --steps ; fi after_script: diff --git a/appveyor.yml b/appveyor.yml index 104f7b18c8..ea33de88b7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -83,6 +83,6 @@ build: off before_test: - bash eccube_install.sh mysql - + test_script: - - data/vendor/bin/phpunit + - data/vendor/bin/phpunit --exclude-group classloader diff --git a/data/app_initial.php b/data/app_initial.php index 926e1fd63c..4cce0ee473 100644 --- a/data/app_initial.php +++ b/data/app_initial.php @@ -47,7 +47,7 @@ // クラスのオートローディングを定義する require_once(CLASS_EX_REALDIR . 'SC_ClassAutoloader_Ex.php'); -spl_autoload_register(array('SC_ClassAutoloader_Ex', 'autoload')); +spl_autoload_register(array('SC_ClassAutoloader_Ex', 'autoload'), true, true); SC_Helper_HandleError_Ex::load(); diff --git a/tests/class/plugin/LoadClassFileChangeTest.php b/tests/class/plugin/LoadClassFileChangeTest.php new file mode 100644 index 0000000000..803d81bcbd --- /dev/null +++ b/tests/class/plugin/LoadClassFileChangeTest.php @@ -0,0 +1,137 @@ +createPlugin(); + if (PHP_VERSION_ID < 70200) { + $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance(); + $objPlugin->load(); + } + } + + protected function tearDown() + { + $plugins = ['AutoloadingPlugin']; + foreach ($plugins as $plugin) { + $dir = PLUGIN_UPLOAD_REALDIR.$plugin; + if (!file_exists($dir)) break; + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($files as $file) { + /** @var SplFileInfo $file */ + $file->isDir() ? rmdir($file->getPathname()) : unlink($file->getRealPath()); + } + rmdir($dir); + } + parent::tearDown(); + } + + /** + * loadClassFileChange で拡張したクラスのテストケース. + */ + public function testLoadExtendedClass() + { + $objProduct = new SC_Product_Ex(); + $this->assertTrue(constant('SC_Product_Ex::AUTOLOAD'), 'loadClassFileChange で拡張したクラス定数にアクセスできる'); + + $refclass = new ReflectionClass($objProduct); + $this->assertTrue($refclass->hasProperty('autoloaded'), 'loadClassFileChange で拡張したプロパティが存在する'); + + $refProp = $refclass->getProperty('autoloaded'); + $this->assertTrue($refProp->getValue($objProduct), 'loadClassFileChange で拡張したプロパティにアクセスできる'); + + $this->assertTrue($refclass->hasMethod('isExtended'), 'loadClassFileChange で拡張したメソッドが存在する'); + $refMethod = $refclass->getMethod('isExtended'); + $this->assertTrue($refMethod->invoke($objProduct), 'loadClassFileChange で拡張したメソッドにアクセスできる'); + } + + /** + * ダミーのプラグインをインストールする. + */ + private function createPlugin() + { + $realdir = PLUGIN_UPLOAD_REALDIR; + $plugin_info = <<< __EOS__ + $plugin_info, + 'AutoloadingPlugin' => $autoloadingPlugin, + 'Autoloading_SC_Product' => $Autoloading_SC_Product + ]; + + $dir = PLUGIN_UPLOAD_REALDIR.'AutoloadingPlugin'; + if (!file_exists($dir)) { + mkdir($dir); + } + foreach ($files as $name => $content) { + file_put_contents($dir.'/'.$name.'.php', $content); + } + + $plugin_id = $this->objQuery->nextVal('dtb_plugin_plugin_id'); + $pluginValues = [ + 'plugin_id' => $plugin_id, + 'plugin_name' => 'AutoloadingPlugin', + 'plugin_code' => 'AutoloadingPlugin', + 'class_name' => 'AutoloadingPlugin', + 'plugin_version' => '0.0.0', + 'compliant_version' => '2.17', + 'enable' => 1, + 'create_date' => 'CURRENT_TIMESTAMP', + 'update_date' => 'CURRENT_TIMESTAMP' + ]; + $this->objQuery->insert('dtb_plugin', $pluginValues); + + $plugin_hookpoint_id = $this->objQuery->nextVal('dtb_plugin_hookpoint_plugin_hookpoint_id'); + $hookpointValues = [ + 'plugin_hookpoint_id' => $plugin_hookpoint_id, + 'plugin_id' => $plugin_id, + 'hook_point' => 'loadClassFileChange', + 'callback' => 'loadClassFileChange', + 'update_date' => 'CURRENT_TIMESTAMP' + ]; + $this->objQuery->insert('dtb_plugin_hookpoint', $hookpointValues); + } +}