Download the PHP package tweakers/symfony-service-mock without Composer

On this page you can find all versions of the php package tweakers/symfony-service-mock. 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 symfony-service-mock

Mockable Service proxy generator

Introduction

This library is designed to be used with Symfony's service-container and leverages Ocramius' Proxy Manager to allow you to configure an 'original' implementation of a service that can be changed to an 'alternative' implementation on-the-fly.

As of Symfony 4.0 you're not allowed to change or remove a service once it has been initialized. As such, when you need a temporary test double in a unit or functional test, you cannot simply replace the service.

This library allows you to add an alternative configuration to Symfony, which replaces the service with a special proxy that will allow you to gain complete control over the 'internals', even after Symfony has initialized the service and started using it as dependency in related services.

Installation

Just include this as a dev dependency:

How to use

Any service that is configured in Symfony can be re-configured in the test-environment's specific services.yaml. For this library to work optimally, you should reconfigure those services as a decorator.

If you have a service 'App\TestService' in your regular configuration, you can configure it like this to allow mocking its internal behavior:

With just this test-configuration, there is normally no difference in behavior. Although there may be minor changes due to the use of a proxy (see Ocramius' manual) or the fact that it was made public.

But all services that depend on the App\TestService will now use the newly configured decorating proxy. Which by default falls back to the original service for any actual work.

Therefor this configuration allows you to adjust the behavior of the TestService without having to know which service is using it or whether Symfony already initiated it. That can be done in a unit test like so:

Compatibility

This code has only been tested with Symfony 3.4, 4.1 and 4.2, although it should work with 4.0 and older versions. In Symfony 4.1 a TestContainer was introduced that gives access to private services. So it may not be necessary to define a service as public with Symfony 4.1 and higher. Symfony however does 'inline' or completely remove unused private services (even in 4.1), so tests may fail due to missing services if you define everything private. To prevent inlining, the example above creates the proxies with public=true, but it may also be necessary to redefine specific services as well.


All versions of symfony-service-mock with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
friendsofphp/proxy-manager-lts Version ^1.0.16
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 tweakers/symfony-service-mock contains the following files

Loading the files please wait ....