StydeNet/enlighten

Laravel Enlighten is shown only when the test breaks

clablancherie opened this issue · 13 comments

Hi,

I'm on Laravel 8, and i'm trying to have the same result from the "demo". But, the doc doesn't work, i see something only when there is an error on my test api...

It's a little weird no ?

Capture
capture-2
capture-3

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
    bootstrap="vendor/autoload.php"
    colors="true"
    printerClass="Styde\Enlighten\Tests\BasicResultPrinter"
>
  <coverage processUncoveredFiles="true">
    <include>
      <directory suffix=".php">./app</directory>
    </include>
  </coverage>
  <testsuites>
    <testsuite name="Unit">
      <directory suffix="Test.php">./tests/Unit</directory>
    </testsuite>
    <testsuite name="Feature">
      <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>
  </testsuites>
  <php>
    <server name="APP_ENV" value="testing"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="DB_CONNECTION" value="enlighten"/>
    <server name="DB_DATABASE" value=":memory:"/>
    <server name="MAIL_MAILER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
    <server name="TELESCOPE_ENABLED" value="false"/>
  </php>
</phpunit>

Hi @clablancherie,

Are you using the latest version? Could you please try installing dev-dev? We released a new version earlier today with a few fixes.

You can also join our discord Chanel to get more help https://discord.gg/hNCV6p

@clablancherie Sorry,last version is 0.2.9, could you please try that one? Let me know if that works for you.

Cheers,
Jeff

Hello Jeff,

I've tried with "0.2.9" but nothing changes. I alway see "intro page" with this uri : http://mydomain/enlighten/intro

dashboard

And my tests are ok.

test-phpunit

It seems you only have one test in your project. Is it possible Enlighten is not reading that test? i.e. You are not calling enlightenSetup or that test extends from the TestCase of PHPUnit instead of Tests\TestCase?

Is it a demo project? Could you please share the code of your test here?

Also could you please triple check you're using Enlighten 0.2.9?

i.e. run in the console: composer show styde/enlighten

Also: are you using Git in your project? Enlighten depends on Git at the moment. Although in dev-dev you can customise the Version Control System.

Alright, it's ok, i've found the problem.

The fact is, when i was using phpunit first with my Laravel, i've use the trait "use RefreshDatabase;". But actually with this package we can't use it, because it will clear the database after test.

So maybe this behavior has to be added to the package, or maybe you could add a warning on the documentation.

Thank you for your availability!

Well actually, i think that you have to add the option to "clear" the database between test, and keep, because when i restart my test suite, it break with some "unique error key", that's it normal. :/

@clablancherie we mention it in the doc actually: https://github.com/StydeNet/enlighten#database-setup

You can, and probably should, use RefreshDatabase or a similar trait in your tests. To avoid losing the data just create a new database for Enlighten. Please follow the instructions I copied above, if you have any further question or problem don't hesitate ask :)

I agree, and i use RefreshDatabase, but the fact is that when i use it, the data are deleted from the new database, and actually the doc doesn't works, because it's only show the intro page.

The only way i find to display the doc was to remove the trait. And i followed the complete doc about setup the project :/

If you add a new database for Enlighten then the data shouldn't be deleted as RefreshDatabase it only transacts the default connect.

What's your database configuration?

Please paste it here to have a look.

<?php

use Illuminate\Support\Str;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => 'InnoDB',
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
        ],

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

    ],
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
    bootstrap="vendor/autoload.php"
    colors="true"
    printerClass="Styde\Enlighten\Tests\BasicResultPrinter"
>
  <coverage processUncoveredFiles="true">
    <include>
      <directory suffix=".php">./app</directory>
    </include>
  </coverage>
  <testsuites>
    <testsuite name="Unit">
      <directory suffix="Test.php">./tests/Unit</directory>
    </testsuite>
    <testsuite name="Feature">
      <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>
  </testsuites>
  <php>
    <server name="APP_ENV" value="testing"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="DB_CONNECTION" value="enlighten"/>
    <server name="DB_DATABASE" value=":memory:"/>
    <server name="MAIL_MAILER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
    <server name="TELESCOPE_ENABLED" value="false"/>
  </php>
</phpunit>
APP_NAME=Laravel
APP_ENV=local
APP_KEY=xxxxx
APP_DEBUG=true
APP_URL=http://projeo.test

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=projeo
DB_USERNAME=root
DB_PASSWORD=

Here you have the things, the database.php (only section connection), .env file, and also phpunit.xml config. The fact is the trait is used by enlighten when i run the tests. :/

@clablancherie it seems you're using the Enlighten connection as your test database. Basically just delete this line from phpunit.xml:

<server name="DB_CONNECTION" value="enlighten"/>

I think that's the problem.

And you can keep <server name="DB_DATABASE" value=":memory:"/> it's fine to run the tests with sqlite if you have added a different database connection for enlighten.

I hope you can start enjoying our component now :)

It's ok you're right :) thanks !