Download the PHP package petrelli/live-statics without Composer
On this page you can find all versions of the php package petrelli/live-statics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package live-statics
About Live-Statics
The petrelli\live-statics
package provides a quick way to generate and integrate fake prototypes into our system. Mocked objects can easily be model to behave as the real ones, so you won't have to spend any time with integration tasks.
Both real and mocked data sources will live together so you will be able you to switch between them at any time by simply changing the subdomain.
A great secondary effect is that because our fake objects behave as real, a fully functional 'live static' version of your web application will be accessible to explore and click around.
Faker content can be parametrized, so your 'live statics' will change by just passing some URL parameters. This will come incredibly handy to perform visual QA, client presentations, and simply just to have a glance on how your site will behave with different types of content.
Quick demo
Let's explore a few links:
Notice the Projects list. It's just a simple loop within an Eloquent model collection.
The second link, is also a collection, but instead of Eloquent it's using our mocked models. Views and controller are the same for both URL's.
Install
- Include the package
You can run the command:
Or directly add it to your composer.json
And run composer update
.
-
If you have Package Auto-discovery (Laravel 5.5+ by default) skip to step 3, otherwise you'll have to manually add the service provider to your
config/app.php
file. - Publish configuration files and the Service Provider
Usage
Create a new mocked class, and it's interface
- Generate a new Mocked class (e.g. Project). Run the command:
This will use the configuration values inside config/live-statics.php
to generate a base mocked class Project
, plus an interface ProjectInterface
that will allow you to bind it to the real or fake implementation.
- Add binding instructions to
config/live-statics.php
Convention is the following:
This will be enough to use your interfaces to inject them properly!
If your real class is not ready yet and you just want a quick prototype, pass null
as the second element of the array.
Once you have your Mocked classes, remember to implement the interface in the real one.
Following our project example:
Using your newly created mocked elements
Let's use a controller as an example:
Here we inject ProjectInterface
to the controller. This will bind the real, or mocked implementation depending on the subdomain.
If you are not confortable injecting dependencies as formal parameters you can use Laravels app
function:
That's it!
You can change this subdomain modifying the subdomain
option inside config/live-statics.php
.
Shortcut for Eloquent models
This is a special case of a general class.
The package will provide a quick way for you to bind models, as most applications will be mainly mocking Eloquent models.
-
Generate the mocked model
- Add binding instructions to
config/live-statics.php
Notice instead of mocked_classes
, we use mocked_models
, and just pass the model's name.
The package will use path configurations for models provided on config/live-statics.php
to bind them properly.
Add a custom namespace when creating new mocked classes or models
Keep your code organized creating namespaces for your mocked elements. Folders will be generated automatically.
This can be easily done passing by a second parameter to both commands:
When creating models, the namespace specified within config/live-statics.php
will be added automatically.
Extra functionalities
Docs to be completed.
Dynamic parameters
Docs to be completed.
Namespaces and directories configuration
Docs to be completed.
Extending Faker through providers
Docs to be completed.
Creating different versions of your mocked classes
Docs to be completed.
Modifying your statics in real time through URL parameters
Docs to be completed.
Partial mocking
Docs to be completed.
License
The MIT License (MIT). Please see License File for more information.