Skip to content

Commit 6a461a7

Browse files
authored
Fix integration tests by fixing a PHP 8.1+ deprecation warnings in ReflectionClass (#1351)
* gha: get more insights when/if logs exist * Better handle cases when we can receive a concrete instance The problem with `null` being passed to `ReflectionClass` was always there but in PHP 8.1+ it triggers a deprecation warnings. Since having `null` in `$concrete` doesn't make sense to reflect anything anyway, we just throw a custom exception (which gets caught a couple lines below) and just carry on. When using `-v` this can be seen, example: ``` $ ./artisan ide-helper:meta -v Cannot make 'Faker\Generator': Class 'Faker\Provider\en_US\Barcode' not found. Cannot make 'Illuminate\Contracts\Auth\Authenticatable': Class does not exist Cannot make 'cache.psr6': Class 'Symfony\Component\Cache\Adapter\Psr16Adapter' not found. Cannot make 'csp-nonce': Class 'Wza3Mf4CXIvCkcp9K3boMUGJoK6S9maO' not found. Cannot make 'env': Class 'local' not found. Cannot make 'filesystem.cloud': Disk [s3] does not have a configured driver. Cannot make 'redis.connection': Redis connection [default] not configured. A new meta file was written to .phpstorm.meta.php ``` * gha: make sure to run meta with -v to see all output Helps when debugging things * Add CHANGELOG.md entry
1 parent 3ba1e25 commit 6a461a7

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

.github/workflows/run-integration-tests.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,22 @@ jobs:
5757
- name: Execute meta run
5858
run: |
5959
cd sample
60-
php artisan ide-helper:meta
60+
php artisan ide-helper:meta -v
6161
6262
- name: Check file existence
6363
run: |
6464
ls sample/_ide_helper.php
6565
ls sample/.phpstorm.meta.php
6666
67-
- name: Check file count in logs
67+
- name: Check logs
6868
run: |
69-
if [ `ls -1q "sample/storage/logs/" | wc -l` -gt 0 ];then exit 1;fi
69+
if [ `ls -1q "sample/storage/logs/" | wc -l` -gt 0 ]; then
70+
for logfile in sample/storage/logs/*; do
71+
echo "-- $logfile --"
72+
cat $logfile
73+
done
74+
exit 1
75+
fi
7076
7177
php-laravel-integration-tests:
7278
runs-on: ubuntu-20.04
@@ -115,13 +121,20 @@ jobs:
115121
- name: Execute meta run
116122
run: |
117123
cd sample
118-
php artisan ide-helper:meta
124+
php artisan ide-helper:meta -v
119125
120126
- name: Check file existence
121127
run: |
122128
ls sample/_ide_helper.php
123129
ls sample/.phpstorm.meta.php
124130
125-
- name: Check file count in logs
131+
132+
- name: Check logs
126133
run: |
127-
if [ `ls -1q "sample/storage/logs/" | wc -l` -gt 0 ];then exit 1;fi
134+
if [ `ls -1q "sample/storage/logs/" | wc -l` -gt 0 ]; then
135+
for logfile in sample/storage/logs/*; do
136+
echo "-- $logfile --"
137+
cat $logfile
138+
done
139+
exit 1
140+
fi

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55
[Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.12.3...master)
66
--------------
77

8+
### Fixes
9+
- Handle PHP 8.1 deprecation warnings when passing `null` to `new \ReflectionClass` [#1351 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1351)
10+
811
2022-03-06, 2.12.3
912
------------------
1013

src/Console/MetaCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Barryvdh\LaravelIdeHelper\Factories;
1515
use Illuminate\Console\Command;
16+
use RuntimeException;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
1819

@@ -95,6 +96,11 @@ public function handle()
9596

9697
try {
9798
$concrete = $this->laravel->make($abstract);
99+
100+
if ($concrete === null) {
101+
throw new RuntimeException("Cannot create instance for '$abstract', received 'null'");
102+
}
103+
98104
$reflectionClass = new \ReflectionClass($concrete);
99105
if (is_object($concrete) && !$reflectionClass->isAnonymous()) {
100106
$bindings[$abstract] = get_class($concrete);

0 commit comments

Comments
 (0)