From 245b98c0f6c8d9142080841de2c87f6bf5ed8710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateu=20Aguil=C3=B3=20Bosch?= Date: Fri, 3 Jul 2015 09:32:03 +0200 Subject: [PATCH 1/5] Easier autoloader inclusion --- autoload.php | 9 +++++++++ drupal_unit_autoloader.php | 7 ------- 2 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 autoload.php delete mode 100644 drupal_unit_autoloader.php diff --git a/autoload.php b/autoload.php new file mode 100644 index 0000000..874c944 --- /dev/null +++ b/autoload.php @@ -0,0 +1,9 @@ +register(); diff --git a/drupal_unit_autoloader.php b/drupal_unit_autoloader.php deleted file mode 100644 index 179a4c6..0000000 --- a/drupal_unit_autoloader.php +++ /dev/null @@ -1,7 +0,0 @@ - Date: Fri, 3 Jul 2015 13:03:47 +0200 Subject: [PATCH 2/5] Create AutoloaderBootstrapInterface --- src/AutoloaderBootstrap.php | 20 +++++++------ src/AutoloaderBootstrapInterface.php | 42 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/AutoloaderBootstrapInterface.php diff --git a/src/AutoloaderBootstrap.php b/src/AutoloaderBootstrap.php index 8ce4b3f..910565d 100644 --- a/src/AutoloaderBootstrap.php +++ b/src/AutoloaderBootstrap.php @@ -14,7 +14,7 @@ * * @package Drupal\Composer\ClassLoader */ -class AutoloaderBootstrap { +class AutoloaderBootstrap implements AutoloaderBootstrapInterface { const AUTOLOAD_METHOD = 'autoload'; const COMPOSER_CONFIGURATION_NAME = 'composer.json'; @@ -67,7 +67,7 @@ public function __construct(\Composer\Autoload\ClassLoader $classLoader, $seed = } /** - * Register the autoloader if it is not registered. + * {@inheritdoc} */ public function register() { if ($this->checkLoadedAutoloader()) { @@ -132,9 +132,7 @@ protected function registerPsr(array $composer_config) { } /** - * Checks if the autoloader has been added. - * - * @return bool + * {@inheritdoc} */ public function checkLoadedAutoloader() { $functions = spl_autoload_functions(); @@ -142,10 +140,7 @@ public function checkLoadedAutoloader() { } /** - * Gets the configuration for the drupal loader from the Composer loader. - * - * @return array - * The configuration array for the drupal loader. + * {@inheritdoc} */ public function getConfig() { // Initialize empty configuration. @@ -196,4 +191,11 @@ public function getConfig() { return $config; } + /** + * {@inheritdoc} + */ + public function getClassLoader() { + return $this->classLoader; + } + } diff --git a/src/AutoloaderBootstrapInterface.php b/src/AutoloaderBootstrapInterface.php new file mode 100644 index 0000000..daface0 --- /dev/null +++ b/src/AutoloaderBootstrapInterface.php @@ -0,0 +1,42 @@ + Date: Fri, 3 Jul 2015 13:04:33 +0200 Subject: [PATCH 3/5] Test getter --- tests/src/AutoloaderBootstrapTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/src/AutoloaderBootstrapTest.php b/tests/src/AutoloaderBootstrapTest.php index 9bd0704..b10d5be 100644 --- a/tests/src/AutoloaderBootstrapTest.php +++ b/tests/src/AutoloaderBootstrapTest.php @@ -182,4 +182,15 @@ public function test_getConfig() { $this->assertEquals($expected, $config); } + /** + * Tests the ::getClassLoader method. + * + * @covers ::getClassLoader() + */ + public function test_getClassLoader() { + $loader = m::mock('\Composer\Autoload\ClassLoader'); + $autoloader = new AutoloaderBootstrap($loader, 'data/docroot/sites/all/modules/testmodule/composer.json'); + $this->assertEquals($loader, $autoloader->getClassLoader()); + } + } From 4cdbd3db19924dfea4baa3280919c1201104e96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateu=20Aguil=C3=B3=20Bosch?= Date: Fri, 3 Jul 2015 13:08:38 +0200 Subject: [PATCH 4/5] Improve the README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1174ccb..30912dc 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,13 @@ The problem that this project aims to solve is to give you a way to provide a si all those scenarios. ## The Solution -Meet the Drupal Unit Autoload. +Meet the Drupal Unit Autoload. To include it, just add the following to your PHPUnit test class: + +```php +require_once __DIR__ . '/../../vendor/mateu-aguilo-bosch/drupal-unit-autoload/autoload.php'; +``` + +That will load Composer's autoloader + the Drupal capabilities. The only thing that you need to do is add a new `composer.json` key with tokens in the path. From 40aed2c42361280be97b04e69723807f82fb8311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateu=20Aguil=C3=B3=20Bosch?= Date: Fri, 3 Jul 2015 13:11:03 +0200 Subject: [PATCH 5/5] Moar docs --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 30912dc..9f97d02 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,8 @@ The problem that this project aims to solve is to give you a way to provide a si all those scenarios. ## The Solution -Meet the Drupal Unit Autoload. To include it, just add the following to your PHPUnit test class: +Meet the Drupal Unit Autoload. To include it, just add the following to your PHPUnit test class (change the path +depending on the location of your test classes): ```php require_once __DIR__ . '/../../vendor/mateu-aguilo-bosch/drupal-unit-autoload/autoload.php';