Skip to content

Commit

Permalink
Merge pull request #406 from tedious/test_upgrades
Browse files Browse the repository at this point in the history
Use Github Actions instead of Travis CI for testing
  • Loading branch information
tedivm authored Feb 21, 2022
2 parents 083bdf5 + 9ab216c commit e43b486
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 942 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pr_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on: [push]
env:
IS_GITHUB: "true"

jobs:
phpunit:
strategy:
fail-fast: false
matrix:
php_version: ["8.0", "8.1", "latest"]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Start Redis on Default Port
uses: supercharge/[email protected]
with:
redis-port: 6379


# - name: Start 2nd Redis Server on 6380
# uses: supercharge/[email protected]
# with:
# redis-port: 6380

# These are the versions of the *actions*, not the libraries.
- name: Install PHP Packages
uses: php-actions/composer@v5

- name: Run Tests
uses: php-actions/phpunit@v3
with:
php_version: ${{ matrix.php_version }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/build

.php_cs.cache
.phpunit.result.cache
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
"require-dev": {
"php": "^7.2|^8.0",
"friendsofphp/php-cs-fixer": "^2.8",
"phpunit/phpunit": "^8.0",
"php-coveralls/php-coveralls": "^2.0"
"phpunit/phpunit": "^9.0",
"php-coveralls/php-coveralls": "^2.0",
"dms/phpunit-arraysubset-asserts": "^0.4.0"
},
"autoload": {
"psr-4": {
"Stash\\": "src/Stash/"
}
},
"provide": {
"psr/cache-implementation": "1.0.0"
"psr/cache-implementation": "1.0.0"
}
}
31 changes: 15 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Stash Test Suite">
<directory suffix="Test.php">./tests/Stash/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/Stash/</directory>
<exclude>
<directory>./src/Stash/Exception</directory>
<directory>./src/Stash/Interfaces</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src/Stash/</directory>
</include>
<exclude>
<directory>./src/Stash/Exception</directory>
<directory>./src/Stash/Interfaces</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Stash Test Suite">
<directory suffix="Test.php">./tests/Stash/</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/Stash/Driver/Sub/SqlitePdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected function setTimeout($milliseconds)
{
$driver = $this->getDriver();
$timeout = ceil($milliseconds / 1000);
$driver->setAttribute(\PDO::ATTR_TIMEOUT, $timeout);
$driver->setAttribute(\PDO::ATTR_TIMEOUT, (int) $timeout);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/Stash/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Session implements \SessionHandlerInterface
* @param \Stash\Session $handler
* @return bool
*/
public static function registerHandler(Session $handler)
public static function registerHandler(Session $handler): bool
{
// this isn't possible to test with the CLI phpunit test
// @codeCoverageIgnoreStart
Expand Down Expand Up @@ -114,7 +114,7 @@ public function __construct(PoolInterface $pool)
* @param array $options
* @return bool
*/
public function setOptions($options = array())
public function setOptions($options = array()) : void
{
$this->options = array_merge($this->options, $options);
}
Expand All @@ -133,7 +133,7 @@ public function setOptions($options = array())
* @param string $session_name
* @return bool
*/
public function open($save_path, $session_name)
public function open($save_path, $session_name) : bool
{
if (isset($save_path) && $save_path !== '') {
$this->path = $save_path;
Expand All @@ -147,7 +147,7 @@ public function open($save_path, $session_name)
}


protected function getCache($session_id)
protected function getCache($session_id) : \Stash\Item
{
$path = '/' .
base64_encode($this->path) . '/' .
Expand All @@ -164,7 +164,7 @@ protected function getCache($session_id)
* @param string $session_id
* @return string
*/
public function read($session_id)
public function read($session_id) : string
{
$cache = $this->getCache($session_id);
$data = $cache->get();
Expand All @@ -180,7 +180,7 @@ public function read($session_id)
* @param string $session_data
* @return bool
*/
public function write($session_id, $session_data)
public function write($session_id, $session_data) : bool
{
$cache = $this->getCache($session_id);

Expand All @@ -194,7 +194,7 @@ public function write($session_id, $session_data)
*
* @return bool
*/
public function close()
public function close() : bool
{
return true;
}
Expand All @@ -206,7 +206,7 @@ public function close()
* @param string $session_id
* @return bool
*/
public function destroy($session_id)
public function destroy($session_id) : bool
{
$cache = $this->getCache($session_id);

Expand All @@ -226,7 +226,7 @@ public function destroy($session_id)
* @param int $maxlifetime
* @return bool
*/
public function gc($maxlifetime)
public function gc($maxlifetime) : int|false
{
return $this->pool->purge();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Stash/Test/AbstractItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @todo find out why this has to be abstract to work (see https://github.com/tedivm/Stash/pull/10)
*/
abstract class AbstractItemTest extends \PHPUnit\Framework\TestCase
abstract class AbstractItemTest extends AbstractTest
{
protected $data = array('string' => 'Hello world!',
'complexString' => "\t\t\t\tHello\r\n\rWorld!",
Expand Down Expand Up @@ -335,11 +335,11 @@ public function testExpiresAt()
}

/**
* @expectedException Stash\Exception\InvalidArgumentException
* @expectedExceptionMessage expiresAt requires \DateTimeInterface or null
*/
public function testExpiresAtException()
{
$this->expectException('InvalidArgumentException');
$stash = $this->testConstruct(array('base', 'expiration', 'test'));
$stash->expiresAt(false);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Stash/Test/AbstractPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @package Stash
* @author Robert Hafner <[email protected]>
*/
class AbstractPoolTest extends \PHPUnit\Framework\TestCase
class AbstractPoolTest extends AbstractTest
{
protected $data = array(array('test', 'test'));
protected $multiData = array('key' => 'value',
Expand Down Expand Up @@ -172,11 +172,11 @@ public function testCommit()


/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid or Empty Node passed to getItem constructor.
*/
public function testGetItemInvalidKeyMissingNode()
{
$this->expectException('InvalidArgumentException');
$pool = $this->getTestPool();
$item = $pool->getItem('This/Test//Fail');
}
Expand Down Expand Up @@ -277,11 +277,11 @@ public function testNamespacing()
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Namespace must be alphanumeric.
*/
public function testInvalidNamespace()
{
$this->expectException('InvalidArgumentException');
$pool = $this->getTestPool();
$pool->setNamespace('!@#$%^&*(');
}
Expand Down
46 changes: 46 additions & 0 deletions tests/Stash/Test/AbstractTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Stash package.
*
* (c) Robert Hafner <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Stash\Test;

use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;

/**
* @package Stash
* @author Robert Hafner <[email protected]>
*/
abstract class AbstractTest extends \PHPUnit\Framework\TestCase
{
use ArraySubsetAsserts;

public function accessProtected($obj, $prop) {
$reflection = new \ReflectionClass($obj);
$property = $reflection->getProperty($prop);
$property->setAccessible(true);
return $property->getValue($obj);
}

public function assertAttributeEquals($expectedValue, $actualAttributeName, $object, $errorMessage="") {
$actualValue = $this->accessProtected($object, $actualAttributeName);
return $this->assertSame($expectedValue, $actualValue, $errorMessage);
}

public function assertAttributeInstanceOf($expectedClass, $actualAttributeName, $object, $errorMessage="") {
$actualValue = $this->accessProtected($object, $actualAttributeName);
return $this->assertInstanceOf($expectedClass, $actualValue);
}

public function assertAttributeInternalType($expectedType, $actualAttributeName, $object, $errorMessage="") {
$actualValue = $this->accessProtected($object, $actualAttributeName);
return $this->assertSame($expectedType, gettype($actualValue), $errorMessage);
}

}
2 changes: 1 addition & 1 deletion tests/Stash/Test/Driver/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @package Stash
* @author Robert Hafner <[email protected]>
*/
abstract class AbstractDriverTest extends \PHPUnit\Framework\TestCase
abstract class AbstractDriverTest extends \Stash\Test\AbstractTest
{
protected $data = array('string' => 'Hello world!',
'complexString' => "\t\tHello\r\n\r\'\'World!\"\'\\",
Expand Down
13 changes: 3 additions & 10 deletions tests/Stash/Test/Driver/CompositeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,21 @@ public function testIsPersistent()
$this->assertFalse($driver->isPersistent());
}


/**
* @expectedException Stash\Exception\RuntimeException
*/
public function testWithoutDriversException()
{
$this->expectException('RuntimeException');
$driver = new Composite(array('drivers' => null));
}

/**
* @expectedException Stash\Exception\RuntimeException
*/
public function testWithFakeDriversException()
{
$this->expectException('RuntimeException');
$driver = new Composite(array('drivers' => array('fakedriver')));
}

/**
* @expectedException Stash\Exception\InvalidArgumentException
*/
public function testWithBadDriverArgumentException()
{
$this->expectException('InvalidArgumentException');
$driver = new Composite(array('drivers' => 'fakedriver'));
}
}
8 changes: 2 additions & 6 deletions tests/Stash/Test/Driver/EphemeralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ public function testKeyCollisions2()
$this->assertEquals('X', $item1->get());
}

/**
* @expectedException \Stash\Exception\InvalidArgumentException
*/
public function testSettingMaxItems_InvalidArgument_Throws()
{
$this->expectException('InvalidArgumentException');
/**
* @var \Stash\Driver\Ephemeral
*/
Expand All @@ -74,11 +72,9 @@ public function testSettingMaxItems_InvalidArgument_Throws()
]);
}

/**
* @expectedException \Stash\Exception\InvalidArgumentException
*/
public function testSettingMaxItems_LessThan0_Throws()
{
$this->expectException('InvalidArgumentException');
/**
* @var \Stash\Driver\Ephemeral
*/
Expand Down
Loading

0 comments on commit e43b486

Please sign in to comment.