Download the PHP package e0ipso/drupal-unit-autoload without Composer

On this page you can find all versions of the php package e0ipso/drupal-unit-autoload. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package drupal-unit-autoload

Coverage Status Build Status Scrutinizer Code Quality

Gitter

Drupal Unit Autoload

Have you ever wanted to add PHPUnit tests to your Drupal 7 module? Well, you should. This tool aims to help you to deal with autoloading the classes that you have in your Drupal installation.

The Problem

The main problem arises when the class -or code- that you are testing depends on classes declared in other modules, or Drupal core itself.

Imagine that you are testing your Car class. That class depends on \DrupalCacheInterface (you are using a mock cache provider that has to implement that interface), and also depends on several classes from the service container module. After all you are injecting services in your Car class to be able to mock them afterwards, and that may require to have the Drupal\service_container\ available to you during tests.

Since you are doing unit testing, you may not want to bootstrap Drupal to have the database available in order to be able to check in the registry to find all those classes.

At this point you can think I will just use Composer's autoloader and define where to find those classes and namespaces. This is when you realize that Drupal allows you to install contrib modules in many locations. That makes it impossible to ship your module with the relative paths that you need.

Imagine this possibility:

It seems that if you wanted to provide the path to includes/cache.inc to make \DrupalCacheInterface available, then you would need to add a path like: ../../../../../../includes/cache.inc. But what if someone decides to install your car module in sites/all/modules/car? That path you provided in the module will not work in that situation. The correct one would be ../../../includes/cache.inc. Basically every site installation may need a different path.

The problem that this project aims to solve is to give you a way to provide a single path in your code that will work in all those scenarios.

The Solution

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):

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.

Inside the folder where you have your unit tests you will need to have a composer.json file that has:

Running composer install on that folder will download PHPUnit, Mockery -and all of the tools that you use for your tests-. Additionally it will download this project, that is what "e0ipso/drupal-unit-autoload": "0.1.*" is for.

At this point you only need is add the paths with DRUPAL_ROOT or DRUPAL_CONTRIB<modulename> in your composer file.

You have two options:

In the paths that you provide, you will be able to include two tokens: DRUPAL_ROOT and DRUPAL_CONTRIB<modulename>. Those tokens will be expanded to the real paths that they represent. This way, providing DRUPAL_CONTRIB<ctools> can end up expanding in:

The important thing to note is that your code ships with the same tokenized path for everyone, without caring about where the dependencies are installed.


All versions of drupal-unit-autoload with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package e0ipso/drupal-unit-autoload contains the following files

Loading the files please wait ....