Skip to content

Commit

Permalink
Fixed Cut converter raising index out of bounds error and added CutTest.
Browse files Browse the repository at this point in the history
Fixed DualConverter::convertCollection not accepting arrays.
Added Coveralls support to Travis settings.
Added architecture diagram to README.
Reorganized tests into test type directories.
  • Loading branch information
Bilge committed Aug 17, 2014
1 parent 45b83cd commit 5399cd0
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 13 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Expand Up @@ -5,11 +5,15 @@ php:
- 5.6

install:
- composer --no-interaction install
- composer -n require satooshi/php-coveralls:dev-master

script:
- vendor/bin/phpunit --coverage-clover=clover.xml test
- vendor/bin/phpunit --coverage-clover=build/logs/clover.xml test

after_script:
# Scrutinizer coverage.
- wget http://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover clover.xml
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml

# Coveralls coverage.
- vendor/bin/coveralls
12 changes: 8 additions & 4 deletions README.md
@@ -1,17 +1,21 @@
Open Dash
=========

![Version][Version image]
[![Version][Version image]]()
[![Build Status][Build image]][Build]
[![Code Coverage][Coverage image]][Coverage]
[![Scrutinizer Code Quality][Quality image]][Quality]

Open source Web-based dashboard for Unix systems.

Architecture
------------
![Diagram](https://raw.githubusercontent.com/ScriptFUSION/Open-Dash/master/diagrams/Open%20Dash.png)

[Version image]: http://img.shields.io/github/tag/ScriptFUSION/Open-Dash.svg "Latest version"
[Build]: http://travis-ci.org/ScriptFUSION/Open-Dash
[Build image]: http://img.shields.io/travis/ScriptFUSION/Open-Dash.svg
[Coverage]: https://scrutinizer-ci.com/g/ScriptFUSION/Open-Dash/?branch=master
[Coverage image]: https://scrutinizer-ci.com/g/ScriptFUSION/Open-Dash/badges/coverage.png?b=master "Code coverage"
[Build image]: http://img.shields.io/travis/ScriptFUSION/Open-Dash.svg "Build status"
[Coverage]: https://coveralls.io/r/ScriptFUSION/Open-Dash
[Coverage image]: https://img.shields.io/coveralls/ScriptFUSION/Open-Dash.svg "Code coverage"
[Quality]: https://scrutinizer-ci.com/g/ScriptFUSION/Open-Dash/?branch=master
[Quality image]: https://scrutinizer-ci.com/g/ScriptFUSION/Open-Dash/badges/quality-score.png?b=master "Code quality"
8 changes: 7 additions & 1 deletion src/Convert/Cut.php
Expand Up @@ -19,6 +19,12 @@ public function __construct($fields, $delimiter = "\t") {
* @return string
*/
public function convertString($string) {
return explode($this->delimiter, $string)[$this->fields - 1];
$parts = explode($this->delimiter, $string);
$field = $this->fields - 1;

if (isset($parts[$field]))
return $parts[$field];

return '';
}
}
4 changes: 2 additions & 2 deletions src/Convert/DualConverter.php
Expand Up @@ -25,10 +25,10 @@ public function convert($data) {
abstract public function convertString($string);

/**
* @param \Traversable $items
* @param \Traversable|array $items
* @return \Iterator
*/
public function convertCollection(\Traversable $items) {
public function convertCollection($items) {
return \iter\map([$this, 'convertString'], $items);
}
}
2 changes: 2 additions & 0 deletions src/DataProvider/DataProvider.php
@@ -1,6 +1,8 @@
<?php
namespace ScriptFUSION\OpenDash\DataProvider;

use ScriptFUSION\OpenDash\Data\Data;

/**
* Defines a mechanism for providing data.
*/
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -3,7 +3,8 @@
use ScriptFUSION\OpenDash\DataProvider\System\ApacheVersion;

class ApacheVersionTest extends PHPUnit_Framework_TestCase {
public function testFilters() {
public function testConverters() {
/** @var ApacheVersion $apacheVersion */
$apacheVersion = Mockery::mock(ApacheVersion::class, [])->makePartial()->shouldReceive(
['execute' => new SystemData(
"Server version: Apache/1.2.34 (Unix)\nServer built: Jan 01 1970 00:00:00\n"
Expand Down
@@ -1,8 +1,8 @@
<?php
use ScriptFUSION\OpenDash\Convert\ConversionChain;

class FilterChainTest extends PHPUnit_Framework_TestCase {
public function testFilterChain() {
class ConversionChainTest extends PHPUnit_Framework_TestCase {
public function testConvert() {
$chain = (new ConversionChain)->addConverters([
function() { return 'foo'; },
function($data) { return "${data}bar"; }
Expand Down
21 changes: 21 additions & 0 deletions test/unit/CutTest.php
@@ -0,0 +1,21 @@
<?php
use ScriptFUSION\OpenDash\Convert\Cut;

class CutTest extends PHPUnit_Framework_TestCase {
/** @dataProvider provideData */
public function test($data, $fields, $delimiter, $result) {
$this->assertSame($result, (new Cut($fields, $delimiter))->convert($data));
}

public function provideData() {
return [
["foo\tbar", 0, "\t", ''],
["foo\tbar", 1, "\t", 'foo'],
["foo\tbar", 2, "\t", 'bar'],
["foo\tbar", 3, "\t", ''],
['foo bar', 1, ' ', 'foo'],
['foo bar', 2, ' ', ''],
['foo bar', 3, ' ', 'bar'],
];
}
}

0 comments on commit 5399cd0

Please sign in to comment.