Skip to content
Snippets Groups Projects
Commit b69dad54 authored by Luhur Abdi Rizal's avatar Luhur Abdi Rizal
Browse files

Issue #3432075 by el7cosmos: Add phpunit test

parent e51f6d13
No related branches found
No related tags found
1 merge request!5Add phpunit test
Pipeline #123934 passed
......@@ -104,3 +104,16 @@ variables:
# .,(((((((((((((((((((((((((.
#
###################################################################################
phpunit:
extends: .phpunit-base
services:
- !reference [.with-database]
- name: redis:alpine
before_script:
# https://docs.gitlab.com/ee/ci/jobs/index.html#pre-collapse-sections
- echo -e "\e[0Ksection_start:`date +%s`:my_first_section[collapsed=true]\r\e[0KInstall PHP Extension"
- pecl install redis && docker-php-ext-enable redis
- echo -e "\e[0Ksection_end:`date +%s`:my_first_section\r\e[0K"
- cp $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/tests/fixtures/settings.testing.php $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/settings.testing.php
- echo "SetEnv REDIS_HOST redis" >> /etc/apache2/apache2.conf
services:
phpredis.batch.storage:
class: Drupal\redis_batch\Batch\PhpRedisBatchStorage
arguments:
$serializer: '@serialization.phpserialize'
autowire: true
arguments: ['@redis.factory', '@csrf_token', '@serialization.phpserialize', '@session']
......@@ -43,6 +43,7 @@ class PhpRedisBatchStorage implements BatchStorageInterface {
protected readonly SerializationInterface $serializer,
protected readonly SessionInterface $session
) {
$this->setPrefix('drupal:batch:items');
}
/**
......@@ -99,18 +100,7 @@ class PhpRedisBatchStorage implements BatchStorageInterface {
/**
* {@inheritdoc}
*/
public function cleanup(): void {
}
/**
* {@inheritdoc}
*/
protected function getPrefix(): string {
if ($this->prefix === NULL) {
$this->prefix = $this->getDefaultPrefix();
}
return $this->prefix . ':batch';
}
public function cleanup(): void {}
/**
* Gets the redis client.
......@@ -125,4 +115,14 @@ class PhpRedisBatchStorage implements BatchStorageInterface {
return $this->client;
}
/**
* Returns a new batch id.
*
* @return int
* A batch id.
*/
public function getId(): int {
return $this->getClient()->incr('drupal:batch:counter');
}
}
<?php
// phpcs:ignoreFile
$settings['redis.connection'] = [
'interface' => getenv('REDIS_INTERFACE') ?? 'PhpRedis',
'host' => getenv('REDIS_HOST') ?? 'redis',
];
name: Redis Batch test
type: module
description: 'Support module for Redis Batch tests.'
package: Testing
core_version_requirement: ^10.2
dependencies:
- redis_batch:redis_batch
hidden: true
services:
batch.storage:
alias: phpredis.batch.storage
<?php
namespace Drupal\Tests\redis_batch\Functional;
use Drupal\Tests\system\Functional\Batch\PageTest;
/**
* @group redis_batch
*/
class PhpRedisPageTest extends PageTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['batch_test', 'redis', 'redis_batch', 'redis_batch_test'];
}
<?php
namespace Drupal\Tests\redis_batch\Functional;
use Drupal\Tests\redis\Traits\RedisTestInterfaceTrait;
use Drupal\Tests\system\Functional\Batch\ProcessingTest;
/**
* @group redis_batch
*/
class PhpRedisProcessingTest extends ProcessingTest {
use RedisTestInterfaceTrait;
/**
* {@inheritdoc}
*/
protected static $modules = ['batch_test', 'redis', 'redis_batch', 'redis_batch_test'];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment