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

Issue with Pest Architecture Testing after installation #16

Closed
swilla opened this issue Jul 11, 2023 · 7 comments · Fixed by #18
Closed

Issue with Pest Architecture Testing after installation #16

swilla opened this issue Jul 11, 2023 · 7 comments · Fixed by #18

Comments

@swilla
Copy link
Contributor

swilla commented Jul 11, 2023

After installing this package and setting it up, I'm getting my global architecture tests failing. I get this error:

./vendor/bin/pest tests/Feature/ArchTest.php         

   FAIL  Tests\Feature\ArchTest
  ✓ controllers                                         0.21s  
  ⨯ globals                                             0.34s  
  ───────────────────────────────────────────────────────────  
   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, 1 passed (7 assertions)
  Duration: 0.61s

https://pestphp.com/docs/arch-testing

Here is the whole test:

<?php

test('controllers')
    ->expect('App\Http\Controllers')
    ->not->toUse('Illuminate\Http\Request');

test('globals')
    ->expect(['dd', 'dump', 'ray'])
    ->not->toBeUsed();

Prior to whisky install, they all pass:

php artisan test

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

   PASS  Tests\Feature\ArchTest
  ✓ controllers                                                                                                                                                  0.08s
  ✓ globals                                                                                                                                                      0.03s

   PASS  Tests\Feature\ExampleTest
  ✓ it returns a successful response                                                                                                                             0.02s

  Tests:    4 passed (12 assertions)
  Duration: 0.18s

I created this repo that can be used to replicate the problem:
https://github.com/TappNetwork/whisky-pest

To replicate:

  • Clone repo
  • composer install
  • php artisan test

See the failure.

@ProjektGopher
Copy link
Owner

ProjektGopher commented Jul 11, 2023

Thx for the feedback! My wife and I are actually in the hospital right now with our newborn, so I can't do anything about this. If there's any possible way that you can figure out why this is happening I can look it over on my phone and merge it though. Is that something you might have the time to do?

Edit: I super appreciate you taking the time to make me a repro. 🙏

@swilla
Copy link
Contributor Author

swilla commented Jul 12, 2023

Congratulations! I created a ticket with Pest as I think it's related to that package. If it is indeed something on this package I'll do my best to make a PR to fix it.

pestphp/pest#858

@ProjektGopher
Copy link
Owner

ProjektGopher commented Jul 13, 2023

I have a feeling that this is related to #11

By not updating the namespace from my default laravel zero install from App I think this is interfering with your App namespace from within the vendor folder

@swilla
Copy link
Contributor Author

swilla commented Jul 13, 2023

I have a feeling that this is related to #11

I'm actually testing this out locally to see if it fixes it. If it does I'll create a PR. I was just going to use Whisky as the root namespace if that is OK with you.

@ProjektGopher
Copy link
Owner

That's perfect. Thx again for your help

@swilla swilla mentioned this issue Jul 14, 2023
@swilla
Copy link
Contributor Author

swilla commented Jul 14, 2023

@ProjektGopher I confirmed that this PR fixes the tests on the sample project using the pest arch plugin.

#17

@ProjektGopher
Copy link
Owner

That's awesome! I'll look this over in a few and merge it. As soon as I get a chance to open up my laptop, I'll version, build, and publish.

Thx so much for taking this one over the finish line.

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 a pull request may close this issue.

2 participants