Skip to content

Commit

Permalink
Fix & update travis config (#31)
Browse files Browse the repository at this point in the history
* fix & update travis config

* fixing tests

* fixing tests, part 2

* fixing tests that fail in 7.1

* restoring prior version constraint for phpunit; should work fine

* fixed warnings about protected static function

* fixed test that broke clover; $_SERVER should never be tampered with
  • Loading branch information
garrettw authored and gjerokrsteski committed Sep 11, 2017
1 parent d85537a commit 0a1d4e1
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 73 deletions.
20 changes: 7 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1

sudo: false

matrix:
include:
- php: 5.5.9
env: setup=lowest
- php: 5.5.9
env: setup=stable
- php: 7.0
env: setup=stable
allow_failures:
- php: 5.6
- php: 7.0
- php: 7.1
fast_finish: true

install:
- composer install

script:
- phpunit --configuration phpunit.xml --coverage-clover=coverage.clover
- vendor/bin/phpunit --coverage-clover=coverage.clover

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --access-token="53c569dececa0578c84587178c5f08e25df8c6e42c37bd313bf0802d2cf74a71" --format=php-clover coverage.clover

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
"php" : ">=5.6"
},
"require-dev" : {
"phpunit/phpunit" : "5.5"
"phpunit/phpunit" : "^5.5"
}
}
2 changes: 1 addition & 1 deletion core/Pimf/Cache/Storages/Dba.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function put($key, $value, $minutes)
return;
}

$value = self::expiration($minutes) . serialize($value);
$value = $this->expiration($minutes) . serialize($value);

if (true === $this->has($key)) {
return dba_replace($key, $value, $this->dba);
Expand Down
2 changes: 1 addition & 1 deletion core/Pimf/Cache/Storages/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function put($key, $value, $minutes)
return null;
}

$value = self::expiration($minutes) . serialize($value);
$value = $this->expiration($minutes) . serialize($value);

return file_put_contents($this->path . $key, $value, LOCK_EX);
}
Expand Down
2 changes: 1 addition & 1 deletion core/Pimf/Cache/Storages/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function put($key, $value, $minutes)
{
$key = $this->key . $key;
$value = serialize($value);
$expiration = self::expiration($minutes);
$expiration = $this->expiration($minutes);

try {
$sth = $this->pdo->prepare(
Expand Down
2 changes: 1 addition & 1 deletion core/Pimf/Cache/Storages/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function offsetUnset($key)
*
* @return int
*/
protected static function expiration($minutes)
public function expiration($minutes)
{
return time() + ($minutes * 60);
}
Expand Down
2 changes: 1 addition & 1 deletion core/Pimf/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected function parse($response)
*
* @return resource
*/
protected function connect()
public function connect()
{
if (!is_null($this->connection)) {
return $this->connection;
Expand Down
3 changes: 2 additions & 1 deletion core/Pimf/Util/Uploaded.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ public static function getMaxFilesize()
}

$unit = strtolower(substr($max, -1));
$max = (int)substr($max, 0, -1);

if (in_array($unit, array('g', 'm', 'k'), true)) {
$max *= 1024;
}

return (int)$max;
return $max;
}
}
19 changes: 12 additions & 7 deletions tests/Pimf/Cache/PdoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ public function testValueIsReturned()
'key.'
))->getMock();

$cache->expects($this->any())->method('retrieve')->with('foo')->will($this->returnValue(serialize('foo')));
$cache->expects($this->any())->method('get')->with('foo')->will($this->returnValue(serialize('foo')));

$this->assertNull($cache->get('foo'));
$this->assertNotNull($cache->get('foo'));

}

public function testSetMethodProperlyCallsPdo()
{
$store = $this->getStore();

$store->expects($this->any())->method('expiration')->with(60 * 60);
$cache = $this->getMockBuilder('\Pimf\Cache\Storages\Pdo')->setConstructorArgs(array(
$store,
'key.'
))->getMock();

$cache = new \Pimf\Cache\Storages\Pdo($store, 'key.');
$cache->expects($this->any())->method('expiration')->with(60 * 60);

$cache->put('foo', 'foo', 60);
}
Expand All @@ -65,9 +68,12 @@ public function testSetMethodProperlyCallsPdoForNumerics()
{
$store = $this->getStore();

$store->expects($this->any())->method('expiration')->with(60 * 60);
$cache = $this->getMockBuilder('\Pimf\Cache\Storages\Pdo')->setConstructorArgs(array(
$store,
'key.'
))->getMock();

$cache = new \Pimf\Cache\Storages\Pdo($store, 'key.');
$cache->expects($this->any())->method('expiration')->with(60 * 60);

$cache->put('foo', 1, 60);
}
Expand All @@ -90,4 +96,3 @@ public function testForgetMethodProperlyCallsRedis()
$cache->forget('foo');
}
}

3 changes: 1 addition & 2 deletions tests/Pimf/Cache/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected function getRedis()
{
return $this->getMockBuilder('\\Pimf\\Redis')->disableOriginalConstructor()
->setMethods(
array('get', 'expire', 'set', 'del', 'forget', 'select', 'put', 'inline', 'bulk', 'multibulk')
array('connect', 'get', 'expire', 'set', 'del', 'forget', 'select', 'put', 'inline', 'bulk', 'multibulk')
)->getMock();
}

Expand Down Expand Up @@ -116,4 +116,3 @@ public function testForgetMethodProperlyCallsRedis()
}

}

70 changes: 28 additions & 42 deletions tests/Pimf/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,10 @@ public function testTokenMethodReturnsCSRFToken()
public function testSaveMethodSweepsIfCleanerAndOddsHitWithTimeGreaterThanThreshold()
{
$payload = $this->getPayload();
$payload->storage = $this->getMock(
'\\Pimf\\Session\\Storages\\File', array(
'save',
'clean'
), array(null)
);
$payload->storage = $this->getMockBuilder('\\Pimf\\Session\\Storages\\File')
->setConstructorArgs(array(null))
->setMethods(array('save','clean'))
->getMock();

$payload->session = $this->getSession();
$expiration = time() - (\Pimf\Config::get('session.lifetime') * 60);
Expand All @@ -308,12 +306,10 @@ public function testSaveMethodSweepsIfCleanerAndOddsHitWithTimeGreaterThanThresh
public function testSaveMethodSweepsIfCleanerAndOddsHitWithTimeLessThanThreshold()
{
$payload = $this->getPayload();
$payload->storage = $this->getMock(
'\\Pimf\\Session\\Storages\\File', array(
'save',
'clean'
), array(null)
);
$payload->storage = $this->getMockBuilder('\\Pimf\\Session\\Storages\\File')
->setConstructorArgs(array(null))
->setMethods(array('save','clean'))
->getMock();

$payload->session = $this->getSession();
$expiration = time() - (\Pimf\Config::get('session.lifetime') * 60);
Expand All @@ -331,12 +327,10 @@ public function testSaveMethodSweepsIfCleanerAndOddsHitWithTimeLessThanThreshold
public function testCleanerShouldntBeCalledIfStorageIsntCleaner()
{
$payload = $this->getPayload();
$payload->storage = $this->getMock(
'\\Pimf\\Session\\Storages\\Apc', array(
'save',
'clean'
), array(), '', false
);
$payload->storage = $this->getMockBuilder('\\Pimf\\Session\\Storages\\Apc')
->disableOriginalConstructor()
->setMethods(array('save','clean'))
->getMock();

$payload->session = $this->getSession();
$payload->storage->expects($this->never())->method('clean');
Expand All @@ -349,12 +343,10 @@ public function testCleanerShouldntBeCalledIfStorageIsntCleaner()
public function testCleanerShouldntBeCalledIfMemoryStorageIsntCleaner()
{
$payload = $this->getPayload();
$payload->storage = $this->getMock(
'\\Pimf\\Session\\Storages\\Memory', array(
'save',
'clean'
), array(), '', false
);
$payload->storage = $this->getMockBuilder('\\Pimf\\Session\\Storages\\Memory')
->disableOriginalConstructor()
->setMethods(array('save','clean'))
->getMock();

$payload->session = $this->getSession();
$payload->storage->expects($this->never())->method('clean');
Expand All @@ -367,12 +359,10 @@ public function testCleanerShouldntBeCalledIfMemoryStorageIsntCleaner()
public function testCleanerShouldntBeCalledIfCookieStorageIsntCleaner()
{
$payload = $this->getPayload();
$payload->storage = $this->getMock(
'\\Pimf\\Session\\Storages\\Cookie', array(
'save',
'clean'
), array(), '', false
);
$payload->storage = $this->getMockBuilder('\\Pimf\\Session\\Storages\\Cookie')
->disableOriginalConstructor()
->setMethods(array('save','clean'))
->getMock();

$payload->session = $this->getSession();
$payload->storage->expects($this->never())->method('clean');
Expand All @@ -385,12 +375,10 @@ public function testCleanerShouldntBeCalledIfCookieStorageIsntCleaner()
public function testCleanerShouldntBeCalledIfMemcachedStorageIsntCleaner()
{
$payload = $this->getPayload();
$payload->storage = $this->getMock(
'\\Pimf\\Session\\Storages\\Memcached', array(
'save',
'clean'
), array(), '', false
);
$payload->storage = $this->getMockBuilder('\\Pimf\\Session\\Storages\\Memcached')
->disableOriginalConstructor()
->setMethods(array('save','clean'))
->getMock();

$payload->session = $this->getSession();
$payload->storage->expects($this->never())->method('clean');
Expand All @@ -403,12 +391,10 @@ public function testCleanerShouldntBeCalledIfMemcachedStorageIsntCleaner()
public function testCleanerShouldntBeCalledIfRedisStorageIsntCleaner()
{
$payload = $this->getPayload();
$payload->storage = $this->getMock(
'\\Pimf\\Session\\Storages\\Redis', array(
'save',
'clean'
), array(), '', false
);
$payload->storage = $this->getMockBuilder('\\Pimf\\Session\\Storages\\Redis')
->disableOriginalConstructor()
->setMethods(array('save','clean'))
->getMock();

$payload->session = $this->getSession();
$payload->storage->expects($this->never())->method('clean');
Expand Down
4 changes: 2 additions & 2 deletions tests/Pimf/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public function tearDown()

protected function fakeUri($uri)
{
$_SERVER = array('REQUEST_URI' => $uri, 'SCRIPT_NAME' => __FILE__, 'PATH_INFO' => $uri);
self::$env = new \Pimf\Environment($_SERVER);
$server = array('REQUEST_URI' => $uri, 'SCRIPT_NAME' => __FILE__, 'PATH_INFO' => $uri);
self::$env = new \Pimf\Environment($server);
$envData = self::$env->data();

\Pimf\Util\Header\ResponseStatus::setup($envData->get('SERVER_PROTOCOL', 'HTTP/1.0'));
Expand Down

0 comments on commit 0a1d4e1

Please sign in to comment.