Jakub77's avatar

Pest - Architecture testing - tests not working.

Hello,

I'm trying to run simple arch test on a clean installation of latest laravel. Stack versions: php 8.2 laravel: v10.20.0 pest: ^2.16 pest-plugin-laravel: ^2.2 phpunit: ^10.1

Test code

test('example', function () {
    test('app')
        ->expect('App\Models')
        ->toBeAbstract();
});

Result

   FAILED  Tests\Feature\ArchTest > example                                                                                                        AssertionError   
  assert(array_key_exists(self::FILE, $trace))

  at tests/Feature/ArchTest.php:4
      1▕ <?php
      2▕ 
      3▕ test('example', function () {
  ➜   4▕     test('app')
      5▕         ->expect('App\Models')
      6▕         ->toBeAbstract();
      7▕ });
      8▕ 

  1   tests/Feature/ArchTest.php:4


  Tests:    1 failed, 2 passed (3 assertions)
  Duration: 0.08s

Is it something that I do wrong? Any idea how to solve the problem?

0 likes
1 reply
LaryAI's avatar
Level 58

The error message suggests that the array_key_exists function is failing on line 4 of the ArchTest.php file. This indicates that the $trace variable does not contain the expected key self::FILE.

To solve this problem, you can try the following steps:

  1. Make sure you have installed the necessary dependencies by running composer install in your project directory.

  2. Check if the ArchTest.php file is located in the correct directory (tests/Feature/ArchTest.php).

  3. Verify that the ArchTest.php file contains the correct namespace declaration. It should be namespace Tests\Feature; at the top of the file.

  4. Ensure that the ArchTest.php file is being autoloaded correctly. You can check the composer.json file to confirm that the tests/ directory is included in the autoload-dev section.

  5. If you have made any changes to the ArchTest.php file, try running the tests again to see if the error persists.

If the issue still persists, it might be worth checking the Pest and Laravel versions for compatibility issues. You can refer to the documentation or the Laracasts forum for any reported compatibility issues between the versions you are using.

If you need further assistance, please provide more details about your project structure and any additional relevant code.

Please or to participate in this conversation.