• Stars
    star
    573
  • Rank 75,384 (Top 2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 3 years ago
  • Updated 25 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Enlighten your APIs with auto-generated documentation

Enlighten for Laravel

Latest Stable Version Total Downloads License

A seamless package to document your Laravel APIs.

There is no need to add endless docblocks to each API method, maintain dozens of readme files, or write extensive wikis to keep your APIs documented and in sync with your codebase!

Enlighten your Laravel applications with a beautiful documentation generated automatically from your test suites, by doing so, your documentation will always be updated with the current version of your app.

If you have already invested a lot of time developing and testing your API you don't need to spend the same amount of time documenting it, we'll do that for you, you deserve it!

Compatibility

Enlighten is compatible with Laravel 7.28 onwards and requires PHP from version 7.3.

You can be a part of this project:

Introducing Laravel Enlighten

Enlighten preview

After installing the component, run php artisan enlighten and that's it! You'll find the entire API documentation in the following URL: /enlighten/

Usage

After finishing the installation process, run your Laravel tests with the following command:

php artisan enlighten

You can pass any option you'd normally pass to php artisan test including the --parallel option available in Laravel 8 onwards!

Now visit /enlighten/ to navigate the documentation.

Run php artisan enlighten:export to export the documentation as static files!

Demo project

Follow our 3min installation guide to see Enlighten in action in your own app (you don't need to modify your tests!)

Alternatively, install our demo project following the instructions in its README.

Installation

Installing Enlighten requires only 3 steps!

Step 1: Composer Require

Require the package with Composer as a dev dependency:

composer require styde/enlighten --dev

If you are NOT using the Laravel package auto-discovery feature, please add the following service-provider to config/app.php

[
    'providers' => [
        // ...
        Styde\Enlighten\Providers\EnlightenServiceProvider::class,
    ]
];

Step 2: Install Enlighten

Run php artisan enlighten:install to install and setup Enlighten automatically, otherwise follow the instructions in the Manual Setup Section.

Step 3: Database Setup

Create and configure a database for Enlighten following the instructions below:

Enlighten needs its own database and database connection to record and preserve the documentation generated from your test suites.

If you use the following convention:

  • A non-sqlite default database for your local enviroment (i.e. my_db)
  • A non-sqlite database for your test enviroment with the _test or _tests suffix (i.e. my_db_tests)

Just add a new database using the same name of your default database with the _enlighten suffix, for example:

# .env
# If your local database is:
DB_NAME=my_default_database
#
# phpunit.xml
# And your test database is:
# <env name="DB_DATABASE" value="my_default_database_tests"/>
#
# Then Enlighten will use a third database automatically:
# my_default_database_enlighten

If you're not following the convention above, just add a new connection entry in config/database.php with the name enlighten and your custom configuration:

   'enlighten' => [
       'driver' => 'mysql',
       'host' => env('DB_HOST', '127.0.0.1'),
       'port' => env('DB_PORT', '3306'),
       'database' => 'my_enlighten_database',
       // ...
    ],

It's important to have a different connection and a different database for Enlighten in order to avoid having the info deleted or not persisted when using any of the database migration traits included by Laravel or if you run the tests using SQLite.

Use php artisan enlighten:migrate to run the package migrations.

You can also use: php artisan enlighten:migrate:fresh to refresh the migrations. Warning: this will also delete the auto generated documentation!

Manual Setup

If you didn't run php artisan enlighten:install or you received an error message, you can setup Enlighten manually following these instructions:

Publish the package assets (CSS, JavaScript) to the public folder using Artisan:

php artisan vendor:publish --tag=enlighten-build

Optionally, you can publish the config file and views for more customization.

php artisan vendor:publish --tag=enlighten-config
php artisan vendor:publish --tag=enlighten-views

Third step: import the trait Styde\Enlighten\Tests\EnlightenSetup and call $this->setUpEnlighten() in the setUp method of your TestCase, for example:

<?php

namespace Tests;

use Styde\Enlighten\Tests\EnlightenSetup;

class TestCase extends \Tests\TestCase
{
    use EnlightenSetup;

    protected function setUp(): void
    {
        parent::setUp();

        $this->setUpEnlighten();
    }
}

Note: remember to include and use the trait Styde\Enlighten\Tests\EnlightenSetup.

Optional configuration

To "group" your tests-classes as "modules", you can use a regular expression to find all the classes that match with the given pattern or patterns:

// config/enlighten.php
[
    'modules' => [
        [
            'name' => 'Users',
            'pattern' => ['*Users*']
        ],
        [
            'name' => 'Projects',
            'pattern' => ['*Projects*', '*Project*']
        ],
        [
            'name' => 'Other Modules',
            'pattern' => ['*'],
        ],
    ]
];

You can add a "catch all" group at the end to include all those files that didn't match with any of the other patterns, otherwise Enlighten will do this automatically for you.

Excluding test-classes from the documentation

If you want to include all the test-classes and methods in your documentation, you can skip this step, otherwise, you can add the following key to the /config/enlighten.php file:

[
    'tests' => [
        // Add expressions to ignore test class names and test method names.
        // i.e. Tests\Unit\* ignores all tests in the Tests\Unit\ suite,
        // validates_* ignores all tests that start with validates_.
        'ignore' => [
            'method_that_will_be_ignored',
        ],
    ],
];

You can also ignore classes and methods adding the @enlighten {"ignore": true} annotation to any class OR method, for example:

/**
 * @enlighten {"ignore": true}
 */
class IgnoreClassWithAnnotationTest extends TestCase
{
    use RefreshDatabase;

    /**
     * @test
     * @enlighten {"ignore": true}
     */
    function does_not_export_test_methods_with_the_enlighten_ignore_annotation()
    {
        $this->assertExampleIsNotCreated();
    }
}

If you'd like to do the opposite (include a class previously ignored via the configuration option) just add the @enlighten annotation to that class OR method:

/**
 * @enlighten
 */
class IncludeMethodWithAnnotationTest extends TestCase
{
    /**
     * @test
     * @enlighten
     */
    function export_test_method_with_the_enlighten_annotation_even_if_its_ignored_in_the_config()
    {
        $this->assertExampleIsCreated();
    }
}

Note: the annotations take precedence over the configuration option.

Customizing titles and descriptions

If you want to have more control on the titles of the classes and methods, or add descriptions to each group or example, you can add the following annotations in your test classes and methods:

/**
 * @title User Module
 *
 * or if you prefer:
 *
 * @testdox User Module
 *
 *  and you can also use:
 *
 * @description Manage all the user-related petitions.
 **/
class UsersTest extends TestCase {

    /**
     *
     * @testdox Create Users
     *
     * @description Register a new user via POST request. API credentials must be provided.
     **/
    public function testRegisterNewUsers()
    {
        $this->assertTrue(true);
    }
}

Hiding sections from the view

You can hide entire UI sections from the view via config

// config/enlighten.php
return [
    // Add values to this array if you want to hide certain sections from your views.
    // For valid sections see \Styde\Enlighten\Section
    'hide' => [
        //
    ],
];

Document your Internal API (Classes, Methods and Functions)

You can also create a code-snippet from your unit-tests by using the Enlighten::test() facade, this will allows you to add code-examples to your documentation.

use Styde\Enlighten\Facades\Settings;

class CalcTest extends TestCase
{
    /**
     * @test 
     * @testdox Sum two numbers
     * @description Use the Calc `sum` static method to sum two numbers.
    **/
    public function can_sum_two_numbers()
    {
        $result = Settings::test(function () {
            $a = 1;
            $b = 2;
            return Calc::sum($a, $b);
        });
          
        $this->assertSame(3, $result);
    }
}

Optionally, you can use the enlighten() helper instead of the Enlighten::test() facade.

Export the documentation as static HTML files

Since v0.4 you can use artisan to generate static files for your documentation:

php artisan enlighten:export

You can select a custom export directory and base URL to use on the static files.

Customizing the intro page

To customize the content of your Dashboard page, you can add an ENLIGHTEN.md markdown file to the root path of your project. The content of this file will overwrite the default page provided by this package.

Community Links

English

Spanish

German

Credits

License

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

More Repositories

1

html

Laravel package designed to generate common HTML components
PHP
266
star
2

curso-de-laravel-desde-cero

Ejemplos del Curso de Laravel 5.5 desde cero: https://styde.net/laravel-5/
PHP
73
star
3

blade-pagination

Laravel's pagination with Blade templating support
PHP
71
star
4

php-oop

Repositorio para el curso de programaci贸n orientada a objetos con PHP.
PHP
34
star
5

teachme

Proyecto del curso "crea tu primera aplicaci贸n con Laravel"
PHP
28
star
6

vue2

C贸digo de las lecciones del curso de Vue.js 2
Vue
20
star
7

curso-vuejs

C贸digo de las lecciones de nuestro primer curso sobre VueJS en https://styde.net
JavaScript
17
star
8

foro

JavaScript
16
star
9

laravel5-1

Building a base project for Laravel 5.1
PHP
16
star
10

factory

Generate and build model factories for Laravel using classes and methods instead of closures
PHP
16
star
11

first-steps

PHP
10
star
12

laravel5p2

Repositorio del curso de Laravel 5.2
PHP
8
star
13

seeder

Improved seeders for Laravel 5.0 and 5.1
PHP
8
star
14

notifications_demo

Creaci贸n de un m贸dulo de notificaci贸n, parte del curso de Laravel 5.3: https://styde.net/curso-de-novedades-en-laravel-5-3/
PHP
8
star
15

form

Advanced form generation for Laravel
PHP
7
star
16

blade-pagination-tests

Integration tests for the Blade Pagination package
PHP
7
star
17

laravel-query-filter

Apply filters to your queries using eloquent.
PHP
7
star
18

unit-tests

Repositorio de la parte 1 del curso: Crea componentes con PHP y Laravel
PHP
6
star
19

design-patterns-php

Repositorio del Curso de Patrones de Dise帽o en Styde.net
HTML
5
star
20

laravel-test-helpers

A collection of additional helpers to test Laravel applications
PHP
5
star
21

curso-de-laravel-9

Repositorio del curso de Laravel 9
PHP
4
star
22

authentication-methods

Repositorio para el curso M茅todos de Autenticaci贸n con Laravel
PHP
4
star
23

advanced-eloquent

Curso de Eloquent Avanzado
PHP
3
star
24

gates

Repositorio de la tercera parte del curso de t茅cnicas de autorizaci贸n: https://styde.net/tecnicas-de-autorizacion-con-laravel/
PHP
3
star
25

primeros-pasos-con-laravel-6

PHP
2
star
26

laravel-dropbox-example

PHP
2
star
27

fast-eloquent

PHP
2
star
28

authorization-techniques

PHP
2
star
29

cars

PHP
2
star
30

vue2-testing

Repositorio del Curso de Testing con Vue.js 2
JavaScript
2
star
31

laravel-7

PHP
2
star
32

container

This is a demo container for the Laravel course (in Spanish) "Creaci贸n de Componentes para PHP".
PHP
2
star
33

authorization-demo

Proyecto demo para aprender el nuevo feature de autorizaci贸n de Laravel como parte del curso introductorio de Laravel 5.1: https://styde.net/curso-introductorio-laravel-5-1/
PHP
2
star
34

html-integration-tests

Sandbox and integration tests for the html package
PHP
1
star
35

mysql-fulltext-search-in-laravel

Repositorio de la serie de FullText Search con MysQL en Laravel
PHP
1
star
36

curso-de-sass

Repositorio para el curso de Sass a fondo en Styde.net
HTML
1
star
37

eloquent-orm

Curso b谩sico de Eloquent ORM
PHP
1
star
38

refactoring-example

PHP
1
star
39

laravel-training

PHP
1
star
40

laravel-scout-demo

C贸digo fuente de la parte 5 del curso https://styde.net/curso-de-novedades-en-laravel-5-3/
PHP
1
star
41

laravel-and-vue

PHP
1
star
42

whetstone

Tool to unit test your Blade views and components
PHP
1
star