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.
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.
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
Key Files
tests/ – Your test directory.phpunit.xml – Configure test suite (extend SimpleSAMLphp’s defaults if needed).Testing SimpleSAMLphp Modules
SimpleSAML\Test\TestCase for core functionality.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);
}
Mocking Dependencies
$this->getSimpleSAMLphp()->getAuth()->setAuthState('test_user');
Database Testing
SimpleSAML\Test\DatabaseTestCase for DB-backed tests:
public function testUserStore() {
$this->assertDatabaseHas('saml_users', ['uid' => 'test_user']);
}
Integration with Laravel
public function testSAMLLoginRedirect() {
$response = $this->get('/login/saml');
$response->assertRedirect('https://simplesaml.example.com/saml2/idp/metadata.php');
}
config.php to tests/_config/ and override settings.SimpleSAML\Test\TestCase::getSimpleSAMLphp() to load test configurations.tests/_config/config.php:
'debug' => true,
'logging' => ['level' => 'debug'],
Environment Mismatch
modules/, lib/). Use TEST_CONFIG_DIR to override:
TEST_CONFIG_DIR=tests/_config phpunit
Session Handling
$this->getSimpleSAMLphp()->getSessionHandler()->clear();
Database Transactions
$this->beginTransaction(false);
HTTP Tests
$this->getSimpleSAMLphp()->getHTTP()->setMockResponse('https://idp.example.com', 200, '{}');
tests/_logs/ for SimpleSAMLphp debug output.var_dump($this->getSimpleSAMLphp()->getAuth()->getAuthState()); for runtime inspection.-v for verbose output:
phpunit -v tests/MyTest.php
Custom Test Cases
Extend SimpleSAML\Test\TestCase to add reusable methods:
class BaseSAMLTest extends TestCase {
protected function assertSAMLResponse($response, $expected) {
// Custom assertion logic
}
}
Test Data Factories
Use SimpleSAMLphp’s SimpleSAML\Test\TestDataFactory to generate test users/attributes:
$user = $this->getTestDataFactory()->createUser(['uid' => 'test_user']);
CI/CD
modules/).--group flag if tests are independent.How can I help you explore Laravel packages today?