0
votes

Class 'yii\web\Controller' not found in C:\xampp\htdocs\basic\controllers\SiteController.php on line 13

I have this error while running the SiteControllerTest.php on the cmd. I'm using a yii2 basic template and testing the PHPUnit on my sample project in Netbeans but I don't know what this error is targeting to. I already have configured the properties of this in Netbeans and I already have a bootstrap where I require the autoload.php..

I have my test files on 'app\tests\phpunit\'

here is my bootstrap.php

<?php
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../../config/console.php');
(new yii\console\Application($config));

and inside my 'tests\phpunit\' folder, PHPUnit creates a another folder named 'controllers' and where my SiteControllerTest.php is located.

<?php
namespace app\controllers;

/**
 * Generated by PHPUnit_SkeletonGenerator on 2016-07-06 at 07:02:52.
 */
include ('/../../../controllers/SiteController.php');
class SiteControllerTest extends \PHPUnit_Framework_TestCase
{
   /*.. basic template of PPHUnit Test when generated in Netbeans ...*/
}

I used the pre-made SiteController in the Basic Template of Yii2. anyway, I still can't find what's wrong with my autoload.php and routing since it can't detect the 'app\web\Controllers' when running the Test File.

I hope anyone can help me with this. I can't find any tutorials regarding with this problem. Thanks.

1

1 Answers

-1
votes

Please use the below code:

<?php
namespace app\controllers;
use controllers/SiteController;

include ('/../../../controllers/SiteController.php');

class SiteControllerTest extends \PHPUnit_Framework_TestCase
{
  ----code Here-----
}