Welcome Guest, Not a member yet? Register   Sign In
Need help with Test
#1

Hello,

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)?
Reply
#2

(This post was last modified: 08-27-2018, 02:08 AM by anthos1984.)

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

I suppose the test is run from project root folder
Reply
#3

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

(08-27-2018, 06: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
Reply
#5

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.
Reply
#6

These the output:


Code:
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?
Reply
#7

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):
Code:
"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

(spec):
Code:
"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
Reply
#8

(08-29-2018, 12: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.

Code:
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:
<?php
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;
Reply
#9

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
Reply
#10

(This post was last modified: 09-05-2018, 02:13 AM by puschie.)

the cli command for my environment is :
Code:
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 :

Code:
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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB