Skip to content

Commit

Permalink
Update test suite (#97)
Browse files Browse the repository at this point in the history
* Require at least php5.4 ([] is not working with php < 5.4)

* Replace tabs with 2 spaces, markTestSkipped for skipping tests, []

* Add link to travis build to travis badge

* Change assertTrue(is_numeric) to assertInternalType(numeric)
  • Loading branch information
kesselb authored and jrgp committed Sep 3, 2018
1 parent a22af50 commit 9e9c985
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 512 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Linfo - Server stats UI/library

![Travis tests](https://api.travis-ci.org/jrgp/linfo.svg)
[![Build Status](https://travis-ci.org/jrgp/linfo.svg?branch=master)](https://travis-ci.org/jrgp/linfo)


### Linfo is a:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require":{
"php":">=5.3.0",
"php":">=5.4.0",
"ext-pcre":"*"
},
"require-dev":{
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
define('LINFO_TESTING', 1);
define('LINFO_TESTDIR', dirname(__FILE__));

require_once dirname(dirname(__FILE__)).'/standalone_autoload.php';
require_once dirname(dirname(__FILE__)) . '/standalone_autoload.php';
70 changes: 35 additions & 35 deletions tests/linfo/LinfoCommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,93 @@

class CommonTest extends PHPUnit_Framework_TestCase
{
protected static $linfo;
protected static $linfo;

public static function setUpBeforeClass()
{
self::$linfo = new Linfo();
}
public static function setUpBeforeClass()
{
self::$linfo = new Linfo();
}

public static function tearDownAfterClass()
{
Common::unconfig();
}
public static function tearDownAfterClass()
{
Common::unconfig();
}

/**
* @test
*/
public function arrayAppendString()
{
$strs = array('str1', 'str2', 'str3');
$expected = array('str1_suffix', 'str2_suffix', 'str3_suffix');
$strs = ['str1', 'str2', 'str3'];
$expected = ['str1_suffix', 'str2_suffix', 'str3_suffix'];

$this->assertEquals(Common::arrayAppendString($strs, '_suffix'), $expected);
$this->assertEquals(Common::arrayAppendString($strs, '_suffix'), $expected);
}

/**
* @test
*/
public function xmlStringSanitize()
{
$this->assertEquals(Common::xmlStringSanitize('te!@#$%^st'), 'te_st');
$this->assertEquals(Common::xmlStringSanitize('te!@#$%^st'), 'te_st');
}

/**
* @test
*/
public function anyInArray()
{
$this->assertTrue(Common::anyInArray(array(1, 2, 3, 4, 5), array(5, 6, 7)));
$this->assertFalse(Common::anyInArray(array(8, 9, 10), array(11, 12, 3)));
$this->assertTrue(Common::anyInArray([1, 2, 3, 4, 5], [5, 6, 7]));
$this->assertFalse(Common::anyInArray([8, 9, 10], [11, 12, 3]));
}

/**
* @test
*/
public function locateActualPath()
{
$paths = array(
LINFO_TESTDIR.'/files/test1.txt',
LINFO_TESTDIR.'/files/test2.txt',
LINFO_TESTDIR.'/files/test3.txt',
);
$real = LINFO_TESTDIR.'/files/test2.txt';
$this->assertEquals($real, Common::locateActualPath($paths));
$paths = [
LINFO_TESTDIR . '/files/test1.txt',
LINFO_TESTDIR . '/files/test2.txt',
LINFO_TESTDIR . '/files/test3.txt',
];
$real = LINFO_TESTDIR . '/files/test2.txt';
$this->assertEquals($real, Common::locateActualPath($paths));
}

/**
* @test
*/
public function getIntFromFile()
{
$file = LINFO_TESTDIR.'/files/intfile.txt';
$this->assertEquals(101, Common::getIntFromFile($file));
$file = LINFO_TESTDIR . '/files/intfile.txt';
$this->assertEquals(101, Common::getIntFromFile($file));
}

/**
* @test
*/
public function getVarFromFile()
{
$file = LINFO_TESTDIR.'/files/varfile.php';
$this->assertEquals('foo', Common::getVarFromFile($file, 'var'));
$file = LINFO_TESTDIR . '/files/varfile.php';
$this->assertEquals('foo', Common::getVarFromFile($file, 'var'));
}

/**
* @test
*/
public function byteConvert()
{
$this->assertEquals('1000 KiB', Common::byteConvert(1024000));
$this->assertEquals('1 GiB', Common::byteConvert(1073741824));
$this->assertEquals('1000 KiB', Common::byteConvert(1024000));
$this->assertEquals('1 GiB', Common::byteConvert(1073741824));
}

/**
* @test
*/
public function secondsConvert()
{
// this is incorrect
// this is incorrect
$this->assertEquals('4 days, 4 hours, 30 seconds', Common::secondsConvert(360000));

// this says '1 hours, 30 seconds' instead. need to find out why...
Expand All @@ -103,18 +103,18 @@ public function secondsConvert()
*/
public function getContents()
{
$contents = "lineone\nlinetwo\nline3";
$file = LINFO_TESTDIR.'/files/lines.txt';
$this->assertEquals($contents, Common::getContents($file));
$contents = "lineone\nlinetwo\nline3";
$file = LINFO_TESTDIR . '/files/lines.txt';
$this->assertEquals($contents, Common::getContents($file));
}

/**
* @test
*/
public function getLines()
{
$lines = array("lineone\n", "linetwo\n", "line3\n");
$file = LINFO_TESTDIR.'/files/lines.txt';
$this->assertEquals($lines, Common::getLines($file));
$lines = ["lineone\n", "linetwo\n", "line3\n"];
$file = LINFO_TESTDIR . '/files/lines.txt';
$this->assertEquals($lines, Common::getLines($file));
}
}
14 changes: 7 additions & 7 deletions tests/linfo/LinfoErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class ErrorTest extends PHPUnit_Framework_TestCase
*/
public function add()
{
Errors::add('testing', 'testing 123');
Errors::add('testing', 'testing 456');
$this->assertCount(2, Errors::show());
Errors::add('testing', 'testing 123');
Errors::add('testing', 'testing 456');
$this->assertCount(2, Errors::show());
}

public function tearDown()
{
Errors::clear();
}
public function tearDown()
{
Errors::clear();
}
}
32 changes: 16 additions & 16 deletions tests/linfo/LinfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,64 @@

class LinfoTest extends PHPUnit_Framework_TestCase
{
protected static $linfo;
protected static $linfo;

public static function setUpBeforeClass()
{
self::$linfo = new Linfo();
}
public static function setUpBeforeClass()
{
self::$linfo = new Linfo();
}

public static function tearDownAfterClass()
{
self::$linfo = null;
Common::unconfig();
}
public static function tearDownAfterClass()
{
self::$linfo = null;
Common::unconfig();
}

/**
* @test
*/
public static function getLang()
{
self::assertInternalType('array', self::$linfo->getLang());
self::assertInternalType('array', self::$linfo->getLang());
}

/**
* @test
*/
public static function getSettings()
{
self::assertInternalType('array', self::$linfo->getSettings());
self::assertInternalType('array', self::$linfo->getSettings());
}

/**
* @test
*/
public static function getAppName()
{
self::assertInternalType('string', self::$linfo->getAppName());
self::assertInternalType('string', self::$linfo->getAppName());
}

/**
* @test
*/
public static function getVersion()
{
self::assertInternalType('string', self::$linfo->getVersion());
self::assertInternalType('string', self::$linfo->getVersion());
}

/**
* @test
*/
public static function getTimeStart()
{
self::assertTrue(is_float(self::$linfo->getTimeStart()));
self::assertTrue(is_float(self::$linfo->getTimeStart()));
}

/**
* @test
*/
public static function getParser()
{
self::assertInstanceOf('\\Linfo\\OS\\OS', self::$linfo->getParser());
self::assertInstanceOf('\\Linfo\\OS\\OS', self::$linfo->getParser());
}
}
20 changes: 10 additions & 10 deletions tests/linfo/LinfoTimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

class LinfoTimerTest extends PHPUnit_Framework_TestCase
{
/**
/**
* @test
*/
public function runTimers()
{
$t1 = new Timer('test1');
unset($t1);
$t2 = new Timer('test2');
unset($t2);
$this->assertCount(2, Timer::getResults());
$t1 = new Timer('test1');
unset($t1);
$t2 = new Timer('test2');
unset($t2);
$this->assertCount(2, Timer::getResults());
}

public function tearDown()
{
Timer::clear();
}
public function tearDown()
{
Timer::clear();
}
}
Loading

0 comments on commit 9e9c985

Please sign in to comment.