Make sure the following software is installed:
To run unit tests on your machine:
First, you will need to clone this repository. Then inside the clone, you will need to create installation-specific copies of the following files:
.env.sample
→ .env
config/config.specific.sample.php
→ config/config.specific.php
The sample versions have sensible defaults, but update the copies as necessary. The options must be consistent between the various configuration files.
To initialize the database or update it with new patches, run:
docker compose run --rm flyway
To modify the database, add a file called V<VERSION_NUMBER>__<NAME>.sql
into
db/patches
and rerun the command.
You can optionally start up phpMyAdmin to
inspect your mysql database in a web browser at http://localhost/pma/
:
docker compose up --build -d pma
Then you can start up the persistent game services
docker compose up --build -d traefik smr
For development, it may be desirable to automatically pick up source code changes without rebuilding the docker image. Simply use the smr-dev
service instead of smr
, i.e.:
docker compose up --build -d traefik smr-dev
In order to create an admin account you should first create a standard account via the register form, then run the following command to give that account admin permissions:
db/init_admin.sh
The account should now have an "Admin Tools" link on the left whilst logged in, which will allow you to assign any extra permissions to yourself and others.
To create a game you will have to have assigned yourself the "1.6 Universe Generator" and then access this link via the admin tools to create the game. Once you are happy with the game you need to edit the "game" table and set the "enabled" flag for your game to 'TRUE' in order for it to appear in the list of games to join.
This is the coding style that should be used for any new code, although currently not all code currently follows these guidelines (the guidelines are also likely to require extension).
Opening races should be placed on the same line with a single space before
Single line if statements should still include braces
if (true) {
}
Variable names should be camelCase normally, except when in templates when they should be UpperCamelCase (to enforce some mental separation between the two contexts).
$applicationVar = 'value';
$TemplateVar = 'value';
Function names should be camelCase, class names should be UpperCamelCase
function exampleFunction() {
}
class ExampleClass {
public function exampleMethod() {
}
}
Associative array indices should be UpperCamelCase
$container['SectorID'] = $sectorID;
Classes should be added to src/lib/Smr
to take advantage of the PSR-4 autoloader.
Engine files and their associated templates should be placed in src/engine
and
src/templates
respectively (see Page::process
for how they will be included).
If possible use a function from Globals
or a relevant object to generate links (e.g. Globals::getCurrentSectorHREF()
or $otherPlayer->getExamineTraderHREF()
).
This is usually clearer and allows hooking into the hotkey system.
To create a link you first create a "container" using a Page
class, e.g.:
$container = new CurrentSector();
You can then call $container->href()
to get a HREF, which will give a link that
can be displayed on the page. In this example, clicking the link will load the
"Current Sector" page next.
You can also call $container->go()
, which will immediately forward to this page
within the same HTTP request.
For any page which takes input through POST or GET, these values may be accessed
using Smr\Session::getRequestVar()
and relatives, which will store the value
in the session. When a page is auto-refreshed with AJAX, these inputs are not
resent, but they are still required to render the page correctly.
This initially started out to be used in the "standard" way for NPCs but that idea has since been discarded. Now all core/shared "Default" code should be in the abstract version, with the normal class child implementing game type specific functionality/overrides, for instance "lib/Semi Wars/Account" which is used to make every account appear to be a "vet" account when playing semi wars.
SMR uses PHPUnit to run unit tests.
composer start:test-services
composer phpunit
to execute the full suite of PHPUnit tests./test
directory.This information applies to IDEA-based IDEs, e.g. IntelliJ
, PHPStorm
. For other vendors, please refer to your vendor's documentation for running PHPUnit tests against a remote container.
IntelliJ
, you must have the following Jetbrains-provided plugins installed:
File > Settings > Languages & Frameworks > PHP
. In the CLI Interpreter
area, click the ...
buttonFrom Docker, Vagrant, VM, WSL, Remote...
Docker Compose
, and in the Service
area, select phpunit
. Press "OK".Xdebug
information.Environment variables
box on the new intepreter's screen, paste in the values from /test/env
in the project directory.Composer
item: In the CLI Interpreter
drop down, select the new interpreter you've created. Press "Apply".Test Frameworks
item.+
button to create an entry, select the newly created interpreter from the drop down, and press "OK".PHPUnit library
section, set the Path to script
value to /smr/vendor/autoload.php
Test Runner
section, set the Default configuration file
to /smr/phpunit.xml
SmrTest\BaseIntegrationSpec
. This will ensure that any test data that gets written to the database will be cleaned up after each test.
BaseIntegrationSpec
will check for any tables that are populated from the flyway
migration during startup, and truncate all other tables after your test.