PHPackages                             petrelli/live-statics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. petrelli/live-statics

ActiveLibrary[Testing &amp; Quality](/categories/testing)

petrelli/live-statics
=====================

Rapid development aid package that facilitates data modelling and dynamic integration with views

v0.0.3-alpha(6y ago)01321MITPHPPHP ^7.1CI failing

Since Jan 30Pushed 5y ago2 watchersCompare

[ Source](https://github.com/ferpetrelli/live-statics)[ Packagist](https://packagist.org/packages/petrelli/live-statics)[ RSS](/packages/petrelli-live-statics/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (3)Dependencies (4)Versions (6)Used By (1)

About Live-Statics
==================

[](#about-live-statics)

[![Build Status](https://camo.githubusercontent.com/97b00937fe3fb23ba6639ac7a9630159b9f8a2131a78c3918a6f6e9c35c286bb/68747470733a2f2f7472617669732d63692e6f72672f66657270657472656c6c692f6c6976652d737461746963732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ferpetrelli/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
==========

[](#quick-demo)

Let's explore a few links:

1. [Open](http://fernandopetrelli.com). A real personal website.
2. [Open](http://static.fernandopetrelli.com). Same URL with a `static` subdomain.

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
=======

[](#install)

1. Include the package

You can run the command:

```
composer require petrelli/live-statics
```

Or directly add it to your composer.json

```
"petrelli/live-statics": "^0.0.1"
```

And run `composer update`.

2. 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.

```
'providers' => [
    //...
    Petrelli\LiveStatics\BaseServiceProvider::class,
    //...
]
```

3. Publish configuration files and the Service Provider

```
php artisan vendor:publish --provider="Petrelli\LiveStatics\BaseServiceProvider"

```

Usage
=====

[](#usage)

Create a new mocked class, and it's interface
---------------------------------------------

[](#create-a-new-mocked-class-and-its-interface)

1. Generate a new Mocked class (e.g. Project). Run the command:

```
php artisan live-statics:class Project
```

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.

2. Add binding instructions to `config/live-statics.php`

```
'mocked_classes' => [
    \App\Interfaces\ProjectInterface::class => [
        \App\Mocks\ProjectMock::class, \App\Project::class
    ],
],
```

Convention is the following:

```
'mocked_classes' => [
    INTERFACE1 => [ MOCKED_CLASS1, REAL_CLASS1 ],
    //...
    INTERFACEn => [ MOCKED_CLASSn, REAL_CLASSn ],
]

```

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.

```
'mocked_classes' => [
    INTERFACE1 => [ MOCKED_CLASS1, null ],
    //...
]

```

Once you have your Mocked classes, remember to implement the interface in the real one.
---------------------------------------------------------------------------------------

[](#once-you-have-your-mocked-classes-remember-to-implement-the-interface-in-the-real-one)

Following our project example:

```
use App\Interfaces\ProjectInterface;

class Project extends Model implements ProjectInterface
{
    #...
}
```

Using your newly created mocked elements
----------------------------------------

[](#using-your-newly-created-mocked-elements)

Let's use a controller as an example:

```
use \App\Interfaces\ProjectInterface;

class Controller extends BaseController
{
    public function index(ProjectInterface $model)
    {
        # Use your Project instance as normal
        # $model->all();
        # $model->published()->get();
    }
}
```

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:

```
use \App\Interfaces\ProjectInterface;

class Controller extends BaseController
{
    public function index()
    {
        $model = app(ProjectInterface:class);

        # Use your Project instance as normal
        # $model->all();
        # $model->published()->get();
    }
}
```

That's it!

You can change this subdomain modifying the `subdomain` option inside `config/live-statics.php`.

Shortcut for Eloquent models
----------------------------

[](#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.

1. Generate the mocked model

```
php artisan live-statics:model Project
```

2. Add binding instructions to `config/live-statics.php`

```
'mocked_models' => [
    'Project',
]
```

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
-----------------------------------------------------------------

[](#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:

```
# Prepend Api to the new class namespace
php artisan live-statics:class Project Api

# Prepend Api\Version1 to the new class namespace
php artisan live-statics:class Project Api\\Version1 #or
php artisan live-statics:class Project Api/Version1

# Prepend Api to the new model namespace
php artisan live-statics:model Project Api

# Prepend Api\Version1 to the new model namespace
php artisan live-statics:model Project Api\\Version1 #or
php artisan live-statics:model Project Api/Version1
```

When creating models, the namespace specified within `config/live-statics.php` will be added automatically.

Extra functionalities
=====================

[](#extra-functionalities)

Docs to be completed.

Dynamic parameters
------------------

[](#dynamic-parameters)

Docs to be completed.

Namespaces and directories configuration
----------------------------------------

[](#namespaces-and-directories-configuration)

Docs to be completed.

Extending Faker through providers
---------------------------------

[](#extending-faker-through-providers)

Docs to be completed.

Creating different versions of your mocked classes
--------------------------------------------------

[](#creating-different-versions-of-your-mocked-classes)

Docs to be completed.

Modifying your statics in real time through URL parameters
----------------------------------------------------------

[](#modifying-your-statics-in-real-time-through-url-parameters)

Docs to be completed.

Partial mocking
---------------

[](#partial-mocking)

Docs to be completed.

License
=======

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~222 days

Total

3

Last Release

2218d ago

PHP version history (2 changes)v0.0.1-alphaPHP ^7.0

v0.0.3-alphaPHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4fc70d39bb6fe2c649062145018204aba8004821722ec6699cb456c18f4db005?d=identicon)[petrelli](/maintainers/petrelli)

---

Top Contributors

[![ferpetrelli](https://avatars.githubusercontent.com/u/421480?v=4)](https://github.com/ferpetrelli "ferpetrelli (34 commits)")

---

Tags

composerinjectionlaravelpackagephpstaticsinjectiondatamockcontrollerservicesstatics

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/petrelli-live-statics/health.svg)

```
[![Health](https://phpackages.com/badges/petrelli-live-statics/health.svg)](https://phpackages.com/packages/petrelli-live-statics)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[nelmio/alice

Expressive fixtures generator

2.5k43.4M133](/packages/nelmio-alice)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33412.5M350](/packages/brain-monkey)[php-http/mock-client

Mock HTTP client

719.7M781](/packages/php-http-mock-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
