Skip to content

Commit

Permalink
Refactor tests for PHPUnit 10.x compat
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasmullie committed Jun 27, 2023
1 parent d49068f commit 69dd1ea
Show file tree
Hide file tree
Showing 142 changed files with 3,704 additions and 2,616 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/healthcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install latest Docker Compose
run: |
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
- name: Test (twice, if needed)
run: make test || make test
- name: Healthcheck ping
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install latest Docker Compose
run: |
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)" -o docker-compose
chmod +x docker-compose
mv docker-compose /usr/local/bin/docker-compose
- name: Test PHP 8.2
run: make test PHP=8.2
- name: Test PHP 8.1
Expand Down
18 changes: 4 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ services:
- ./.php-cs-fixer.php:/var/www/.php-cs-fixer.php
- ./phpunit.xml:/var/www/phpunit.xml
- ./ruleset.xml:/var/www/ruleset.xml
depends_on:
couchbase:
condition: service_healthy
memcached:
condition: service_started
mysql:
condition: service_healthy
postgresql:
condition: service_healthy
redis:
condition: service_healthy
php-8.0:
<<: *default-php
build:
Expand Down Expand Up @@ -60,11 +49,12 @@ services:
image: mysql
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_ROOT_PASSWORD=
- MYSQL_ROOT_PASSWORD=pass
- MYSQL_USER=user
- MYSQL_PASSWORD=pass
- MYSQL_DATABASE=cache
healthcheck:
test: ["CMD", "mysql" ,"-h", "mysql", "-P", "3306", "-u", "root", "-e", "SELECT 1", "cache"]
test: ["CMD", "mysqladmin", "ping", "-hmysql", "-P3306", "-uuser", "-ppass"]
interval: 3s
timeout: 3s
retries: 30
Expand Down
5 changes: 3 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# defaults for `make test`
PHP ?=
ADAPTER ?= Apc,Couchbase,Flysystem,Memcached,MemoryStore,MySQL,PostgreSQL,Redis,SQLite
GROUP ?= adapter,buffered,collections,keyvaluestore,psr6,psr16,shard,transactional,stampede

install:
wget -q -O - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Expand Down Expand Up @@ -36,8 +37,8 @@ test:
test "$(PHP)" && TEST_CONTAINER=php-$(PHP) || TEST_CONTAINER=php;\
DEPENDENT_CONTAINERS="$(filter-out apc flysystem memorystore sqlite, $(shell echo $(ADAPTER) | tr 'A-Z,' 'a-z '))";\
RELEVANT_CONTAINERS="$$TEST_CONTAINER $(filter-out apc flysystem memorystore sqlite, $(shell echo $(ADAPTER) | tr 'A-Z,' 'a-z '))";\
docker-compose up --no-deps -d $$DEPENDENT_CONTAINERS;\
docker-compose run --no-deps $$TEST_CONTAINER env XDEBUG_MODE=coverage vendor/bin/phpunit --group $(ADAPTER) --coverage-clover build/coverage-$(PHP)-$(ADAPTER).clover;\
docker-compose up --no-deps --wait -d $$DEPENDENT_CONTAINERS;\
docker-compose run --no-deps $$TEST_CONTAINER env XDEBUG_MODE=coverage vendor/bin/phpunit --group $(GROUP) --testsuite $(ADAPTER) --coverage-clover build/coverage-$(PHP)-$(ADAPTER).clover --configuration phpunit.xml;\
TEST_STATUS=$$?;\
docker-compose stop -t0 $$RELEVANT_CONTAINERS;\
exit $$TEST_STATUS
Expand Down
56 changes: 41 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/coverage.clover"/>
</report>
</coverage>
<testsuites>
<testsuite name="scrapbook">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<logging/>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd">
<coverage>
<report>
<clover outputFile="build/coverage.clover"/>
</report>
</coverage>
<testsuites>
<testsuite name="Apc">
<directory suffix="Test.php">tests/Adapters/Apc</directory>
</testsuite>
<testsuite name="Couchbase">
<directory suffix="Test.php">tests/Adapters/Couchbase</directory>
</testsuite>
<testsuite name="Flysystem">
<directory suffix="Test.php">tests/Adapters/Flysystem</directory>
</testsuite>
<testsuite name="Memcached">
<directory suffix="Test.php">tests/Adapters/Memcached</directory>
</testsuite>
<testsuite name="MemoryStore">
<directory suffix="Test.php">tests/Adapters/MemoryStore</directory>
</testsuite>
<testsuite name="MySQL">
<directory suffix="Test.php">tests/Adapters/MySQL</directory>
</testsuite>
<testsuite name="PostgreSQL">
<directory suffix="Test.php">tests/Adapters/PostgreSQL</directory>
</testsuite>
<testsuite name="Redis">
<directory suffix="Test.php">tests/Adapters/Redis</directory>
</testsuite>
<testsuite name="SQLite">
<directory suffix="Test.php">tests/Adapters/SQLite</directory>
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
10 changes: 6 additions & 4 deletions src/Adapters/Couchbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,14 @@ protected function deleteIfExpired(string|array $key, int $expire): bool
* Couchbase expects an integer TTL (under 1576800000) for relative
* times, or a \DateTimeInterface for absolute times.
*
* @return int|DateTime expiration in seconds or \DateTimeInterface
* @return int|\DateTime expiration in seconds or \DateTimeInterface
*/
protected function expire(int $expire): int|DateTime
protected function expire(int $expire): int|\DateTime
{
// relative time in seconds, <30 days
if ($expire < 30 * 24 * 60 * 60) {flush();
if ($expire < 30 * 24 * 60 * 60) {
flush();

return $expire;
}

Expand All @@ -411,7 +413,7 @@ protected function expire(int $expire): int|DateTime
return -1; // @todo this if statement should be useless; this case should be fine as DateTime
}

return (new DateTime())->setTimestamp($expire);
return (new \DateTime())->setTimestamp($expire);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Psr6/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public function getItem(string $key): CacheItemInterface
}

/**
* {@inheritdoc}
*
* @return Item[]
*/
public function getItems(array $keys = []): iterable
Expand Down
26 changes: 26 additions & 0 deletions tests/AbstractAdapterTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace MatthiasMullie\Scrapbook\Tests;

use MatthiasMullie\Scrapbook\KeyValueStore;
use PHPUnit\Framework\TestCase;

abstract class AbstractAdapterTestCase extends TestCase
{
protected KeyValueStore $adapterKeyValueStore;
protected string $collectionName;

protected function setUp(): void
{
parent::setUp();

$this->collectionName = $this->getCollectionName();
$this->adapterKeyValueStore = $this->getAdapterKeyValueStore();
}

abstract public function getAdapterKeyValueStore(): KeyValueStore;

abstract public function getCollectionName(): string;
}
Loading

0 comments on commit 69dd1ea

Please sign in to comment.