mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
Add tests
This commit is contained in:
parent
5c52c51e3e
commit
df4113c226
7 changed files with 118 additions and 2 deletions
|
@ -7,3 +7,4 @@ finder:
|
||||||
- "*Stub.php"
|
- "*Stub.php"
|
||||||
path:
|
path:
|
||||||
- "src"
|
- "src"
|
||||||
|
- "tests"
|
13
.travis.yml
Normal file
13
.travis.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
language: php
|
||||||
|
|
||||||
|
php:
|
||||||
|
- 5.5
|
||||||
|
- 5.6
|
||||||
|
- 7.0
|
||||||
|
- hhvm
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- travis_retry composer self-update
|
||||||
|
- travis_retry composer install --no-interaction --prefer-source
|
||||||
|
|
||||||
|
script: phpunit --configuration phpunit.xml --coverage-text
|
|
@ -44,6 +44,9 @@
|
||||||
"zendframework/zend-version": "^2.5",
|
"zendframework/zend-version": "^2.5",
|
||||||
"monolog/monolog": "^1.18"
|
"monolog/monolog": "^1.18"
|
||||||
},
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^4.8"
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"TorrentPier\\": "src/"
|
"TorrentPier\\": "src/"
|
||||||
|
|
19
phpunit.xml
Normal file
19
phpunit.xml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<phpunit
|
||||||
|
colors="true"
|
||||||
|
bootstrap="tests/bootstrap.php"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
beStrictAboutTestsThatDoNotTestAnything="true"
|
||||||
|
beStrictAboutOutputDuringTests="true"
|
||||||
|
beStrictAboutTestSize="true">
|
||||||
|
<testsuite name="TorrentPier">
|
||||||
|
<directory suffix="Test.php">tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
<filter>
|
||||||
|
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||||
|
<directory suffix=".php">src</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
</phpunit>
|
|
@ -4,6 +4,10 @@ namespace TorrentPier;
|
||||||
|
|
||||||
use Zend\Config\Config as ZendConfig;
|
use Zend\Config\Config as ZendConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Config
|
||||||
|
* @package TorrentPier
|
||||||
|
*/
|
||||||
class Config extends ZendConfig
|
class Config extends ZendConfig
|
||||||
{
|
{
|
||||||
protected $root;
|
protected $root;
|
||||||
|
@ -43,7 +47,7 @@ class Config extends ZendConfig
|
||||||
$result = $this;
|
$result = $this;
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$result = $result->get($key);
|
$result = $result->get($key);
|
||||||
if ($result === null) {
|
if (null === $result) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +59,12 @@ class Config extends ZendConfig
|
||||||
return $this->prepareValue($result);
|
return $this->prepareValue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse value
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
protected function prepareValue($value)
|
protected function prepareValue($value)
|
||||||
{
|
{
|
||||||
if (is_string($value)) {
|
if (is_string($value)) {
|
||||||
|
|
6
tests/bootstrap.php
Normal file
6
tests/bootstrap.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
|
$autoLoader = include __DIR__ . '/../vendor/autoload.php';
|
||||||
|
$autoLoader->addPsr4('TorrentPier\\', __DIR__ . '/src');
|
64
tests/src/ConfigTest.php
Normal file
64
tests/src/ConfigTest.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TorrentPier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ConfigTest
|
||||||
|
* @package TorrentPier
|
||||||
|
*/
|
||||||
|
class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Config
|
||||||
|
*/
|
||||||
|
public $config;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'key1' => 'value1',
|
||||||
|
'key2' => [
|
||||||
|
'key3' => 'value2',
|
||||||
|
'key4' => '{self.key1}',
|
||||||
|
'key5' => '{self.key2.key4}',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->config = new Config($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \TorrentPier\Config::get
|
||||||
|
*/
|
||||||
|
public function testGet()
|
||||||
|
{
|
||||||
|
$this->assertEquals($this->config->get('key1'), 'value1');
|
||||||
|
$this->assertEquals($this->config->get('key2.key3'), 'value2');
|
||||||
|
$this->assertEquals($this->config->get('key2.key4'), 'value1');
|
||||||
|
$this->assertEquals($this->config->get('key2.key5'), 'value1');
|
||||||
|
$this->assertEquals($this->config->get('key2')->get('key3'), 'value2');
|
||||||
|
|
||||||
|
$this->assertEquals($this->config['key1'], 'value1');
|
||||||
|
$this->assertEquals($this->config['key2.key3'], 'value2');
|
||||||
|
$this->assertEquals($this->config['key2.key4'], 'value1');
|
||||||
|
$this->assertEquals($this->config['key2.key5'], 'value1');
|
||||||
|
$this->assertEquals($this->config['key2']['key3'], 'value2');
|
||||||
|
|
||||||
|
$this->assertEquals($this->config['key2.key6'], null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \TorrentPier\Config::toArray
|
||||||
|
*/
|
||||||
|
public function testToArray()
|
||||||
|
{
|
||||||
|
$this->assertEquals($this->config->toArray(), [
|
||||||
|
'key1' => 'value1',
|
||||||
|
'key2' => [
|
||||||
|
'key3' => 'value2',
|
||||||
|
'key4' => 'value1',
|
||||||
|
'key5' => 'value1',
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue