Download the PHP package c-malet/class-test without Composer

On this page you can find all versions of the php package c-malet/class-test. 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 class-test

Class test

Current version Supported PHP version CI

PHP testing library focused on testing classes mocking all of their constructor parameters, using Prophecy.

The main objective is to make testing a class quicker by automatizing the tested class instantiation with dummy parameters, and retrieve a whole new instance for each test. Particularly useful to test classes with many objects as constructor parameters that you don't want to be executed, such as helpers, loggers, services, repositories, ...

This library is based on the PHP object mocking framework Prophecy, and requires to know how to test with it, learn more about it here

Simple example

Installation

Prerequisites

Requires PHP 8.1 or greater and PHPUnit ^9.0 || ^10.0

Composer

Run composer command composer require c-malet/class-test

Usage

Test set up

Set up the test class for the tested class as such :

Extend the ClassTestCase class (which extends the PHPUnit TestCase)

Implement the two mandatory methods defining the tested class :

Testing

For each test, a whole new instance of the tested class is created and can be retrieved :

You can override the getTestedClass method in each test case to inform your IDE the class type of $someClass

It returns a "real" instance of the tested class, it is not a mock, and the whole code of this class will be executed.

Contrariwise, every constructor parameter provided that matches an instantiatable class is transformed into a revealed Prophecy, in such a way that they will automatically handle any parameter and always return null by default.

These Prophecy mocks can be retrieved anytime during tests, to do anything you could do with Prophecy alone, using the getMock method, allowing you to override the default dummy set up as needed for your tests.

Mocks can be retrieved by their class name or by key, as described earlier in the 'Test set up' part

If your IDE fails to resolve the methods from the class name and gives warning, you can also get ProphecyMethod objects this way :

If you wish to use the internal mocks container for any other class to mock, for instance mocks you'd want to use in your tested methods, you can also create mocks and dummies that can be retrieved as other mocks with addNewMock or addNewDummy

Full example

Contributing

See the CONTRIBUTING file.

Install / update project

You can install project with the following command:

And update with the following command:

NB: For the components, the composer.lock file is not committed.

Testing & CI (Continuous Integration)

Tests

You can run unit tests (with coverage) on your side with following command:

For prettier output (but without coverage), you can use the following command:

Code Style

You also can run code style check with following commands:

You also can run code style fixes with following commands:

Static Analysis

To perform a static analyze of your code (with phpstan, lvl 9 at default), you can use the following command:

To ensure you code still compatible with current supported version at Deezer and futures versions of php, you need to run the following commands (both are required for full support):

Minimal supported version:

Maximal supported version:

CI Simulation

And the last "helper" commands, you can run before commit and push, is:


All versions of class-test with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
phpunit/phpunit Version ^9.0||^10.0
phpspec/prophecy Version ^1.0
phpspec/prophecy-phpunit Version ^2.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 c-malet/class-test contains the following files

Loading the files please wait ....