Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed property PHPUnit\Architecture\Asserts\Dependencies\ObjectDependenciesDescription::$uses must not be accessed before initialization #858

Closed
swilla opened this issue Jul 12, 2023 · 8 comments

Comments

@swilla
Copy link

swilla commented Jul 12, 2023

I recently installed Whisky, and after installation, I started getting the following error when running Architecture tests:

./vendor/bin/pest

   PASS  Tests\Unit\ExampleTest
  ✓ that true is true                                                                                                                                            0.01s

   FAIL  Tests\Feature\ArchTest
  ✓ controllers                                                                                                                                                  0.14s
  ⨯ globals                                                                                                                                                      0.04s

   PASS  Tests\Feature\ExampleTest
  ✓ it returns a successful response                                                                                                                             0.02s
  ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   FAILED  Tests\Feature\ArchTest > globals                                                                                                                     Error
  Typed property PHPUnit\Architecture\Asserts\Dependencies\ObjectDependenciesDescription::$uses must not be accessed before initialization

  at vendor/ta-tikoma/phpunit-architecture-test/src/Asserts/Dependencies/DependenciesAsserts.php:70
     66▕         $result = [];
     67▕
     68▕         foreach ($layers as $layer) {
     69▕             foreach ($layer as $object) {
  ➜  70▕                 foreach ($object->uses as $use) {
     71▕                     foreach ($layersToSearch as $layerToSearch) {
     72▕                         // do not test layer with self
     73▕                         if ($layer->equals($layerToSearch)) {
     74▕                             continue;



  Tests:    1 failed, 3 passed (9 assertions)
  Duration: 0.29s

I was able to create a repo that you can use to replicate the problem:
https://github.com/TappNetwork/whisky-pest

To replicate:

  • Clone repo
  • composer install
  • php artisan test

This seems like it is only causing issues with architecture testing: https://pestphp.com/docs/arch-testing

php artisan about

  Environment ......................................................................................................................................
  Application Name ......................................................................................................................... Laravel
  Laravel Version .......................................................................................................................... 10.15.0
  PHP Version ................................................................................................................................ 8.2.4
  Composer Version ........................................................................................................................... 2.5.5
  Environment ................................................................................................................................ local
  Debug Mode ............................................................................................................................... ENABLED
  URL ............................................................................................................................. whisky-pest.test
  Maintenance Mode ............................................................................................................................. OFF

  Cache ............................................................................................................................................
  Config ................................................................................................................................ NOT CACHED
  Events ................................................................................................................................ NOT CACHED
  Routes ................................................................................................................................ NOT CACHED
  Views ..................................................................................................................................... CACHED

  Drivers ..........................................................................................................................................
  Broadcasting ................................................................................................................................. log
  Cache ....................................................................................................................................... file
  Database ................................................................................................................................... mysql
  Logs .............................................................................................................................. stack / single
  Mail ........................................................................................................................................ smtp
  Queue ....................................................................................................................................... sync
  Session ..................................................................................................................................... file
composer show pestphp/pest
name     : pestphp/pest
descrip. : An elegant PHP Testing Framework.
keywords : framework, pest, php, test, testing, unit
versions : * v2.8.2
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage :
source   : [git] https://github.com/pestphp/pest.git a1208b5876525d309ee8d39c83870fca60d1a0ac
dist     : [zip] https://api.github.com/repos/pestphp/pest/zipball/a1208b5876525d309ee8d39c83870fca60d1a0ac a1208b5876525d309ee8d39c83870fca60d1a0ac
path     : /Users/stevewilliamson/Code/Tapp/whisky-pest/vendor/pestphp/pest
names    : pestphp/pest

support
issues : https://github.com/pestphp/pest/issues
source : https://github.com/pestphp/pest/tree/v2.8.2

autoload
files
psr-4
Pest\ => src/

requires
brianium/paratest ^7.2.2
nunomaduro/collision ^7.7.0
nunomaduro/termwind ^1.15.1
pestphp/pest-plugin ^2.0.1
pestphp/pest-plugin-arch ^2.2.1
php ^8.1.0
phpunit/phpunit ^10.2.3

requires (dev)
pestphp/pest-dev-tools ^2.12.0
symfony/process ^6.3.0

conflicts
phpunit/phpunit >10.2.3
webmozart/assert <1.11.0
@nunomaduro
Copy link
Member

Do you face that issue, when not using whisky?

@swilla
Copy link
Author

swilla commented Jul 13, 2023

No, only after whisky is installed. The Architecture Test will fail until whisky is uninstalled.

@nunomaduro
Copy link
Member

You need to report this issue in their repository then.

@swilla
Copy link
Author

swilla commented Jul 14, 2023

For the record, this PR fixes this issue:
ProjektGopher/whisky#17

@giorgiopogliani
Copy link

giorgiopogliani commented Jan 31, 2025

I have the same error but not sure what is causing it, @nunomaduro could you explain what's behind this?

@giorgiopogliani
Copy link

giorgiopogliani commented Jan 31, 2025

I changed my arch test to use ->not->toBeUsedIn('App') instead of ->not->toBeUsed() and the error disappeard. Presets are still not working though.

@laudaikinhdi
Copy link

I have the same issue

@giorgiopogliani
Copy link

this should fix it pestphp/pest-plugin-arch#22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants