Skip to content

Commit 3458898

Browse files
Message reminders (#135)
* feat: implemented message reminders feature * chore: add Docker and development configuration files * enabled reminders for channel * chore: updated failing test
1 parent 4fadc8b commit 3458898

File tree

7 files changed

+552
-1
lines changed

7 files changed

+552
-1
lines changed

.env.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Stream Chat PHP SDK - Environment Variables Example
2+
# Copy this file to .env or .env.test and fill in your values
3+
4+
# API Credentials
5+
# STREAM_KEY=your_api_key
6+
# STREAM_SECRET=your_api_secret
7+
8+
# Test Configuration
9+
# STREAM_CHAT_TIMEOUT=3.0
10+
11+
# STREAM_HOST is the base URL for the Stream Chat API
12+
# STREAM_HOST=http://localhost:3030 # Use localhost to access the local machine
13+
# STREAM_HOST=http://host.docker.internal:3030 # Use host.docker.internal to access the host machine from Docker
14+
# STREAM_HOST=https://chat.stream-io-api.com #[default] # Use the production API

Makefile

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
SHELL := bash
2+
.ONESHELL:
3+
.SHELLFLAGS := -eu -o pipefail -c
4+
.DELETE_ON_ERROR:
5+
MAKEFLAGS += --warn-undefined-variables
6+
MAKEFLAGS += --no-builtin-rules
7+
8+
# Docker configuration
9+
DOCKER_IMAGE := stream-chat-php
10+
DOCKER_TAG := latest
11+
DOCKER_CONTAINER := stream-chat-php-test
12+
DOCKER_RUN := docker run --rm -v $(PWD):/app -w /app --add-host=host.docker.internal:host-gateway
13+
14+
# Environment variables
15+
ENV_FILE ?= .env
16+
17+
# PHP configuration
18+
PHP_VERSION ?= 8.2
19+
COMPOSER_FLAGS ?= --prefer-dist --no-interaction
20+
21+
# Test configuration
22+
PHPUNIT := vendor/bin/phpunit
23+
PHPUNIT_FLAGS ?= --colors=always
24+
PHPUNIT_FILTER ?=
25+
26+
# Find all .env files in the env directory (if it exists)
27+
ENV_DIR := env
28+
ENV_FILES := $(wildcard $(ENV_DIR)/*.env)
29+
TEST_TARGETS := $(addprefix docker-test-, $(subst .env,,$(subst $(ENV_DIR)/,,$(ENV_FILES))))
30+
31+
# Default target
32+
.PHONY: help
33+
help:
34+
@echo "Stream Chat PHP SDK Makefile"
35+
@echo ""
36+
@echo "Usage:"
37+
@echo " make docker-build Build the Docker image"
38+
@echo " make docker-test Run all tests in Docker"
39+
@echo " make docker-test-unit Run unit tests in Docker"
40+
@echo " make docker-test-integration Run integration tests in Docker"
41+
@echo " make docker-lint Run PHP CS Fixer in Docker"
42+
@echo " make docker-lint-fix Fix code style issues in Docker"
43+
@echo " make docker-analyze Run static analysis (Phan) in Docker"
44+
@echo " make docker-shell Start a shell in the Docker container"
45+
@echo " make docker-clean Remove Docker container and image"
46+
@echo " make docker-install Install dependencies in Docker"
47+
@echo " make docker-update Update dependencies in Docker"
48+
@echo ""
49+
@echo "Environment:"
50+
@echo " ENV_FILE Path to .env file (default: .env)"
51+
@echo " PHP_VERSION PHP version to use (default: 8.2)"
52+
@echo " PHPUNIT_FLAGS Additional flags for PHPUnit"
53+
@echo " PHPUNIT_FILTER Filter for PHPUnit tests"
54+
@echo ""
55+
56+
# Docker image build
57+
.PHONY: docker-build
58+
docker-build:
59+
@echo "Building Docker image $(DOCKER_IMAGE):$(DOCKER_TAG)..."
60+
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) \
61+
--build-arg PHP_VERSION=$(PHP_VERSION) \
62+
-f docker/Dockerfile .
63+
64+
# Ensure the Docker image is built
65+
.PHONY: ensure-image
66+
ensure-image:
67+
@if ! docker image inspect $(DOCKER_IMAGE):$(DOCKER_TAG) > /dev/null 2>&1; then \
68+
$(MAKE) docker-build; \
69+
fi
70+
71+
# Run all tests in Docker
72+
.PHONY: docker-test
73+
docker-test: ensure-image .env
74+
@echo "Running all tests in Docker..."
75+
$(DOCKER_RUN) --env-file $(ENV_FILE) $(DOCKER_IMAGE):$(DOCKER_TAG) \
76+
$(PHPUNIT) $(PHPUNIT_FLAGS) $(PHPUNIT_FILTER)
77+
78+
# Run unit tests in Docker
79+
.PHONY: docker-test-unit
80+
docker-test-unit: ensure-image .env
81+
@echo "Running unit tests in Docker..."
82+
$(DOCKER_RUN) --env-file $(ENV_FILE) $(DOCKER_IMAGE):$(DOCKER_TAG) \
83+
$(PHPUNIT) $(PHPUNIT_FLAGS) --testsuite "Unit Test Suite" $(PHPUNIT_FILTER)
84+
85+
# Run integration tests in Docker
86+
.PHONY: docker-test-integration
87+
docker-test-integration: ensure-image .env
88+
@echo "Running integration tests in Docker..."
89+
$(DOCKER_RUN) --env-file $(ENV_FILE) $(DOCKER_IMAGE):$(DOCKER_TAG) \
90+
$(PHPUNIT) $(PHPUNIT_FLAGS) --testsuite "Integration Test Suite" $(PHPUNIT_FILTER)
91+
92+
# Run PHP CS Fixer in Docker
93+
.PHONY: docker-lint
94+
docker-lint: ensure-image
95+
@echo "Running PHP CS Fixer in Docker..."
96+
$(DOCKER_RUN) $(DOCKER_IMAGE):$(DOCKER_TAG) \
97+
vendor/bin/php-cs-fixer fix --dry-run --diff
98+
99+
# Fix code style issues
100+
.PHONY: docker-lint-fix
101+
docker-lint-fix: ensure-image
102+
@echo "Fixing code style issues..."
103+
$(DOCKER_RUN) $(DOCKER_IMAGE):$(DOCKER_TAG) \
104+
vendor/bin/php-cs-fixer fix
105+
106+
# Run static analysis
107+
.PHONY: docker-analyze
108+
docker-analyze: ensure-image
109+
@echo "Running static analysis..."
110+
$(DOCKER_RUN) $(DOCKER_IMAGE):$(DOCKER_TAG) \
111+
vendor/bin/phan --color
112+
113+
# Start a shell in the Docker container
114+
.PHONY: docker-shell
115+
docker-shell: ensure-image
116+
@echo "Starting shell in Docker container..."
117+
$(DOCKER_RUN) -it $(DOCKER_IMAGE):$(DOCKER_TAG) bash
118+
119+
# Clean up Docker resources
120+
.PHONY: docker-clean
121+
docker-clean:
122+
@echo "Cleaning up Docker resources..."
123+
-docker rm -f $(DOCKER_CONTAINER) 2>/dev/null || true
124+
-docker rmi -f $(DOCKER_IMAGE):$(DOCKER_TAG) 2>/dev/null || true
125+
126+
# Create .env file if it doesn't exist by copying from .env.example
127+
.env: .env.example
128+
@echo "Creating .env file from .env.example..."
129+
@cp .env.example .env
130+
@echo "Created .env file. Please edit it with your configuration."
131+
132+
# Create .env.test file for testing
133+
.PHONY: .env.test
134+
.env.test: .env.example
135+
@echo "Creating .env.test file from .env.example..."
136+
@cp .env.example .env.test
137+
@echo "Created .env.test file. Please edit it with your test configuration."
138+
139+
# Dynamic targets for environment-specific tests
140+
.PHONY: $(TEST_TARGETS)
141+
$(TEST_TARGETS): ensure-image .env
142+
$(eval TARGET := $(subst docker-test-,,$@))
143+
$(eval ENV_FILE := $(ENV_DIR)/$(TARGET).env)
144+
@echo "Running tests with environment $(TARGET)..."
145+
$(DOCKER_RUN) --env-file $(ENV_FILE) $(DOCKER_IMAGE):$(DOCKER_TAG) \
146+
$(PHPUNIT) $(PHPUNIT_FLAGS) $(PHPUNIT_FILTER)
147+
148+
# Install dependencies
149+
.PHONY: docker-install
150+
docker-install: ensure-image
151+
@echo "Installing dependencies..."
152+
$(DOCKER_RUN) $(DOCKER_IMAGE):$(DOCKER_TAG) \
153+
composer install $(COMPOSER_FLAGS)
154+
155+
# Update dependencies
156+
.PHONY: docker-update
157+
docker-update: ensure-image
158+
@echo "Updating dependencies..."
159+
$(DOCKER_RUN) $(DOCKER_IMAGE):$(DOCKER_TAG) \
160+
composer update $(COMPOSER_FLAGS)
161+
162+
# Run tests with test environment
163+
.PHONY: docker-test-with-test-env
164+
docker-test-with-test-env: ensure-image .env.test
165+
@echo "Running all tests in Docker with test environment..."
166+
$(DOCKER_RUN) --env-file .env.test $(DOCKER_IMAGE):$(DOCKER_TAG) \
167+
$(PHPUNIT) $(PHPUNIT_FLAGS) $(PHPUNIT_FILTER)

docker/Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
ARG PHP_VERSION=8.2
2+
3+
FROM php:${PHP_VERSION}-cli
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y \
7+
git \
8+
unzip \
9+
libzip-dev \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Install PHP extensions
13+
RUN docker-php-ext-install \
14+
zip \
15+
pcntl
16+
17+
# Install AST extension for Phan
18+
RUN pecl install ast && \
19+
docker-php-ext-enable ast
20+
21+
# Install Composer
22+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
23+
24+
# Set working directory
25+
WORKDIR /app
26+
27+
# Copy composer files
28+
COPY composer.json composer.lock* ./
29+
30+
# Install dependencies
31+
RUN composer install --prefer-dist --no-scripts --no-progress --no-interaction
32+
33+
# Copy the rest of the application
34+
COPY . .
35+
36+
# Set environment variables
37+
ENV PHAN_ALLOW_XDEBUG=0
38+
ENV PHAN_DISABLE_XDEBUG_WARN=1
39+
40+
# Default command
41+
CMD ["php", "-v"]

docker/README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Docker-based Testing for Stream Chat PHP SDK
2+
3+
This directory contains Docker configuration for testing the Stream Chat PHP SDK in an isolated environment.
4+
5+
## Requirements
6+
7+
- Docker installed on your system
8+
- Make (usually pre-installed on macOS and Linux)
9+
10+
## Quick Start
11+
12+
1. Build the Docker image:
13+
```
14+
make docker-build
15+
```
16+
17+
2. Run all tests:
18+
```
19+
make docker-test
20+
```
21+
This will automatically create a `.env` file from `.env.example` if it doesn't exist.
22+
23+
3. Run tests with test environment:
24+
```
25+
make docker-test-with-test-env
26+
```
27+
This will use `.env.test` for environment variables.
28+
29+
4. Run only unit tests:
30+
```
31+
make docker-test-unit
32+
```
33+
34+
5. Run only integration tests:
35+
```
36+
make docker-test-integration
37+
```
38+
39+
## Available Commands
40+
41+
All Docker-related commands are prefixed with `docker-` to distinguish them from local commands:
42+
43+
- `make docker-build` - Build the Docker image
44+
- `make docker-test` - Run all tests
45+
- `make docker-test-with-test-env` - Run all tests with test environment
46+
- `make docker-test-unit` - Run unit tests
47+
- `make docker-test-integration` - Run integration tests
48+
- `make docker-lint` - Check code style with PHP CS Fixer
49+
- `make docker-lint-fix` - Fix code style issues
50+
- `make docker-analyze` - Run static analysis with Phan
51+
- `make docker-shell` - Start a shell in the Docker container
52+
- `make docker-clean` - Remove Docker container and image
53+
- `make docker-install` - Install dependencies
54+
- `make docker-update` - Update dependencies
55+
56+
## Environment Variables
57+
58+
The project includes a `.env.example` file with commented example values. When you run tests, the Makefile will:
59+
60+
1. Create a `.env` file from `.env.example` if it doesn't exist
61+
2. Create a `.env.test` file from `.env.example` when running `make docker-test-with-test-env`
62+
63+
You can also use environment-specific files in the `env/` directory:
64+
65+
```
66+
make docker-test-[environment_name]
67+
```
68+
69+
### Environment File Hierarchy
70+
71+
- `.env` - Default environment file for general testing
72+
- `.env.test` - Environment file specifically for test environments
73+
- `env/*.env` - Environment files for specific test scenarios
74+
75+
## Accessing Host Machine from Docker
76+
77+
When running tests in Docker, the container's `localhost` refers to the container itself, not the host machine. To access services running on your host machine (like a local server on port 3030), use `host.docker.internal` instead of `localhost`.
78+
79+
For example, in your `.env` file:
80+
```
81+
STREAM_HOST=http://host.docker.internal:3030
82+
```
83+
84+
The Makefile includes the `--add-host=host.docker.internal:host-gateway` flag to ensure this works across different Docker environments.
85+
86+
## Customizing PHP Version
87+
88+
You can specify a different PHP version when building the Docker image:
89+
```
90+
make docker-build PHP_VERSION=8.3
91+
```
92+
93+
## Additional PHPUnit Options
94+
95+
You can pass additional options to PHPUnit:
96+
```
97+
make docker-test PHPUNIT_FLAGS="--verbose --filter=testSpecificMethod"
98+
```
99+
100+
Or use the filter directly:
101+
```
102+
make docker-test PHPUNIT_FILTER="testSpecificMethod"
103+
```

0 commit comments

Comments
 (0)