Download the PHP package sellerlabs/injected without Composer

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

injected

Automatic mocked dependency injection for testing

What is this?

InjectedTrait allows you to easily create classes with all of their dependencies mocked out for testing purposes.

Why?

The following pattern is very common:

  1. Create a class A with its dependencies (service objects) passed in through the constructor
  2. Use these services in various functions internal to the object
  3. Create tests that mock out each of A's dependencies, asserting that they are called as expected.

A lot of the testing logic ends up being boilerplate for constructing an object. InjectedTrait aims to remove this boilerplate entirely, letting you focus on what matters: the tests themselves.

Getting Started

Use composer to get the latest release (you'll probably only need it for development):

Example Usage

Suppose we're developing a web app, and we want to email users when they sign up. For a simple example, let's assume a user is defined entirely by their email address. When they sign up, naturally we want to send them a thank you email. Furthermore, we'd like to test that the emails are really being sent without actually sending them.

First, let's define an email service:

(In a real application, email would send out an email -- we're not concerned with the implementation here, though!)

Let's also define a UserController which handles the extremely simple sign up process:

Here, we provide the EmailService dependency through the constructor, and use it during our (incredibly simple) signup process.

To test this class, we'll have to do one of two things:

  1. Actually send an email out, and make sure it was sent somehow, or
  2. Mock the EmailService object using something like Mockery and make sure that email is called with the expected arguments.

InjectedTrait allows you to painlessly achieve option 2. Let's take a look:

Every class using InjectedTrait is required to have the $className property, which is used to locate the class that is being tested. InjectedTrait provides a single public method, make, which constructs an object of this type, but mocks its dependencies out and saves them as properties to the test class itself.

So, in testSignUp, we're constructing the controller using make(), which gives us access to a mocked EmailService type object called $service. This is because it's defined that way in the UserController's constructor:

For the duration of the test case, the $service member variable is bound to this mocked EmailService, which allows us to make expectations about what happens with it when the signUp method of the controller gets called. We use Mockery in order to create the mocked objects. There are some annotations in the class comment, which help with IDE autocompletion for these classes since the mock properties are declared dynamically.

This example lives in tests/InjectedExample.php. Feel free to poke around!

The impact of this trait may seem relatively small, but when working on large applications where classes have several dependencies, this makes testing much easier.


All versions of injected with dependencies

PHP Build Version
Package Version
Requires mockery/mockery Version 0.9.*
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 sellerlabs/injected contains the following files

Loading the files please wait ....