Download the PHP package tonybogdanov/mockable-annotations without Composer

On this page you can find all versions of the php package tonybogdanov/mockable-annotations. 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 mockable-annotations

build coverage

Introduction

Doctrine Annotations are a powerful tool that allows specifying all sorts of meta information for classes, methods and properties, in a clean, semantic & predictable way.

One feature lacking in the default annotation readers is mock-ability, or the ability to inject annotations at runtime.\ This can be particularly useful when the annotated classes are part of a third party library that you have no control over. The default strategy in this case would be to extend or override the entire class, but that is not always possible and is definitely not maintainable.

This package introduces a mock-able annotation reader, with support for various ways of "instructing" it how to read annotations. It supports overriding and merging class, method and property level annotations, and also exposes a lot of interfaces for you to introduce your own functionality.

It works as a wrapper to an annotation reader instance of your choice, so you can still benefit from its features (such as caching for example) with minimal effort.

Installation

* By default the reader has dependency only on the doctrine/annotations package, so if you intend to use Doctrine's cached reader, make sure to also add doctrine/cache to your dependencies.

Providers

The included MockableAnnotationReader mocks annotations using annotation providers for class, method and property level annotations respectively. Use any of the [clear|get|set|add][Class|Method|Property]MockProvider(s) methods to register your providers. The methods expect instances of the respective interfaces, so you can even build your own provider if required.

The package comes with 3 default providers: ClassMockProvider, MethodMockProvider and PropertyMockProvider with support for override and merge strategies, optional filtering and priority (higher priority values are executed later).

Examples

The following class definition:

Can have its class annotations mocked, so that the reader actually sees this:

With the following example code:

Here we are using the OverrideStrategy, which ignores the original annotations and replaces them with the custom ones passed to the ClassMockProvider. You can also use a MergeStrategy, which will merge the original annotations with the new ones instead. You can of course implement and pass your own strategy.

Additionally we are using a ClassNameFilter, so that the provider will only be applied if the class being read is an instance of TestClass.

* If you need the filter to check if the class being read is exactly an instance of TestClass and not an instance of a class extending TestClass, you can pass true as a second argument to the ClassNameFilter filter.

Mocking methods and properties follows the same principles with a very similar API.\ Take a look at the source for reference.

Convenience Methods

Registering providers can be quite a verbose task, so for most common scenarios the reader exposes a couple of convenience methods instead.

Mocking & Inheritance

Doctrine annotations are not inheritable by design. Meaning that if you have class A extending class B, and you define some class level annotations on B, retrieving annotations for A will not include them.

* Keep in mind that the above is only true for annotations. Methods and properties of parent classes are still visible and their annotations will be inspected in child classes.

The above, reflecting onto mocking, means that you would (in theory) need to separately mock both child and parent classes, since the reader will traverse them individually.

The MockableReader can help alleviate this problem by respecting inheritance to some degree. When you mock class B, all class level annotations will be applied (unless the strict flag is set to TRUE on the ClassNameFilter) when the reader inspects any class that inherits from B, even if you did not explicitly mock it.

If you did explicitly mock it, then the inherited annotations will be ignored.


All versions of mockable-annotations with dependencies

PHP Build Version
Package Version
Requires doctrine/annotations Version ^1.10
php-64bit Version ^7.3
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 tonybogdanov/mockable-annotations contains the following files

Loading the files please wait ....