Add some semblance of testing.

This commit is contained in:
2019-03-13 16:07:54 +01:00
parent 8e669e62f3
commit dd6baeff09
4 changed files with 46 additions and 2 deletions

View File

@@ -14,11 +14,17 @@
},
"require-dev": {
"phpro/grumphp": "^0.15.0",
"friendsofphp/php-cs-fixer": "^2.14"
"friendsofphp/php-cs-fixer": "^2.14",
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
"FooBar\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"FooBar\\tests\\": "tests"
}
}
}

View File

@@ -3,4 +3,5 @@ parameters:
bin_dir: vendor/bin
tasks:
phpcsfixer2:
config: .php_cs
config: .php_cs
phpunit: ~

8
phpunit.xml Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd">
<testsuite name="main">
<directory>tests</directory>
</testsuite>
</phpunit>

View File

@@ -0,0 +1,29 @@
<?php
namespace tests\FooBar;
use FooBar\Configuration;
use PHPUnit\Framework\TestCase;
class ConfigurationTest extends TestCase
{
public function testDefaultSecurity()
{
$config = $this->getSampleConfig();
$this->assertTrue($config->isAuthorized('127.0.0.1'));
$this->assertFalse($config->isAuthorized('8.8.8.8'));
}
public function testLoadConfig()
{
$this->assertNotNull(Configuration::loadConfig());
}
private function getSampleConfig(): Configuration
{
$path = dirname(__DIR__) . '/config/config.sample.php';
return new Configuration(require $path);
}
}