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

Simplesamlphp Test Framework Laravel Package

simplesamlphp/simplesamlphp-test-framework

Testing framework for SimpleSAMLphp to help validate authentication and SAML flows in automated test suites. Provides tooling and fixtures to simulate IdP/SP interactions, enabling reliable integration tests for applications using SimpleSAMLphp.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer in your Laravel project (if integrating with SimpleSAMLphp):

    composer require simplesamlphp/simplesamlphp-test-framework
    

    Note: This package is primarily designed for SimpleSAMLphp testing, not Laravel. Use it via CLI or standalone PHP scripts.

  2. First Use Case Test a SimpleSAMLphp module or core functionality:

    use SimpleSAML\Test\TestCase;
    
    class MyTest extends TestCase {
        public function testSomething() {
            $this->assertTrue(true); // Basic test
        }
    }
    

    Run tests via:

    phpunit path/to/tests
    
  3. Key Files

    • tests/ – Your test directory.
    • phpunit.xml – Configure test suite (extend SimpleSAMLphp’s defaults if needed).

Implementation Patterns

Workflows

  1. Testing SimpleSAMLphp Modules

    • Extend SimpleSAML\Test\TestCase for core functionality.
    • Use SimpleSAML\Test\WebTestCase for HTTP/integration tests (e.g., auth flows):
      public function testAuthn() {
          $this->get('/simplesaml/module.php/core/authadmin/authenticate.php')
               ->assertStatus(200);
      }
      
  2. Mocking Dependencies

    • Override SimpleSAMLphp’s DI container in tests:
      $this->getSimpleSAMLphp()->getAuth()->setAuthState('test_user');
      
  3. Database Testing

    • Use SimpleSAML\Test\DatabaseTestCase for DB-backed tests:
      public function testUserStore() {
          $this->assertDatabaseHas('saml_users', ['uid' => 'test_user']);
      }
      
  4. Integration with Laravel

    • If using SimpleSAMLphp as an auth provider, test its API endpoints via Laravel’s HTTP tests:
      public function testSAMLLoginRedirect() {
          $response = $this->get('/login/saml');
          $response->assertRedirect('https://simplesaml.example.com/saml2/idp/metadata.php');
      }
      

Integration Tips

  • Configuration: Copy SimpleSAMLphp’s config.php to tests/_config/ and override settings.
  • Fixtures: Use SimpleSAML\Test\TestCase::getSimpleSAMLphp() to load test configurations.
  • Logging: Enable debug logs in tests/_config/config.php:
    'debug' => true,
    'logging' => ['level' => 'debug'],
    

Gotchas and Tips

Pitfalls

  1. Environment Mismatch

    • Tests assume SimpleSAMLphp’s default paths (e.g., modules/, lib/). Use TEST_CONFIG_DIR to override:
      TEST_CONFIG_DIR=tests/_config phpunit
      
  2. Session Handling

    • SimpleSAMLphp tests rely on PHP sessions. Clear them between tests:
      $this->getSimpleSAMLphp()->getSessionHandler()->clear();
      
  3. Database Transactions

    • DatabaseTestCase uses transactions by default. Disable with:
      $this->beginTransaction(false);
      
  4. HTTP Tests

    • WebTestCase uses Guzzle under the hood. Mock external services (e.g., IdPs) with:
      $this->getSimpleSAMLphp()->getHTTP()->setMockResponse('https://idp.example.com', 200, '{}');
      

Debugging

  • Logs: Check tests/_logs/ for SimpleSAMLphp debug output.
  • Dumping: Use var_dump($this->getSimpleSAMLphp()->getAuth()->getAuthState()); for runtime inspection.
  • PHPUnit: Run with -v for verbose output:
    phpunit -v tests/MyTest.php
    

Extension Points

  1. Custom Test Cases Extend SimpleSAML\Test\TestCase to add reusable methods:

    class BaseSAMLTest extends TestCase {
        protected function assertSAMLResponse($response, $expected) {
            // Custom assertion logic
        }
    }
    
  2. Test Data Factories Use SimpleSAMLphp’s SimpleSAML\Test\TestDataFactory to generate test users/attributes:

    $user = $this->getTestDataFactory()->createUser(['uid' => 'test_user']);
    
  3. CI/CD

    • Cache SimpleSAMLphp’s dependencies in CI (e.g., Docker volumes for modules/).
    • Parallelize tests with PHPUnit’s --group flag if tests are independent.
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.
terminal42/code-quality-tools
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