Skip to content

Update ObjectDependenciesDescription.php#18

Closed
giorgiopogliani wants to merge 1 commit intota-tikoma:mainfrom
giorgiopogliani:patch-1
Closed

Update ObjectDependenciesDescription.php#18
giorgiopogliani wants to merge 1 commit intota-tikoma:mainfrom
giorgiopogliani:patch-1

Conversation

@giorgiopogliani
Copy link
Copy Markdown

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

Fixing error: Typed property PHPUnit\Architecture\Asserts\Dependencies\ObjectDependenciesDescription::$uses must not be accessed before initialization
@ta-tikoma
Copy link
Copy Markdown
Owner

@giorgiopogliani can you write an example here to reproduce this error? please

@giorgiopogliani
Copy link
Copy Markdown
Author

I was using pestphp/pest on a laravel project, setting up arch tests cause this error if some packages are installed.

In pestphp/pest repo they closed the issue shifting the blame on the packages, but with the chages I am proposing all my tests suite was fixed.

i am not sure the root cause of the error and why some packages installed cause this and other packages don't.

If you want to replicate the error with one of the dep I found you can with these steps:

  • Install new laravel proejct composer create-project laravel/laravel test
  • Install pest 3: composer require pestphp/pest:^3 --dev -W
  • Install a dep I found: composer require mateusjunges/laravel-trackable-jobs
  • Init pest: vendor/bin/pest --init
  • Replace everything inside Unit/ExampleTest.php with for example: arch()->preset()->php();
  • Run: vendor/bin/pest
  • You should see: " Typed property PHPUnit\Architecture\Asserts\Dependencies\ObjectDependenciesDescription::$uses must not be accessed before initialization"

@ta-tikoma
Copy link
Copy Markdown
Owner

@giorgiopogliani I try to fix it pestphp/pest-plugin-arch#22

@momostafa
Copy link
Copy Markdown

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

I had the same exact error and applying your snippet fixed the issue Thank you.
Then i got similar error at abstract class ObjectDescriptionBase and following your pattern i fixed as below

public function __construct() { $this->reflectionClass = new ReflectionClass($this); $this->type = new ObjectType($this->reflectionClass->getShortName()); $this->path = $this->reflectionClass->getFileName(); $this->name = $this->reflectionClass->getName(); $this->stmts = ServiceContainer::$nodeTraverser->traverse($this->reflectionClass->getAST()); }

@ta-tikoma
Copy link
Copy Markdown
Owner

@momostafa , please try v3.1.0 and tell us if you still have the error?

@momostafa
Copy link
Copy Markdown

@momostafa , please try v3.1.0 and tell us if you still have the error?

I will do that. Thank you

@ta-tikoma ta-tikoma self-requested a review May 7, 2025 05:19
@ta-tikoma ta-tikoma self-assigned this May 7, 2025
@ta-tikoma ta-tikoma closed this May 7, 2025
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

Successfully merging this pull request may close these issues.

3 participants