Jonnny
Jonnny

Reputation: 5039

Codeception\Test\Unit not found

I am having some problems with Codeception using Yii2. I just upgraded to Yii 2.0.10 and have been using this guide

I am getting the error: Codeception\Test\Unit not found in vendor\codeception\base\shim.php. If I ocmment this class out, the next one fails which is:

namespace Codeception\Module {

class Symfony2 extends Symfony {
}

This is what've done: I created a file test.php and put it in my config folder:

<?php
// config/test.php
$config =  yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/main.php'),
require(__DIR__ . '/main-local.php'),
[
'id' => 'app-tests',
'components' => [
    'db1' => require(__DIR__ . '/db.php'),
]
]
);
return $config;

codeception.yaml

actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
memory_limit: 1024M
colors: true
modules:
config:
    Yii2:
        configFile: 'config/test.php'

unit.suite.yml

class_name: UnitTester
modules:
enabled:
  - Asserts
  - Yii2:
        part: [orm, email]

I'm completely new to Codeception, so not sure what I've done wrong

Upvotes: 0

Views: 2647

Answers (2)

Jonnny
Jonnny

Reputation: 5039

In this situation as I upgraded from 2.0.9 -> 2.0.10. I had to composer remove yiisoft/yii2-codeception, codeception/codeception, codeception\verify, codeception\specify, codeception\base.

I copied the test folder structure over. Changed my composer.json in the root project to include:

    "require-dev": {
    "yiisoft/yii2-debug": "*",
    "yiisoft/yii2-gii": "*",
    "yiisoft/yii2-faker": "*",
    "codeception/base": "^2.2.3",
    "codeception/verify": "~0.3.1",
    "codeception/specify": "~0.4.3"
},

I also added the test.php and test_db.php files to /config

Upvotes: 0

Uladzimir Pasvistselik
Uladzimir Pasvistselik

Reputation: 3921

As far as I remember you have to do nothing except php vendor/bin/codecept run in directory where you have codeception.yaml.

Please note that path vendor/bin/codecept may differ in your case. Generally speaking Codeception will parse your configuration and do the magic.


It's not necessary to know but if you're interested: it parses configuration and establishes relations between namespaces and paths dynamically by using its own PSR-4 compatible class autoloader implementation.

Take a look here - https://github.com/Codeception/Codeception/blob/2.2/src/Codeception/Configuration.php#L214 and here https://github.com/Codeception/Codeception/blob/2.2/src/Codeception/Util/Autoload.php

Upvotes: 1

Related Questions