Repository navigation
Running Tests
KeyAnyWhere has a PHPUnit suite that runs against a real PostgreSQL database: there is no SQLite fallback, because the migrations use PostgreSQL-specific SQL. This page runs the suite, a single file and a single test, and then lists the conventions to follow when writing new tests.
The test database from the Quick Start (keyanywhere_test, the DB_TEST_* variables in config/.env) must exist. The suite creates the tables itself.
composer testOne file:
vendor/bin/phpunit tests/TestCase/Controller/UsersControllerTest.phpOne test, by name:
vendor/bin/phpunit --filter testLoginComCredenciaisECodigo2faValidosAutenticacomposer check runs the tests, the code style check (phpcs) and the static analysis (PHPStan level 8). Run it before considering any work done.
composer checkThe code style must end with 0 errors and 0 warnings. To fix what can be fixed automatically:
composer cs-fixThese rules come from problems that already happened. Following them keeps the suite reliable.
-
Fixtures with an explicit integer
idmust extendtests/Fixture/AppFixture.php, which resyncs the PostgreSQL sequence after the insert. Otherwise the nextsave()collides on a duplicate key. -
Encrypted fields in fixtures must be encrypted with
Criptografia::criptografar()(seeEntradasFixture). Plain text there fails to decrypt. -
Controller tests
use CsrfTestTrait;. The CSRF cookie name depends on the environment: always useApplication::nomeCookieCsrf(), never a literal. To send a request without the token, set$this->_csrfToken = false;. -
Logged-in requests:
AuthenticatedTestTrait::loginAsUser()andloginAsNonRootUser()fake a session, including thesessionsrow thatSessionsKawMiddlewareexpects. -
Guarded fields:
Userdoesn't mass-assignroot,tfa_ativoortfa_secret. Set them by property assignment ($user->root = true;) afternewEntity(). -
Audited tables: a test that saves an entry, category or user lists
'app.Auditorias'in$fixtures, so the audit table is emptied between tests. A test that logs a security event lists'app.EventosSeguranca'. -
Real 2FA through the login: flip
Configure::write('debug', false)for the request and simulate HTTPS, asUsersControllerTest::postLoginEmModoProducao()does. Send a real current code (Google2FA::getCurrentOtp()). -
Session contents after a request: read
$_SESSIONdirectly, not$this->_requestSession->read(). -
Parallel runs (mutation tests): each process gets a
TEST_TOKENand its own database,<DB_TEST_NAME>_<token>. Anything new that tests share across processes (a file, a folder) needs the same per-token treatment.
Source code · Issues · Releases · Packagist · Online demo · Hosted edition
1. Getting started
2. Installing in production
- Overview
- Preparing the Server
- Installing KeyAnyWhere
- File Permissions
- Generating Security Keys
- Environment Variables
- Configuration Files
- Database Setup
- Insecure Password Catalog
- Web Server and HTTPS
- First-Run Setup
3. Operating your installation
4. Using KeyAnyWhere
5. Security
6. Development
7. Extending