Download the PHP package pkly/phpunit-service-create-trait without Composer

On this page you can find all versions of the php package pkly/phpunit-service-create-trait. 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 phpunit-service-create-trait

PHPUnit Service Create Trait

A helper trait for PHPUnit 10+ for easier creation of services with dependencies in unit testing

Packagist Downloads

Installation

Simply run

Currently compatible only with PHPUnit 10 (11?)

Usage

In any of your PHPUnit test cases simply

Any dependencies in the constructor as well as methods marked with Symfony's #[Required] attribute will be automatically plugged in with mocks. This allows you to write complex tests without wasting time updating your construct calls each time you modify something.

Okay, but what if I need to use something custom?

Simply assign the proper parameter name in either $constructor or $required in the appropriate methods. That will use your object instead of creating one for you, keep in mind you cannot retrieve it via $this->getMockedService().

Partial objects?

Sure, works the same, just use createRealPartialMockedServiceInstance instead of createRealMockedServiceInstance, in that case you must also specify the methods to override in your mock. Returned instance is T&MockObject.

Tests? More examples?

I'll add them shortly, for now this code is being used thoroughly in a few of the projects I work at and I grew tired of updating it across multiple repositories. It's also very simple, so I doubt anyone is going to complain.

Feature requests?

Sure, hit me up with an issue if you wish.


All versions of phpunit-service-create-trait with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
phpunit/phpunit Version >=10
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 pkly/phpunit-service-create-trait contains the following files

Loading the files please wait ....