• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with Test


I just learn PHPUnit (i am newbie for test suite).

I try setting PHPUnit on netbeans project. I try following user guide.
But no success.

First, Fatal error: Class 'Test\CIUnitTestCase' not found
I modify the test/_support/CIUnitTestCase.php adding : require 'system/Test/CIUnitTestCase.php';

Then another error not found

I just think the path for testing not set properly.
Where the file for set this path (for testing)?

Any people can answer this? The problem is broken path. Where to fix this?

I suppose the test is run from project root folder

Have you checked https://github.com/bcit-ci/CodeIgniter4/...elop/tests

(08-27-2018, 07:33 AM)ciadmin Wrote: Have you checked https://github.com/bcit-ci/CodeIgniter4/...elop/tests

Yes, I have. I have already installed PHPUnit globally. It works on simple projects. But I have trouble to configure it for CI4

You mentioned netbeans, which I also use. However, all my unit testing is done from the command line. If you have phpunit installed globally, then you shuld be able to run "phpunit"
from your project root, with no changes to any CI code, and have the tests complete successfully.

These the output:

H:\wamp306_x64\www\CodeIgniter4-develop>php phpunit-7.3.0.phar -c phpunit.xml UnitTest tests\system\CommonFunctionsTest.php

Fatal error: Class 'CodeIgniter\Test\CIUnitTestCase' not found in H:\wamp306_x64\www\CodeIgniter4-develop\tests\_support\CIUnitTestCase.php on line 5

Call Stack:
   0.0189     833584   1. {main}() H:\wamp306_x64\www\CodeIgniter4-develop\phpunit-7.3.0.phar:0
   0.1778    9536984   2. PHPUnit\TextUI\Command::main() H:\wamp306_x64\www\CodeIgniter4-develop\phpunit-7.3.0.phar:594
   0.1779    9545776   3. PHPUnit\TextUI\Command->run() phar://H:/wamp306_x64/www/CodeIgniter4-develop/phpunit-7.3.0.phar/phpunit/TextUI/Command.php:159
   0.1779    9545776   4. PHPUnit\TextUI\Command->handleArguments() phar://H:/wamp306_x64/www/CodeIgniter4-develop/phpunit-7.3.0.phar/phpunit/TextUI/Command.php:170
   0.2058    9615576   5. PHPUnit\TextUI\Command->handleBootstrap() phar://H:/wamp306_x64/www/CodeIgniter4-develop/phpunit-7.3.0.phar/phpunit/TextUI/Command.php:840
   0.2058    9615576   6. PHPUnit\Util\FileLoader::checkAndLoad() phar://H:/wamp306_x64/www/CodeIgniter4-develop/phpunit-7.3.0.phar/phpunit/TextUI/Command.php:1035
   0.2063    9615864   7. PHPUnit\Util\FileLoader::load() phar://H:/wamp306_x64/www/CodeIgniter4-develop/phpunit-7.3.0.phar/phpunit/Util/FileLoader.php:45
   0.2066    9622256   8. include_once('H:\wamp306_x64\www\CodeIgniter4-develop\tests\_support\_bootstrap.php') phar://H:/wamp306_x64/www/CodeIgniter4-develop/phpunit-7.3.0.phar/phpunit/Util/FileLoader.php:57
   0.2072    9626192   9. require('H:\wamp306_x64\www\CodeIgniter4-develop\tests\_support\CIUnitTestCase.php') H:\wamp306_x64\www\CodeIgniter4-develop\tests\_support\_bootstrap.php:28

How is your CLI command btw?

have an similar problem when i dont set the correct working directory ( which has to be the project directory ). But dont know how to set it via cli, sry.

my execution command is (all):
"C:\PHP Server\7.2.3_TS_64\php.exe" C:/Repos/FlamingaWeb3/vendor/phpunit/phpunit/phpunit --configuration C:\Repos\FlamingaWeb3\phpunit.xml.dist --teamcity

"C:\PHP Server\7.2.3_TS_64\php.exe" C:/Repos/FlamingaWeb3/vendor/phpunit/phpunit/phpunit --configuration C:\Repos\FlamingaWeb3\phpunit.xml.dist --filter "/(::testListFilesWithoutPath)( .*)?$/" CodeIgniter\Autoloader\FileLocatorTest C:\Repos\FlamingaWeb3\tests\system\Autoloader\FileLocatorTest.php --teamcity

(08-29-2018, 01:14 AM)puschie Wrote: have an similar problem when i dont set the correct working directory ( which has to be the project directory ). But dont know how to set it via cli, sry.

Working directory means folder where you work.

C:\>cd [CodeIgniterRoot]
C:\CodeIgniterRoot>"C:\PHP Server\7.2.3_TS_64\php.exe showcwd.php
That will set working directory to C:\CodeIgniterRoot

Supposed showcwd.php

PHP Code:
echo getcwd(); 
Will show 'C:\CodeIgniterRoot'

I also create _bootstrapshow.php which like _bootstrap, but echoing every defined constant to verify the path. It shows correct path, but it can't recognize namespace CodeIgniter\Test;

So no one knows how to repair the missing path then?
I can always include absolute path, but it needs to be included on every file. not good solution

the cli command for my environment is :
C:\Repos\FlamingaWeb3>"C:\PHP Server\7.2.3_TS_64\php.exe" C:\Repos\FlamingaWeb3\vendor\phpunit\phpunit\phpunit --configuration C:\Repos\FlamingaWeb3\phpunit.xml.dist

pls try to customize the command for your usage ( just change the paths ).
specific command for single test file :

C:\Repos\FlamingaWeb3>"C:\PHP Server\7.2.3_TS_64\php.exe" C:\Repos\FlamingaWeb3\vendor\phpunit\phpunit\phpunit --configuration C:\Repos\FlamingaWeb3\phpunit.xml.dist CodeIgniter\Autoloader\FileLocatorTest C:\Repos\FlamingaWeb3\tests\system\Autoloader\FileLocatorTest.php

if this will not work, something is wrong with your environment - try to use the codeigniter phpunit, which can be loaded by composer

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.