Skip to content

Commit bbd77d0

Browse files
committed
Test use cases IRL
1 parent 5985c3c commit bbd77d0

File tree

8 files changed

+206
-0
lines changed

8 files changed

+206
-0
lines changed

.github/workflows/cases.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
on:
2+
- push
3+
4+
jobs:
5+
case-incompatible-signature:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
php-version:
10+
- "8.0"
11+
- "8.4"
12+
composer-version:
13+
- "v2.4.0"
14+
- "v2"
15+
composer-tweak:
16+
- "--prefer-lowest"
17+
- ""
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
- name: Install PHP
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: ${{ matrix.php-version }}
25+
ini-values: memory_limit=-1
26+
tools: composer:${{ matrix.composer-version }}
27+
- name: Run case
28+
run: |
29+
cd cases/incompatible-signature
30+
composer --version
31+
composer update --no-interaction --no-progress ${{ matrix.composer-tweak }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
ARG PHP_TAG=8.0-cli-buster
2+
FROM php:${PHP_TAG}
3+
4+
RUN <<-EOF
5+
apt-get update
6+
apt-get install -y autoconf pkg-config
7+
pecl channel-update pecl.php.net
8+
pecl install xdebug
9+
docker-php-ext-enable opcache xdebug
10+
EOF
11+
12+
RUN <<-EOF
13+
cat <<-SHELL >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
14+
xdebug.client_host=host.docker.internal
15+
xdebug.mode=develop
16+
xdebug.start_with_request=yes
17+
SHELL
18+
19+
cat <<-SHELL >> /usr/local/etc/php/conf.d/php.ini
20+
display_errors=On
21+
error_reporting=E_ALL
22+
date.timezone=UTC
23+
SHELL
24+
EOF
25+
26+
ENV COMPOSER_ALLOW_SUPERUSER 1
27+
28+
RUN <<-EOF
29+
apt-get update
30+
apt-get install unzip
31+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
32+
php composer-setup.php --version=2.4.0
33+
php -r "unlink('composer-setup.php');"
34+
mv composer.phar /usr/local/bin/composer
35+
cat <<-SHELL >> /root/.bashrc
36+
export PATH="$HOME/.composer/vendor/bin:$PATH"
37+
SHELL
38+
EOF
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# do not edit the following lines
2+
3+
vendor:
4+
@composer install --prefer-lowest
5+
6+
.PHONY: test-container
7+
test-container: test-container80
8+
9+
.PHONY: test-container80
10+
test-container80:
11+
@-docker compose run --rm app80 bash
12+
@docker compose down -v
13+
14+
.PHONY: test-container81
15+
test-container81:
16+
@-docker-compose run --rm app81 bash
17+
@docker-compose down -v
18+
19+
.PHONY: test-container82
20+
test-container82:
21+
@-docker compose run --rm app82 bash
22+
@docker compose down -v
23+
24+
.PHONY: test-container84
25+
test-container84:
26+
@-docker compose run --rm app84 bash
27+
@docker compose down -v
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Use case: Incompatible Signature
2+
3+
> [!NOTE]
4+
> Fixed in [v2.1.0](https://github.com/olvlvl/composer-attribute-collector/releases/tag/v2.1.0)
5+
6+
Running the collector within Composer's realm is causing issues when the interfaces used by Composer
7+
are incompatible with those used by the codebase, as reported by [#31][] and [#32][]. The issue was
8+
fixed in [#35][], by running the collector as a command.
9+
10+
```
11+
Fatal error: Declaration of Acme\MyLogger::emergency(Stringable|string $message, array $context = []): void must be compatible with Psr\Log\LoggerInterface::emergency($message, array $context = []) in /app/src/MyLogger.php on line 23
12+
```
13+
14+
[#31]: https://github.com/olvlvl/composer-attribute-collector/issues/31
15+
[#32]: https://github.com/olvlvl/composer-attribute-collector/issues/32
16+
[#35]: https://github.com/olvlvl/composer-attribute-collector/pull/35
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"require": {
3+
"php": ">=8.0",
4+
"psr/log": "^3.0",
5+
"olvlvl/composer-attribute-collector": "^2.1.0"
6+
},
7+
"config": {
8+
"allow-plugins": {
9+
"olvlvl/composer-attribute-collector": true
10+
}
11+
},
12+
"extra": {
13+
"composer-attribute-collector": {
14+
"include": [
15+
"src"
16+
]
17+
}
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"Acme\\": "src"
22+
}
23+
}
24+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
services:
3+
app80:
4+
build:
5+
context: .
6+
args:
7+
PHP_TAG: '8.0-cli-buster'
8+
environment:
9+
PHP_IDE_CONFIG: 'serverName=olvlvl/attribute-collector'
10+
volumes:
11+
- .:/app:delegated
12+
- ~/.composer:/root/.composer:delegated
13+
working_dir: /app
14+
app81:
15+
build:
16+
context: .
17+
args:
18+
PHP_TAG: '8.1-cli-buster'
19+
environment:
20+
PHP_IDE_CONFIG: 'serverName=olvlvl/attribute-collector'
21+
volumes:
22+
- .:/app:delegated
23+
- ~/.composer:/root/.composer:delegated
24+
working_dir: /app
25+
app82:
26+
build:
27+
context: .
28+
args:
29+
PHP_TAG: '8.2-cli-bookworm'
30+
environment:
31+
PHP_IDE_CONFIG: 'serverName=olvlvl/attribute-collector'
32+
volumes:
33+
- .:/app:delegated
34+
- ~/.composer:/root/.composer:delegated
35+
working_dir: /app
36+
app84:
37+
build:
38+
context: .
39+
args:
40+
PHP_TAG: '8.4-cli-bookworm'
41+
environment:
42+
PHP_IDE_CONFIG: 'serverName=olvlvl/attribute-collector'
43+
volumes:
44+
- .:/app:delegated
45+
- ~/.composer:/root/.composer:delegated
46+
working_dir: /app
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Acme;
4+
5+
use Psr\Log\LoggerInterface;
6+
use Psr\Log\LoggerTrait;
7+
8+
#[SampleAttribute]
9+
class MyLogger implements LoggerInterface
10+
{
11+
use LoggerTrait;
12+
13+
public function log($level, \Stringable|string $message, array $context = []): void
14+
{
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Acme;
4+
5+
#[\Attribute(\Attribute::TARGET_CLASS)]
6+
class SampleAttribute
7+
{
8+
}

0 commit comments

Comments
 (0)