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

Wopi Test Bundle Laravel Package

champs-libres/wopi-test-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require champs-libres/wopi-test-bundle
    

    Register the bundle in config/app.php under providers:

    ChampsLibres\WopiTestBundle\WopiTestBundle::class,
    
  2. First Use Case: Mocking WOPI Server Configure the bundle in config/packages/champs_libres_wopi_test.yaml:

    wopi_test:
        enabled: true
        mock_server_url: 'http://localhost:8000/wopi'
    

    Use the WopiTestClient in a test:

    use ChampsLibres\WopiTestBundle\Client\WopiTestClient;
    
    public function testWopiIntegration()
    {
        $client = new WopiTestClient();
        $response = $client->getFileInfo('test-file-id');
        $this->assertEquals(200, $response->getStatusCode());
    }
    
  3. Key Files to Review

    • src/Client/WopiTestClient.php: Core client logic.
    • src/DependencyInjection/Configuration.php: Configuration schema.
    • tests/: Example test cases.

Implementation Patterns

Workflows

  1. Mocking WOPI Endpoints Use WopiTestClient to simulate WOPI server responses (e.g., getFileInfo, lock, unlock):

    $client = new WopiTestClient();
    $client->mockGetFileInfo(['size' => 1024, 'userId' => 'test-user']);
    $response = $client->getFileInfo('file-id');
    
  2. Integration with wopi-bundle Replace the real WOPI client with the test client in tests:

    $kernel = self::bootKernel();
    $container = $kernel->getContainer();
    $container->set('wopi.client', function () use ($client) {
        return $client;
    });
    
  3. Custom Mock Responses Extend WopiTestClient to add custom endpoints:

    class CustomWopiTestClient extends WopiTestClient
    {
        public function mockCustomEndpoint(array $data)
        {
            $this->mockResponse('/custom', $data);
        }
    }
    

Integration Tips

  • Laravel Service Container: Bind the test client to the container for easy swapping:
    $this->app->bind(WopiTestClient::class, function () {
        return new WopiTestClient();
    });
    
  • Test Traits: Create a reusable trait for WOPI tests:
    trait WopiTestTrait
    {
        protected function mockWopiResponse(string $endpoint, array $data)
        {
            $client = new WopiTestClient();
            $client->mockResponse($endpoint, $data);
            return $client;
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Configuration Overrides Ensure wopi_test.enabled is false in production to avoid unintended mocking:

    # config/packages/champs_libres_wopi_test.yaml
    wopi_test:
        enabled: false  # Disable in production!
    

    Debugging Tip: Check config('wopi_test.enabled') in tests to confirm mocking is active.

  2. Endpoint Mismatches The bundle assumes WOPI endpoints follow standard paths (e.g., /files/{id}). Custom WOPI setups may require extending WopiTestClient:

    $client->setBaseUrl('http://custom-wopi-server');
    
  3. Stateful Mocks Mock responses are stateless by default. For stateful tests (e.g., locks), use a custom client:

    $client->setState(['locks' => ['file-id' => true]]);
    

Debugging

  • Verify Mocks: Use dd($client->getMockedResponses()) to inspect active mocks.
  • HTTP Errors: Check the WopiTestClient logs for malformed requests:
    $client->setDebug(true);
    

Extension Points

  1. Custom Responses Override mockResponse() to add logic (e.g., dynamic data):

    $client->mockResponse('/files/{id}', function ($id) {
        return ['size' => rand(1, 1024), 'id' => $id];
    });
    
  2. Middleware Simulation Simulate WOPI middleware (e.g., auth) by extending the client:

    class AuthWopiTestClient extends WopiTestClient
    {
        public function __construct()
        {
            $this->mockResponse('/files/*', [], 401);
        }
    }
    
  3. Event Listeners Hook into the bundle’s events (if added in future versions) to log test interactions:

    $client->on('request', function ($request) {
        \Log::info('WOPI Test Request:', $request->toArray());
    });
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui