Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Testinglaravelpackageinstaller Laravel Package

acacha/testinglaravelpackageinstaller

A minimal Laravel package installer test project. Provides a simple skeleton repository used to validate and experiment with Laravel package installation workflows, composer configuration, and installer behavior in a lightweight environment.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require --dev acacha/testinglaravelpackageinstaller
    

    Add to composer.json under require-dev:

    "extra": {
        "laravel": {
            "package-installer": {
                "composer": {
                    "repositories": {
                        "custom-repo": {
                            "type": "vcs",
                            "url": "https://github.com/your-repo/package.git"
                        }
                    }
                }
            }
        }
    }
    
  2. First Use Case In a test class, use the trait to install a package dynamically:

    use Acacha\TestingLaravelPackageInstaller\TestingLaravelPackageInstaller;
    
    class ExampleTest extends TestCase
    {
        use TestingLaravelPackageInstaller;
    
        public function test_package_installation()
        {
            $this->installPackage('vendor/package', '1.0.0');
            // Test logic here...
        }
    }
    

Implementation Patterns

Workflows

  1. Dynamic Package Installation Install packages conditionally in tests:

    if ($this->shouldTestFeatureX()) {
        $this->installPackage('vendor/feature-x', 'dev-main');
    }
    
  2. Integration with setUp() Centralize package installation in test setup:

    public function setUp(): void
    {
        parent::setUp();
        $this->installPackage('vendor/core', '2.1.*');
    }
    
  3. Composer Configuration Overrides Extend composer.json dynamically:

    $this->installPackage('vendor/package', '1.0.0', [
        'config': {
            'extra': {
                'laravel': {
                    'env': ['APP_DEBUG=true']
                }
            }
        }
    ]);
    

Integration Tips

  • Leverage with refreshDatabase() Combine with Laravel’s database testing:

    public function test_with_package_and_db()
    {
        $this->installPackage('vendor/db-utils', '1.2.*');
        $this->refreshDatabase();
        // Test DB interactions...
    }
    
  • Use with withFactories() Install packages before factory loading:

    public function test_with_factories()
    {
        $this->installPackage('vendor/factories', 'dev-master');
        $this->withFactories(__DIR__.'/factories');
        // Test factory usage...
    }
    

Gotchas and Tips

Pitfalls

  1. Composer Cache Issues Clear Composer cache if packages fail to install:

    composer clear-cache
    

    Or programmatically:

    $this->artisan('cache:clear')->expectsOutput('Cache cleared!');
    
  2. Version Constraints Avoid overly broad constraints (e.g., *) in tests—use exact versions or ranges (e.g., 1.0.0, ^2.0).

  3. Dependency Conflicts Install packages in a specific order to avoid conflicts:

    $this->installPackage('vendor/base', '1.0.0');
    $this->installPackage('vendor/extension', '1.0.0'); // Depends on base
    

Debugging

  • Check Installed Packages Verify installation via Composer:

    $this->artisan('composer:dump-autoload')
         ->expectsOutput('Generating autoload files')
         ->assertExitCode(0);
    
  • Inspect composer.json Temporarily dump the modified composer.json for debugging:

    file_put_contents(
        storage_path('app/composer.json'),
        json_encode($this->getComposerConfig(), JSON_PRETTY_PRINT)
    );
    

Extension Points

  1. Custom Repositories Add VCS or package repositories dynamically:

    $this->addComposerRepository('git@github.com:vendor/repo.git');
    $this->installPackage('vendor/repo', 'dev-branch');
    
  2. Post-Install Scripts Run scripts after installation:

    $this->installPackage('vendor/package', '1.0.0', [
        'scripts': {
            'post-install-cmd': [
                'php artisan package:discover'
            ]
        }
    ]);
    
  3. Environment-Specific Config Use getenv() to conditionally install packages:

    if (getenv('TEST_FEATURE_X')) {
        $this->installPackage('vendor/feature-x', '1.0.0');
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle