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

Test Laravel Package

myqee/test

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require myqee/test --dev
    

    Add to composer.json under require-dev if not auto-installed.

  2. Basic Test File Structure Place test files in tests/Feature/ (for HTTP tests) or tests/Unit/ (for logic tests). Example minimal test:

    // tests/Feature/ExampleTest.php
    use Myqee\Test\TestCase;
    
    class ExampleTest extends TestCase
    {
        public function test_example()
        {
            $this->assertTrue(true);
        }
    }
    
  3. First Use Case: HTTP Assertions

    public function test_homepage_returns_success()
    {
        $response = $this->get('/');
        $response->assertStatus(200);
    }
    

Implementation Patterns

Core Workflows

  1. HTTP Testing

    • Route Testing: Use route() helper to test named routes.
      $this->get(route('login'))->assertStatus(302);
      
    • Session/Authentication:
      $this->actingAs(User::first())->get('/dashboard');
      
  2. Database Transactions Automatically rolled back after each test (default behavior). Disable with:

    public function setUp(): void
    {
        parent::setUp();
        $this->withoutExceptionHandling();
        $this->withoutTransactions();
    }
    
  3. Mocking Services Use Laravel’s built-in mocking:

    $this->mock(EmailService::class)->shouldReceive('send')
        ->once()->with('welcome');
    
  4. Custom Assertions Extend TestCase to add reusable assertions:

    class CustomTestCase extends TestCase
    {
        protected function assertJsonHasError($response, $field, $message)
        {
            $response->assertJsonStructure([$field => [$message]]);
        }
    }
    

Integration Tips

  1. Laravel Mix/Pest If using Pest, alias TestCase in pest.php:

    uses(Myqee\Test\TestCase::class)->in('Feature');
    
  2. API Testing Use ->assertJson() for API responses:

    $this->postJson('/api/login', ['email' => 'test@example.com'])
         ->assertJson(['status' => 'success']);
    
  3. Event Testing Assert events fired:

    $this->assertEventFired(UserRegistered::class);
    
  4. Queue Testing Use Queue::fake():

    Queue::fake();
    $this->post('/send-email');
    Queue::assertPushed(SendEmailJob::class);
    

Gotchas and Tips

Pitfalls

  1. Missing TestCase Import Forgetting to extend Myqee\Test\TestCase (not Laravel’s default) will break assertions. Fix: Always extend use Myqee\Test\TestCase.

  2. Database Seeding If using DatabaseMigrations trait, ensure php artisan migrate runs before tests. Tip: Add to phpunit.xml:

    <env name="DB_CONNECTION" value="sqlite_memory"/>
    
  3. Assertion Chaining Chained assertions (e.g., assertStatus()->assertSee()) may fail silently. Tip: Use ->assertStatus(200)->assertSee('text') explicitly.

  4. Slow Tests Avoid withoutTransactions() in CI; use refreshDatabase() instead:

    public function setUp(): void
    {
        parent::setUp();
        $this->refreshDatabase();
    }
    

Debugging

  1. Dump Responses Use dd($response->getContent()) or dump($response->json()).

  2. Enable Exception Handling Temporarily disable in setUp():

    $this->withoutExceptionHandling();
    
  3. Log Test Output Add to phpunit.xml:

    <listeners>
        <listener class="Illuminate\Foundation\Testing\TestListener">
            <arguments>
                <object class="Illuminate\Log\TestLogListener"/>
            </arguments>
        </listener>
    </listeners>
    

Extension Points

  1. Custom Test Traits Create reusable traits:

    trait AssertsApiErrors
    {
        protected function assertApiValidationError($response, $field)
        {
            $response->assertJsonValidationErrors([$field]);
        }
    }
    
  2. Hooks Override setUp()/tearDown() for shared logic:

    protected function setUp(): void
    {
        parent::setUp();
        $this->seed(); // Custom seed
    }
    
  3. Configuration Publish config (if available) with:

    php artisan vendor:publish --provider="Myqee\Test\TestServiceProvider"
    

    Note: Package lacks config; check for defaults in TestCase.

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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor