Download the PHP package crimsonkissaki/mockmaker without Composer

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

MockMaker

An automated entity class "mock" file seeder.

Whether you call them doubles, stubs, mocks, partials, fakes, or something else there are times when a mocking library such as PHPUnit's mockBuilder, Mockery, Prophecy, etc. just doesn't do exactly what you need or want. Sometimes you just need a concrete class implementation to run through the unit test wringer or a full end to end functional unit test suite.

MockMaker aims to simplify the process of generating concrete fake object with a particular emphasis on ORM entities (because that's the original problem I wrote this library so solve).

Why use MockMaker:

Let's face it, if you've ever inherited a large code base with a couple dozen entity classes that need to quickly be set up for use in unit/functional tests you know how big of a PITA standing those up can be. Jumping back and forth between files, keeping the properties, methods, and entity relationships straight while manually writing up the code to generate those mocks is horribly time consuming. If those entities have non-public properties it makes dynamic data setting annoying as hell. Toss in some heavy association mapping and a few many-to-one relationships that circle around each other and it's enough to make you need a stiff drink.

So, if you are:

MockMaker might be able to lend you a hand.

What MockMaker does:

At its core, MockMaker takes a list of files and/or directories and generates mock 'seeder' files for any instantiable classes. Those mock files can be used to generate on-the-fly instantiations of entity classes for use in testing. Interfaces and Abstracts need not apply.

Flexible and extendable, the seed code can be altered to suit your particular project with relative ease, so after the initial setup you can re-run MockMaker for any new entities that get added in, or existing entities that change with little to no fuss. What's more, once MockMaker has made your files it's done. You don't have to include it in your code base and can use the generated files like any other project class.

Please be aware, I consider MockMaker to be in Beta stage. There is still some functionality that is not completely working, but I needed to get this up and available for testing with pulling into Composer.

Installation:

Through Composer:

NOTE You will have to update your composer.json file with a repository entry for this github repo as I have not yet uploaded the repo to packagist. I will do so when I'm happy that it will work on most use-cases.

MockMaker Configuration & Usage:

I've tried to include enough configuration options to cover a good majority of use cases.

MockMaker is configured through human-readable settings that should make sense to just about everyone. Hopefully.

MockMaker supports method chaining, so virtually all of them can be stacked up. Exceptions to this are the verifySettings(), testRegexPatterns(), and createMocks() methods since they are for returning actual results based on configuration settings.

Create a new MockMaker instance.

Define files you want mocked.

Have MockMaker parse directories and find .php files for you.

Tell MockMaker to recursively check through the read directories for files.

The default setting is false

Tell MockMaker where your project's root path is.

MockMaker tries to auto-detect this, so you only have to set it if that's failing.

Have MockMaker create & save the mock files for you.

If there is no directory specified here, the mock code will be returned as a string you can copy/paste/stdout from wherever you dump it.

Have MockMaker create unit tests for the mock files.

Unit tests are very basic and only make sure the mocks return valid instances of the entity class

Have MockMaker save the mock files for you.

If there is no directory specified here, the mock code will be returned as a string you can copy/paste/stdout from wherever you dump it.

By default, MockMaker will replicate the directory structure of the read directories you specify as it's saving files, if it's reading through them recursively.

If you'd rather they get lumped together into one directory, use this.

By default MockMaker will not overwrite existing files if you've told it to re-mock something that's already been done. (This is to prevent accidentally overwriting files that have already been customized with defaults and losing your work.)

By using this option you avow you're a responsible developer and understand what 'overwrite' means and what its consequences are.

By default MockMaker will not overwrite existing unit tests if you've told it to re-mock something that's already been done. (This is to prevent accidentally overwriting files that have already been customized and losing your work.)

By using this option you avow you're a responsible developer and understand what 'overwrite' means and what its consequences are.

Define a regex pattern used to exclude files from being processed. (default allow)

This will override any files included through includeFilesWithFormat().

This will be applied to any files obtained through mockTheseEntities() or mockEntitiesInDirectory().

Define a regex pattern used to include files from being processed. (default deny)

This will be applied to any files obtained through mockTheseEntities() or mockEntitiesInDirectory().

If you don't want the default mock name format of {FileName}Mock, then you can specify a new format here. If you want the file/class name in the string just put %FileName% somewhere in there.

e.g. If you want MockedMyEntity to be the class name, use 'Mocked%FileName%'

MockMaker will make a good effort at determining a proper class namespace for the mock classes it generates, but that depends on having access to Composer.

If the automatic namespaces are not right, you can specify a 'base namespace' here.

If you're recursively reading files from a directory with sub-directories, MockMaker should be able to adjust the namespace accordingly.

If you don't use PSR-4 or PSR-0 namespaces, you're gonna have a bad time.

Returns an object with the results of your MockMaker configuration settings.

This is good for checking things out before you actually have MockMaker write stuff.

Returns an associative array of files that are filtered out by your regex patterns.

$results = array( 'include' => [], 'exclude' => [], 'workable' => [] );

Generate the mock file code, and either return it or write it to files.

Use Case Examples:

MockMaker is set up in such a way that options can be added in any order, so don't worry about where in the stack it ends up.

Mock single file and return code as string:

Mock everything excluding Doctrine's "{EntityName}Repository" classes:

Mock File Usage:

Setting Defaults:

You do have to do SOME work, but at least it's kept to a minimum. By default, MockMaker will set up a 'best guess' array of defaults for any entity properties, regardless of visibility (constant/public/private/protected/static).

If a default value is typehinted in the setter, assigned in a __construct(), or set in-line in the class property declaration, it is included automatically. Change or add the default value as appropriate.

This setup allows for special cases of entities that have conditional properties (e.g. a customer entity with a 'disabledOn' property) that, if defined, will influence business logic. Properties that are omitted/deleted from this array will not be used when setting up a mock unless you specifically tell it to. And if for some reason you don't want one of the default properties to be set, that option is covered later on.

'Basic' Mocks:

When store-brand generic is all you need.

If you just need an object with pre-populated default values using the minimum required properties for viability:

The mock file returns an instance of the class with only the properties defined in the array having your predefined default values. Properties NOT in the array will be ignored.

'Advanced' Mocks:

Because off-the-rack doesn't fit quite right.

This is especially useful for run-time customization of entity values so you can use PHPUnit data providers, factories, or random data generators to create as many customized entity instances as your tests require.

If you need to override a default value for particular propert(y|ies), or include a property that is omitted from the defaults array:

When the mock is returned, the 'propertyName' property in the array will be set to 'desiredValue'. If no value is set then the property will automatically be set to NULL.

But, what if you have a value in the default array because it's one of those things that is usually-needed-but-just-not-right-now-dangit? We've got you covered.

When the mock is returned, any properties defined in the $ignore array will be ... ignored. Even if they're in the defaults array or passed in with the $properties array, nothing will happen to them.

Known Bugs & Issues

Future Improvements:


All versions of mockmaker with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.3
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 crimsonkissaki/mockmaker contains the following files

Loading the files please wait ....