Download the PHP package sytzez/data-object-tester without Composer

On this page you can find all versions of the php package sytzez/data-object-tester. 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 data-object-tester

PHPUnit PHPStan

Data Object Tester

Should you even unit test your data object classes? With DataObjectTester it's so effortless that you don't even need to ask yourself that question! It automates doing automated tests in PHPUnit for immutable data objects. Within a minute, you'll have written a test that covers all possible cases. Check out the code below to see how it works.

Requirements

Installation

`

Usage

Consider the following data class:

To make sure the getter methods always return the given values, all you need to do is write a test that extends the DataObjectTestCase:

(Alternatively to extending the DataObjectTestCase, you could also use TestsDataObjects)

This will test that all the getters exist, and that they give back the values provided in the constructor.

The array in the class expectation lists the getters, in the same order as their respective constructor arguments. For each property, any number of possible values can be given. The tester will construct a couple of objects using those values, and assert that the getters return the right values.

Features

Testing optional arguments

If an argument can be optional (having a default value), you can use a DefaultPropertyCase to define the default expected value.

Testing validation exceptions

If passing certain values should cause an error or exception to be thrown during instantiation, use the ConstructorExceptionPropertyCase. So if your constructor looks like this:

You can test it like this:

If multiple arguments should cause an exception, the test will assert that one the possible exceptions will be thrown.

Testing transformative properties

If your data class alters the passed in values in some way, you can use the TransformativePropertyCase class in your class expectation.

Let's say your getter looks like this:

Then you could write the class expectation like this:

Testing with closures

You can use the ClosurePropertyCase to do your own validation of getter output by writing a closure returning a bool. Example:

Test case generator

By default, a minimal amount of objects is created, covering each specified property value at least once. But if you wish to cover every possible combination of property values, you can use a MaximalCaseGenerator, by passing it as the second argument to testDataObjects, like so:

In this case, 12 (2 3 2) objects will be instantiated and tested, instead of the minimum of 3 cases.

You can cap the number of objects by providing an argument to the generator, e.g. new MaximalCaseGenerator(20). The default cap is 100.

You can also provide your own case generators by implementing the CaseGeneratorStrategy.

Special cases

If there is a case not (yet) covered by the package, you can of course still add your own @test methods to the test case.

Code Quality

Unit tests

The project has a testing coverage of 100% of lines using PHPUnit.

PHPStan

PHPstan reports 0 errors on the maximum level 8.

License

The MIT License (MIT). Please see License File for more information.


All versions of data-object-tester with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
phpunit/phpunit Version ^9.5
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 sytzez/data-object-tester contains the following files

Loading the files please wait ...