Fix configuration bug with new game settings and add tests
This commit is contained in:
@@ -94,7 +94,7 @@ class Configuration
|
|||||||
throw new InvalidConfigurationException("Game days per day cannot be negative: {$gameDaysPerDay}");
|
throw new InvalidConfigurationException("Game days per day cannot be negative: {$gameDaysPerDay}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->gameEpoch = $gameEpoch;
|
$this->gameEpoch = (new DateTime())->setTimestamp($gameEpoch);
|
||||||
$this->gameOffsetSeconds = $gameOffsetSeconds;
|
$this->gameOffsetSeconds = $gameOffsetSeconds;
|
||||||
$this->gameDaysPerDay = $gameDaysPerDay;
|
$this->gameDaysPerDay = $gameDaysPerDay;
|
||||||
}
|
}
|
||||||
@@ -183,7 +183,7 @@ class Configuration
|
|||||||
$s .= " user: " . $this->getDatabaseUser() . "\n";
|
$s .= " user: " . $this->getDatabaseUser() . "\n";
|
||||||
$s .= " password: <hidden>\n";
|
$s .= " password: <hidden>\n";
|
||||||
$s .= "game:\n";
|
$s .= "game:\n";
|
||||||
$s .= " epoch: " . $this->getGameEpoch() . "\n";
|
$s .= " epoch: " . $this->getGameEpoch()->format(DateTime::ISO8601) . "\n";
|
||||||
$s .= " offsetSeconds: " . $this->getGameOffsetSeconds() . "\n";
|
$s .= " offsetSeconds: " . $this->getGameOffsetSeconds() . "\n";
|
||||||
$s .= " daysPerDay: " . $this->getGameDaysPerDay() . "\n";
|
$s .= " daysPerDay: " . $this->getGameDaysPerDay() . "\n";
|
||||||
$s .= "logs:\n";
|
$s .= "logs:\n";
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace LotGD\Core\Tests;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Monolog\Handler\NullHandler;
|
||||||
|
|
||||||
|
use LotGD\Core\Configuration;
|
||||||
|
|
||||||
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private $logger;
|
||||||
|
private $configDir;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->configDir = __DIR__ . DIRECTORY_SEPARATOR . join(DIRECTORY_SEPARATOR, ['datasets', 'config']);
|
||||||
|
|
||||||
|
$this->logger = new Logger('test');
|
||||||
|
$this->logger->pushHandler(new NullHandler());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBasicConfiguration()
|
||||||
|
{
|
||||||
|
$configuration = new Configuration($this->configDir . DIRECTORY_SEPARATOR . 'basic.yml');
|
||||||
|
|
||||||
|
$this->assertEquals('some_dsn', $configuration->getDatabaseDSN());
|
||||||
|
$this->assertEquals('some_name', $configuration->getDatabaseName());
|
||||||
|
$this->assertEquals('some_user', $configuration->getDatabaseUser());
|
||||||
|
$this->assertEquals('some_password', $configuration->getDatabasePassword());
|
||||||
|
$this->assertEquals($this->configDir . DIRECTORY_SEPARATOR . './', $configuration->getLogPath());
|
||||||
|
$this->assertEquals(new DateTime('2016-07-01 01:01:01.0 -8'), $configuration->getGameEpoch());
|
||||||
|
$this->assertEquals(32, $configuration->getGameOffsetSeconds());
|
||||||
|
$this->assertEquals(2, $configuration->getGameDaysPerDay());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToString()
|
||||||
|
{
|
||||||
|
$configuration = new Configuration($this->configDir . DIRECTORY_SEPARATOR . 'basic.yml');
|
||||||
|
$s = $configuration->__toString();
|
||||||
|
|
||||||
|
$this->assertFalse(strpos($s, 'some_password'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
database:
|
||||||
|
dsn: some_dsn
|
||||||
|
name: some_name
|
||||||
|
user: some_user
|
||||||
|
password: some_password
|
||||||
|
game:
|
||||||
|
epoch: 2016-07-01 01:01:01.0 -8
|
||||||
|
offsetSeconds: 32
|
||||||
|
daysPerDay: 2
|
||||||
|
logs:
|
||||||
|
path: ./
|
||||||
Reference in New Issue
Block a user