diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 4199fa7..c5631c0 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,8 +2,11 @@ declare(strict_types=1); -$finder = PhpCsFixer\Finder::create() - ->in(['src', 'tests']) +$finder = (new PhpCsFixer\Finder()) + ->in(__DIR__) + ->exclude([ + 'node_modules', + ]) ; $config = new PhpCsFixer\Config(); diff --git a/README.md b/README.md index 9165bf9..f41e824 100644 --- a/README.md +++ b/README.md @@ -199,14 +199,17 @@ _Note: Don't set the schedule frequency to high to not overload their website_ ## Run (serverless) -Termin can also be run as a serverless application. Configure the application like you would normally. +Termin can also be run as a serverless application. Configure the application like you would like any other way. -Then configure your environment with [serverless tooling][9]. +Install serverless toolchain: ```bash npm install ``` +Then configure your environment with [serverless tooling][9]. + + And finally deploy: ```bash diff --git a/app.php b/app.php index 500438a..5e1e664 100644 --- a/app.php +++ b/app.php @@ -1,5 +1,7 @@ parse(Yaml::parseFile(__DIR__ . '/config.yml')); +$config = $configLoader->parse(Yaml::parseFile(__DIR__.'/config.yml')); $container = new Container($config); diff --git a/index.php b/index.php deleted file mode 100644 index 346496c..0000000 --- a/index.php +++ /dev/null @@ -1,7 +0,0 @@ -parse(Yaml::parseFile(__DIR__ . '/config.yml')); - + $config = $configLoader->parse(Yaml::parseFile(__DIR__.'/config.yml')); + $container = new Container($config, 'serverless'); - + $termin = $container->getTermin(); $termin->run($config->getSites()); - + return 'OK'; } } - + return new Handler(); diff --git a/tests/Config/ConfigParserTest.php b/tests/Config/ConfigParserTest.php index 34312e3..1a0e3c8 100644 --- a/tests/Config/ConfigParserTest.php +++ b/tests/Config/ConfigParserTest.php @@ -89,7 +89,7 @@ public function testParseValid(): void $config = $this->configParser->parse($this->getBasicConfig()); self::assertCount(1, $config->getSites()); - self::assertEquals($config->getSites()[0]->getLabel(), 'Important'); + self::assertEquals('Important', $config->getSites()[0]->getLabel()); self::assertEquals(['param_1' => 'value_1'], $config->getSites()[0]->getParams()); self::assertFalse($config->isAllowMultipleNotifications()); self::assertNull($config->getTelegram()); @@ -120,8 +120,13 @@ public function testParseNtfyValidDefaultServer(): void ], ]); - self::assertEquals($config->getNtfy()->getServer(), Ntfy::DEFAULT_SERVER); - self::assertEquals($config->getNtfy()->getTopic(), 'termin_fun'); + $ntfy = $config->getNtfy(); + if (null === $ntfy) { + self::fail('Ntfy config must not be null'); + } + + self::assertEquals(Ntfy::DEFAULT_SERVER, $ntfy->getServer()); + self::assertEquals('termin_fun', $ntfy->getTopic()); } public function testParseNtfyValid(): void @@ -133,8 +138,13 @@ public function testParseNtfyValid(): void ], ]); - self::assertEquals($config->getNtfy()->getServer(), 'https://my-server.com'); - self::assertEquals($config->getNtfy()->getTopic(), 'termin_fun'); + $ntfy = $config->getNtfy(); + if (null === $ntfy) { + self::fail('Ntfy config must not be null'); + } + + self::assertEquals('https://my-server.com', $ntfy->getServer()); + self::assertEquals('termin_fun', $ntfy->getTopic()); } public function testParseTelegramEmpty(): void @@ -202,8 +212,13 @@ public function testParseTelegramValid(): void ], ]); - self::assertEquals($config->getTelegram()->getApiKey(), 'api'); - self::assertEquals($config->getTelegram()->getChatId(), 1); + $telegram = $config->getTelegram(); + if (null === $telegram) { + self::fail('Telegram config must not be null'); + } + + self::assertEquals('api', $telegram->getApiKey()); + self::assertEquals(1, $telegram->getChatId()); } public function testParsePushbulletEmpty(): void @@ -235,7 +250,12 @@ public function testParsePushbulletValid(): void ], ]); - self::assertEquals($config->getPushbullet()->getApiToken(), 'token'); + $pushbullet = $config->getPushbullet(); + if (null === $pushbullet) { + self::fail('Pushbullet config must not be null'); + } + + self::assertEquals('token', $pushbullet->getApiToken()); } public function testParseRulesNotArray(): void