Skip to content

Commit

Permalink
PLT-519 Move to CircleCI and test against newer PHP (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrliptontea authored Jul 17, 2024
1 parent 84a167c commit 11454dd
Show file tree
Hide file tree
Showing 30 changed files with 591 additions and 381 deletions.
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2.1

jobs:
test:
parameters:
php_version:
type: string
docker:
- image: cimg/php:<< parameters.php_version >>
steps:
- checkout
- run: composer install
- run: composer run lint
- run: composer run test
- store_test_results:
path: build
- store_artifacts:
path: build

workflows:
build_and_test:
jobs:
- test:
matrix:
parameters:
php_version:
- 5.6.40
- 7.4.33
- 8.0.30
- 8.1.29
- 8.2.20
- 8.3.8
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage
vendor
docker-compose.override.yml
.env
.phpunit.result.cache
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM talis/ubuntu:1404-latest

ENV DEBIAN_FRONTEND noninteractive
ENV DEBIAN_FRONTEND=noninteractive

ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_HOME=/tmp
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "talis/talis-php",
"description": "This is a php client library for talis APIs",
"version": "0.6.3",
"version": "0.7.0",
"keywords": [
"persona",
"echo",
Expand All @@ -19,15 +19,17 @@
},
"require": {
"php": ">=5.5.9",
"ext-hash": "*",
"ext-openssl": "*",
"doctrine/common": "^2.5",
"firebase/php-jwt": "^3.0",
"guzzlehttp/guzzle": "^6.0",
"guzzlehttp/guzzle": "^6.5.8 || ^7.4.5",
"monolog/monolog": ">=1.13.1",
"predis/predis": ">=0.8.5",
"psr/log": ">=1.0.0"
},
"require-dev": {
"phpunit/phpunit": "4.8.36",
"phpunit/phpunit": ">=4.8 <10",
"squizlabs/php_codesniffer": "3.*",
"phpmd/phpmd": "@stable",
"overtrue/phplint": "^1.1"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ x-common-values: &common-values
services:
init:
<<: *common-values
command: "bash -c 'test -f composer.phar || (curl -sS https://getcomposer.org/installer | php -- --version 1.10.17); php composer.phar install'"
command: "bash -c 'test -f composer.phar || (curl -sS https://getcomposer.org/installer | php); php composer.phar install'"

lint:
<<: *common-values
Expand Down
24 changes: 16 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<phpunit bootstrap="test/bootstrap.php" colors = "true">
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="test/bootstrap.php"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
failOnWarning="false"
>
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<ini name="display_errors" value="On"/>
<ini name="display_startup_errors" value="On"/>
<ini name="memory_limit" value="512M"/>
<ini name="date.timezone" value="Europe/London"/>
</php>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<testsuites>
<testsuite name="unit tests">
<directory>test/unit</directory>
Expand Down
23 changes: 7 additions & 16 deletions src/Talis/Babel/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

/**
* Babel client.
Expand All @@ -15,6 +16,8 @@
*/
class Client implements LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* @var string
*/
Expand All @@ -30,11 +33,6 @@ class Client implements LoggerAwareInterface
*/
private $httpClient = null;

/**
* @var \Psr\Log\LoggerInterface
*/
private $logger = null;

/**
* Babel client must be created with a host/port to connect to Babel.
*
Expand All @@ -58,15 +56,6 @@ public function __construct($host, $port = null)
$this->babelPort = $port;
}

/**
* Specify an instance of MonoLog Logger for the Babel client to use.
* @param \Psr\Log\LoggerInterface $logger logger to use
*/
public function setLogger(\Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}

/**
* Get a feed based off a target identifier. Return either a list of feed
* identifiers, or hydrate it and pass back the data as well.
Expand Down Expand Up @@ -388,8 +377,10 @@ protected function performBabelPost($url, $token, array $arrData, array $request
protected function getLogger()
{
if ($this->logger == null) {
$this->logger = new Logger('BabelClient');
$this->logger->pushHandler(new StreamHandler('php://stderr', Logger::DEBUG));
$logger = new Logger('BabelClient');
$logger->pushHandler(new StreamHandler('php://stderr', Logger::DEBUG));

$this->logger = $logger;
}

return $this->logger;
Expand Down
2 changes: 1 addition & 1 deletion src/Talis/EchoClient/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function getCacheClient()
*/
protected function getStringSizeInBytes($input)
{
return strlen(utf8_decode($input));
return strlen($input);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/Talis/EchoClient/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Talis\EchoClient;

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Talis\EchoClient\Event;
use Talis\EchoClient\Base;

/**
Expand Down
12 changes: 2 additions & 10 deletions src/Talis/Persona/Client/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use Monolog\Logger;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Talis\Persona\Client\ClientVersionCache;

abstract class Base implements LoggerAwareInterface
{
use ClientVersionCache;
use LoggerAwareTrait;

const LOGGER_NAME = 'PERSONA';
const PERSONA_API_VERSION = '3';
Expand All @@ -19,11 +21,6 @@ abstract class Base implements LoggerAwareInterface
*/
protected $config = null;

/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;

/**
* @var \Doctrine\Common\Cache\CacheProvider
*/
Expand Down Expand Up @@ -100,11 +97,6 @@ protected function checkConfig(array $config)
}
}

public function setLogger(\Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}

/**
* @return \Psr\Log\LoggerInterface
*/
Expand Down
1 change: 0 additions & 1 deletion src/Talis/Persona/Client/ClientVersionCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

trait ClientVersionCache
{

/**
* Retrieve the Persona client version
* @return string Persona client version
Expand Down
44 changes: 44 additions & 0 deletions test/CompatAssert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace test;

use PHPUnit\Framework\Assert;

/**
* Comprises assertions that have changed between since PHPUnit 4,
* and that, due to incompatible definitions (final, type hints),
* could not be overridden in TestBase.
*/
class CompatAssert
{
/**
* @param string $needle
* @param string $haystack
* @param string $message
* @return void
*/
public static function assertStringContainsString($needle, $haystack, $message = '')
{
if (method_exists(Assert::class, __FUNCTION__)) {
Assert::assertStringContainsString($needle, $haystack, $message);
} else {
Assert::assertContains($needle, $haystack, $message);
}
}

/**
* Asserts that a variable is of type array.
*
* @param mixed $actual
* @param string $message
* @return void
*/
public static function assertIsArray($actual, $message = '')
{
if (method_exists(Assert::class, __FUNCTION__)) {
Assert::assertIsArray($actual, $message);
} else {
Assert::assertInternalType('array', $actual, $message);
}
}
}
49 changes: 20 additions & 29 deletions test/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@

namespace test;

use Doctrine\Common\Cache\FilesystemCache;
use PHPUnit\Framework\TestCase;

abstract class TestBase extends \PHPUnit_Framework_TestCase
abstract class TestBase extends TestCase
{
protected $cacheBackend = null;

protected function removeCacheFolder()
/**
* Backward-compatible way of setting exception expectations.
*
* @param mixed $exceptionName
* @param string $exceptionMessage
* @param int $exceptionCode
* @return void
*/
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
{
$dir = '/tmp/personaCache';

if (!file_exists($dir)) {
return;
}

$it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
$files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);

foreach ($files as $file) {
if ($file->isDir()) {
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
if (method_exists($this, 'expectException')) {
$this->expectException($exceptionName);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode);
}

rmdir($dir);
}

/**
Expand All @@ -53,14 +52,6 @@ protected function printName()
echo " Test: {$className}->{$testName}\n";
}

protected function setUp()
{
$this->removeCacheFolder();
$this->cacheBackend = new FilesystemCache(
sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'personaCache'
);
}

/**
* @param string $version Override this to a specific version (defaults to the latest).
* @return string The versioned persona host used in the test environment.
Expand Down
5 changes: 3 additions & 2 deletions test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

require APPROOT . '/vendor/autoload.php';

date_default_timezone_set('Europe/London');

/**
* Retrieve environment variable, else return a default
* @param string $name name of environment value
Expand All @@ -19,3 +17,6 @@ function envvalue($name, $default)
$value = getenv($name);
return $value == false ? $default : $value;
}

// For PHPUnit 4+ compatibility
require 'compat.php';
9 changes: 9 additions & 0 deletions test/compat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\Framework\MockObject {
if (!interface_exists(\PHPUnit\Framework\MockObject\MockObject::class)) {
interface MockObject extends \PHPUnit_Framework_MockObject_MockObject
{
}
}
}
Loading

0 comments on commit 11454dd

Please sign in to comment.