# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=9

COMPOSER_INSTALL_PATH="Predis"

inherit composer git-r3

DESCRIPTION="Flexible and feature-complete Redis client for PHP"
HOMEPAGE="https://github.com/predis/predis"
EGIT_REPO_URI="https://github.com/predis/predis.git"
SRC_URI="https://github.com/SpiderX/portage-overlay/releases/download/${PN}-3.6.0/${PN}-3.6.0-patches.tar.xz"

LICENSE="MIT"
SLOT="0"

RDEPEND="dev-php/psr-http-message"
BDEPEND="test? ( dev-db/redis
		dev-php/relay )"

PATCHES=( "${WORKDIR}/${PN}-3.6.0-patches/tests" )

# ssl tests need cluster, blocking Pub/Sub integration test can hang
# indefinitely due to timing issues
EPHPUNIT_EXCLUDE_FILTER='testPubSubAgainstRedisServerBlocking'
EPHPUNIT_EXCLUDE_GROUP=( cluster realm-stack realm-server sentinel ssl )
composer_enable_tests phpunit

src_unpack() {
	git-r3_src_unpack
	unpack ${A}
}

src_test() {
	edo "${EPREFIX}"/usr/sbin/redis-server - <<- EOF
		daemonize yes
		pidfile "${T}/redis-6379.pid"
		logfile "${T}/redis-6379.log"
		port 6379
		bind 127.0.0.1
	EOF
	edo "${EPREFIX}"/usr/sbin/redis-server - <<- EOF
		daemonize yes
		pidfile "${T}/redis-6479.pid"
		logfile "${T}/redis-6479.log"
		port 6479
		bind 127.0.0.1
	EOF
	REDIS_HOST=127.0.0.1 ephpunit
	edo kill "$(<"${T}/redis-6379.pid")"
	edo kill "$(<"${T}/redis-6479.pid")"
}