Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-Statamic tests run slow after Statamic installation #10753

Open
Fadarrizz opened this issue Sep 3, 2024 · 5 comments
Open

Non-Statamic tests run slow after Statamic installation #10753

Fadarrizz opened this issue Sep 3, 2024 · 5 comments

Comments

@Fadarrizz
Copy link

Bug description

After installing Statamic in an existing Laravel project, all non-Statamic tests take more than a second per test longer.

I've been playing with some config settings, such as stache, but nothing seems to improve it.

How to reproduce

  • Have an existing Laravel project with tests
  • Pick a test and see duration after running
  • Install Statamic with eloquent-driver addon
  • Run test again and notice duration increase

Logs

No response

Environment

❯ a statamic:support:details

Environment
Application Name: Laravel
Laravel Version: 11.21.0
PHP Version: 8.3.11
Composer Version: 2.7.8
Environment: local
Debug Mode: ENABLED
URL: localhost
Maintenance Mode: OFF
Timezone: Europe/Amsterdam
Locale: nl

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED

Drivers
Broadcasting: null
Cache: file
Database: mysql
Logs: stack / daily
Mail: smtp
Queue: sync
Session: database

Filament
Packages: filament, forms, notifications, support, tables
Version: v3.2.110
Views: PUBLISHED: notifications

Livewire
Livewire: v3.5.6

Sentry
Enabled: MISSING DSN
Environment: local
Laravel SDK Version: 4.8.0
PHP SDK Version: 4.9.0
Release: NOT SET
Sample Rate Errors: 100%
Sample Rate Performance Monitoring: 0%
Sample Rate Profiling: NOT SET
Send Default PII: DISABLED

Statamic
Addons: 1
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.23.0 Solo

Statamic Addons
statamic/eloquent-driver: 4.14.0

Statamic Eloquent Driver
Asset Containers: file
Assets: file
Blueprints: file
Collection Trees: file
Collections: file
Entries: eloquent
Forms: file
Global Sets: file
Global Variables: file
Navigation Trees: file
Navigations: file
Revisions: file
Sites: file
Taxonomies: file
Terms: file
Tokens: file

Installation

Existing Laravel app

Additional details

No response

@duncanmcclean
Copy link
Member

Are you able to share an example of a test that's running slow? What does your TestCase look like?

@Fadarrizz
Copy link
Author

Hi @duncanmcclean,

This is what my TestCase looks like:

<?php
declare(strict_types = 1);

namespace Tests;

use Nuwave\Lighthouse\Testing\MakesGraphQLRequests;
use Nuwave\Lighthouse\Testing\RefreshesSchemaCache;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use MakesGraphQLRequests;
    use RefreshesSchemaCache;

    /**
     * Setup the test environment.
     *
     * @return void
     */
    protected function setUp(): void
    {
        parent::setUp();

        $this->withoutVite();
    }
}

I use Pest btw:

<?php
declare(strict_types = 1);

use Illuminate\Foundation\Testing\RefreshDatabase;

uses(Tests\TestCase::class, RefreshDatabase::class)->in('Feature');

A test that runs slow for example is the following:

<?php
declare(strict_types = 1);

test('that the dd and dump functions are not used in the codebase')
    ->expect(['dd', 'dump'])
    ->not
    ->toBeUsed();

This test takes ~6.5 seconds to complete with Statamic installed.
Without Statamic (by not letting Composer discover Statamic), the test takes ~5 seconds to complete.

@duncanmcclean
Copy link
Member

Thanks!

@jasonvarga
Copy link
Member

jasonvarga commented Sep 4, 2024

What about tests that aren't 5 seconds long to begin with? That's already slow.

@Fadarrizz
Copy link
Author

Fadarrizz commented Sep 6, 2024

So, I trimmed some stuff down to have the bare minimum in feature tests:

// tests/TestCase.php

<?php
declare(strict_types = 1);

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    /**
     * Setup the test environment.
     *
     * @return void
     */
    protected function setUp(): void
    {
        parent::setUp();

        $this->withoutVite();
    }
}
// tests/Pest.php

<?php
declare(strict_types = 1);

uses(Tests\TestCase::class)->in('Feature');

I wrote the most basic test I could think of and ran it both with and without Statamic:

// tests/Feature/Test.php

<?php
declare(strict_types = 1);

test('true', function () {
    expect(true)->toBe(true);
});

This test takes 0.42 sec on my machine without Statamic installed (this time I removed both Statamic packages from Composer).

With Statamic, this test takes 1.91 sec.

Do you have any idea what makes it run slower?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants