Skip to content

Commit 96e893c

Browse files
authored
Merge branch 'master' into 1.0.0
2 parents 7f0446e + f0ecf4f commit 96e893c

12 files changed

+190
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ settings:
3030
##### * UNIX socket configuration using YAML
3131
```
3232
settings:
33-
socket_type: tcp
33+
socket_type: unix
3434
address: socket.sock
3535
content_length: 2048
3636
```

phpunit.xml.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<phpunit bootstrap="vendor/autoload.php">
3+
<testsuites>
4+
<testsuite name="Socket unit tests">
5+
<directory>tests/unit</directory>
6+
</testsuite>
7+
</testsuites>
8+
</phpunit>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Qonsillium\Credential\SocketCredentials;
5+
6+
class SocketCredentialTest extends TestCase
7+
{
8+
public function testGetterMethodReturnsSameProperty()
9+
{
10+
$credentials = new SocketCredentials;
11+
$credentials->setCredential('host', '127.0.0.1');
12+
13+
$this->assertSame('127.0.0.1', $credentials->getCredential('host'));
14+
}
15+
16+
public function testPropertyExistenceValidatorReturnsBool()
17+
{
18+
$credentials = new SocketCredentials();
19+
$credentials->setCredential('port', '8001');
20+
$this->assertTrue(
21+
$credentials->validateExistence('port'),
22+
"SocketCredentials::validateExistence. Expected property 'port', but doesnt exists"
23+
);
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Qonsillium\Parsers\ConfigParser;
5+
use Qonsillium\Parsers\ConfigParsersFactory;
6+
7+
class ConfigParserFactory extends TestCase
8+
{
9+
public function testGetParserReturnsConfigParserInstance()
10+
{
11+
$factory = new ConfigParsersFactory(dirname(__DIR__, 1) . '/fixtures/config_tcp.json');
12+
13+
// ConfigParserFactory::getParser will always return ConfigParser instance
14+
// that's because we have a null object which contain realize interface of
15+
// ConfigParser. Even if we will pass wrong file will be returned null object
16+
$this->assertInstanceOf(
17+
ConfigParser::class,
18+
$factory->getParser(),
19+
'ConfigParserFactory::getParser, Expected type ConfigParser, but getting null'
20+
);
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Qonsillium\Parsers\ConfigParsersFactory;
5+
6+
class JSONConfigParserTest extends TestCase
7+
{
8+
public function testParseMethodReturnsArraySettings()
9+
{
10+
$factory = new ConfigParsersFactory( dirname(__DIR__, 1) . '/fixtures/config_tcp.json');
11+
$this->assertIsArray(
12+
$factory->getParser()->parse(),
13+
"JSONConfigParser::parse. Expected type 'array', but getting null"
14+
);
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Qonsillium\Parsers\ConfigParsersFactory;
5+
6+
class YAMLConfigParserTest extends TestCase
7+
{
8+
public function testParseMethodReturnsArraySettings()
9+
{
10+
$factory = new ConfigParsersFactory(dirname(__DIR__, 1) . '/fixtures/config_tcp.yaml');
11+
$this->assertIsArray(
12+
$factory->getParser()->parse(),
13+
"YAMLConfigParser::parse. Expected 'array', but getting null"
14+
);
15+
}
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Qonsillium\Parsers\ConfigParsersFactory;
5+
use Qonsillium\Types\TypeConfiguration;
6+
use Qonsillium\Types\SocketTypeFactory;
7+
use Qonsillium\Types\SocketType;
8+
9+
class SocketTypeFactoryTest extends TestCase
10+
{
11+
public function testGetSocketReturnsSocketTypeInstance()
12+
{
13+
$factorySettings = new ConfigParsersFactory(dirname(__DIR__, 1) . '/fixtures/config_tcp.yaml');
14+
$configuration = new TypeConfiguration($factorySettings->getParser()->parse()['settings']);
15+
$socketTypeFactory = new SocketTypeFactory($configuration);
16+
17+
// SocketTypeFactory::getSocket will always return SocketType instance
18+
// that's because we have a null object which contain realize interface of
19+
// SocketType. Even if we will pass wrong file will be returned null object
20+
$this->assertInstanceOf(
21+
SocketType::class,
22+
$socketTypeFactory->getSocket('tcp')
23+
);
24+
}
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Qonsillium\Parsers\ConfigParsersFactory;
5+
use Qonsillium\Types\TypeConfiguration;
6+
7+
class TypeConfigurationTest extends TestCase
8+
{
9+
public function testValidateSettingExistenceReturnsBool()
10+
{
11+
$factorySettings = new ConfigParsersFactory(dirname(__DIR__, 1) . '/fixtures/config_tcp.yaml');
12+
$configuration = new TypeConfiguration($factorySettings->getParser()->parse()['settings']);
13+
$configuration->configure();
14+
15+
$this->assertTrue(
16+
$configuration->validateSettingsExistence('domain'),
17+
"TypeConfiguration::validateSettingExistence. Setting 'domain' doesn't exists in settings list"
18+
);
19+
}
20+
21+
public function testGetConfigurationSettingReturnsSameString()
22+
{
23+
$factorySettings = new ConfigParsersFactory(dirname(__DIR__, 1) . '/fixtures/config_tcp.yaml');
24+
$configuration = new TypeConfiguration($factorySettings->getParser()->parse()['settings']);
25+
$configuration->configure();
26+
27+
$this->assertSame(
28+
'127.0.0.1',
29+
$configuration->getConfigurationSetting('host'),
30+
"TypeConfiguration::getConfigurationSetting. Expected '127.0.0.1', but got not the same string"
31+
);
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"settings": {
3+
"socket_type": "tcp",
4+
"domain": "AF_INET",
5+
"type": "SOCK_STREAM",
6+
"protocol": "SOL_TCP",
7+
"backkog": "1",
8+
"read_length": "2048",
9+
"read_flag": "MSG_WAITALL",
10+
"host": "127.0.0.1",
11+
"port": "8001"
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
settings:
2+
socket_type: tcp
3+
domain: AF_INET
4+
type: SOCK_STREAM
5+
protocol: SOL_TCP
6+
backlog: 1
7+
read_length: 2048
8+
read_flag: MSG_WAITALL
9+
host: 127.0.0.1
10+
port: 8001

0 commit comments

Comments
 (0)