php – Class not found phpunit-ThrowExceptions

Exception or error:

I have the following structure of my project:

.
├── Api
├── ClickHouse
├── Core
├── Database
├── Manage.php
├── Middlewares
├── Models
├── Modules
├── README.md
├── Serializers
├── Utils.php
├── app.yaml
├── composer.json
├── composer.lock
├── config.php
├── cron.yaml
├── dispatch.yaml
├── include.php
├── index.php
├── loc.config.php
├── phinx.php
├── phinx.yml
├── php.ini
├── phpunit.xml
├── scripts
├── static
├── tests
└── vendor

And I’m trying to run PHPUnit tests from the /tests/ folder. And there’s an error with Class not found (but class exists and it runs fine from the index.php file). My composer.json:

{
    "require": {
        "ext-json": "*",
        "guzzlehttp/guzzle": "^6.5",
        "robmorgan/phinx": "^0.11.4",
        "fzaninotto/faker": "^1.9",
        "google/recaptcha": "^1.2",
        "opis/closure": "^3.5"
    },
    "require-dev": {
        "odan/phinx-migrations-generator": "^4.6",
        "phpunit/phpunit": "^8.5"
    },
    "scripts": {
        "migration:create": "vendor/bin/phinx create",
        "migration:migrate": "vendor/bin/phinx migrate"
    }
}

Also my phpunit.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         executionOrder="depends,defects"
         forceCoversAnnotation="true"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTodoAnnotatedTests="true"
         verbose="true">
    <testsuites>
        <testsuite name="default">
            <directory suffix="Test.php">tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

Where did I go wrong?

some text to update the question, can not update it due to the code is too large

Oops, I have to add the code of the example test as a picture
test example
And this code fails with Class UserModel not found

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *