Skip to content

Commit

Permalink
Tidy repo (#91)
Browse files Browse the repository at this point in the history
* Tidy repo

* Use versioned action
  • Loading branch information
inverse authored Feb 22, 2024
1 parent 06091e1 commit 218a923
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@master
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@master
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
- name: Install dependencies
Expand All @@ -27,7 +27,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@master
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- name: Install dependencies
Expand All @@ -39,7 +39,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@master
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- name: Install dependencies
Expand Down
7 changes: 5 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

use Inverse\Termin\Config\ConfigParser;
use Inverse\Termin\Container;
use Symfony\Component\Yaml\Yaml;

require __DIR__.'/vendor/autoload.php';

$configLoader = new ConfigParser();
$config = $configLoader->parse(Yaml::parseFile(__DIR__ . '/config.yml'));
$config = $configLoader->parse(Yaml::parseFile(__DIR__.'/config.yml'));

$container = new Container($config);

Expand Down
7 changes: 0 additions & 7 deletions index.php

This file was deleted.

2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ parameters:
- %currentWorkingDirectory%/tests
excludePaths:
- %currentWorkingDirectory%/src/Container.php
level: 7
level: 8
checkMissingIterableValueType: false
17 changes: 9 additions & 8 deletions serverless.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<?php


declare(strict_types=1);

use Bref\Context\Context;
use Inverse\Termin\Config\ConfigParser;
use Inverse\Termin\Container;
use Symfony\Component\Yaml\Yaml;

require __DIR__.'/vendor/autoload.php';


class Handler implements \Bref\Event\Handler
class Handler implements Bref\Event\Handler
{
public function handle($event, Context $context)
{
$configLoader = new ConfigParser();
$config = $configLoader->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();
36 changes: 28 additions & 8 deletions tests/Config/ConfigParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 218a923

Please sign in to comment.