From 281c3be55a7c3a480aaf03a97a0c100d2d6f61df Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 24 Jun 2019 10:05:40 +0900 Subject: [PATCH 1/4] =?UTF-8?q?SC=5FClassAutoloader=20=E3=82=92=20Composer?= =?UTF-8?q?=20=E3=81=AE=20autoloader=20=E3=82=88=E3=82=8A=E5=84=AA?= =?UTF-8?q?=E5=85=88=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/app_initial.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); From 7da0baaf79b6779531db9e790a29e593dd81975a Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 24 Jun 2019 19:26:37 +0900 Subject: [PATCH 2/4] =?UTF-8?q?SC=5FProduct=20=E3=82=92=E6=8B=A1=E5=BC=B5?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class/plugin/LoadClassFileChangeTest.php | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 tests/class/plugin/LoadClassFileChangeTest.php diff --git a/tests/class/plugin/LoadClassFileChangeTest.php b/tests/class/plugin/LoadClassFileChangeTest.php new file mode 100644 index 0000000000..37f5c058cb --- /dev/null +++ b/tests/class/plugin/LoadClassFileChangeTest.php @@ -0,0 +1,130 @@ +createPlugin(); + } + + 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); + } +} From 023818bde96863eb2c91af0b8580f3c42d6191c8 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 24 Jun 2019 21:02:02 +0900 Subject: [PATCH 3/4] =?UTF-8?q?classloader=20=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E5=88=86=E5=89=B2=E3=81=97=E3=81=A6=E5=AE=9F?= =?UTF-8?q?=E8=A1=8C=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 5 +++-- appveyor.yml | 3 ++- tests/class/plugin/LoadClassFileChangeTest.php | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) 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..d7f32761a6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -85,4 +85,5 @@ before_test: - bash eccube_install.sh mysql test_script: - - data/vendor/bin/phpunit + - data/vendor/bin/phpunit --exclude-group classloader + - data/vendor/bin/phpunit --group classloader diff --git a/tests/class/plugin/LoadClassFileChangeTest.php b/tests/class/plugin/LoadClassFileChangeTest.php index 37f5c058cb..db88a77791 100644 --- a/tests/class/plugin/LoadClassFileChangeTest.php +++ b/tests/class/plugin/LoadClassFileChangeTest.php @@ -1,5 +1,8 @@ Date: Mon, 24 Jun 2019 21:17:37 +0900 Subject: [PATCH 4/4] =?UTF-8?q?PHP7.2=E6=9C=AA=E6=BA=80=E3=81=AE=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AF=20SC=5FHelper=5FPlugin::load()=20=E3=82=92?= =?UTF-8?q?=E5=AE=9F=E8=A1=8C=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appveyor.yml | 3 +-- tests/class/plugin/LoadClassFileChangeTest.php | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d7f32761a6..ea33de88b7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -83,7 +83,6 @@ build: off before_test: - bash eccube_install.sh mysql - + test_script: - data/vendor/bin/phpunit --exclude-group classloader - - data/vendor/bin/phpunit --group classloader diff --git a/tests/class/plugin/LoadClassFileChangeTest.php b/tests/class/plugin/LoadClassFileChangeTest.php index db88a77791..803d81bcbd 100644 --- a/tests/class/plugin/LoadClassFileChangeTest.php +++ b/tests/class/plugin/LoadClassFileChangeTest.php @@ -9,6 +9,10 @@ protected function setUp() { parent::setUp(); $this->createPlugin(); + if (PHP_VERSION_ID < 70200) { + $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance(); + $objPlugin->load(); + } } protected function tearDown()