Welcome Guest, Not a member yet? Register   Sign In
Is it possible to run CI3 unit tests without sudo privileges?
#1

I don't know how extensively unit testing was used in CI3, but I was reading the instructions in the tests/README.md file and they seem quite preliminary -- and require you to install PEAR packages and stuff. Does anyone have experience running the CI3 unit tests? Is it possible to do this using composer instead of installing system-wide packages with PEAR?
Reply
#2

See https://github.com/kenjis/ci-phpunit-test
Reply
#3

(03-07-2023, 06:06 PM)kenjis Wrote: See https://github.com/kenjis/ci-phpunit-test

Thank you, @kenjis, for this suggestion. I'm finally getting around to trying it.

I note that the steps you outline in your README results in a LOT of files being added to one's application folder. The ci-phpunit-test-3.0.4/application/tests folder has 1025 files in it, including 4 shell scripts, 669 PHP files, and hundreds of other files. I also note that running install.php doesn't appear to change any files, at least none that git can detect.

Also, I ran into an error installing phpunit via composer:
Code:
$ ./composer.phar require phpunit/phpunit --dev
./composer.json has been updated
Running composer update phpunit/phpunit
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
25 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> sed -i s/name{0}/name[0]/ vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStream.php
sed: 1: "vendor/mikey179/vfsstre ...": invalid command code v
Script sed -i s/name{0}/name[0]/ vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStream.php handling the post-update-cmd event returned with error code 1

Finally, the tests would not run.
Code:
$ vendor/bin/phpunit -c application/tests/
PHPUnit 9.6.5 by Sebastian Bergmann and contributors.

Error in bootstrap script: ArgumentCountError:
Too few arguments to function CI_Hooks::__construct(), 0 passed in /private/tmp/foo/CodeIgniter-develop/application/tests/_ci_phpunit_test/replacing/core/Common.php on line 111 and exactly 1 expected
#0 /private/tmp/foo/CodeIgniter-develop/application/tests/_ci_phpunit_test/replacing/core/Common.php(111): CI_Hooks->__construct()
#1 /private/tmp/foo/CodeIgniter-develop/application/tests/_ci_phpunit_test/replacing/core/CodeIgniter.php(202): load_class('Hooks', 'core')
#2 /private/tmp/foo/CodeIgniter-develop/application/tests/_ci_phpunit_test/CIPHPUnitTest.php(118): require('/private/tmp/fo...')
#3 /private/tmp/foo/CodeIgniter-develop/application/tests/_ci_phpunit_test/CIPHPUnitTest.php(70): CIPHPUnitTest::loadCodeIgniter()
#4 /private/tmp/foo/CodeIgniter-develop/application/tests/Bootstrap.php(389): CIPHPUnitTest::init()
#5 /private/tmp/foo/CodeIgniter-develop/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once('/private/tmp/fo...')
#6 /private/tmp/foo/CodeIgniter-develop/vendor/phpunit/phpunit/src/Util/FileLoader.php(49): PHPUnit\Util\FileLoader::load('/private/tmp/fo...')
#7 /private/tmp/foo/CodeIgniter-develop/vendor/phpunit/phpunit/src/TextUI/Command.php(565): PHPUnit\Util\FileLoader::checkAndLoad('/private/tmp/fo...')
#8 /private/tmp/foo/CodeIgniter-develop/vendor/phpunit/phpunit/src/TextUI/Command.php(345): PHPUnit\TextUI\Command->handleBootstrap('/private/tmp/fo...')
#9 /private/tmp/foo/CodeIgniter-develop/vendor/phpunit/phpunit/src/TextUI/Command.php(112): PHPUnit\TextUI\Command->handleArguments(Array)
#10 /private/tmp/foo/CodeIgniter-develop/vendor/phpunit/phpunit/src/TextUI/Command.php(97): PHPUnit\TextUI\Command->run(Array, true)
#11 /private/tmp/foo/CodeIgniter-develop/vendor/phpunit/phpunit/phpunit(98): PHPUnit\TextUI\Command::main()
#12 /private/tmp/foo/CodeIgniter-develop/vendor/bin/phpunit(123): include('/private/tmp/fo...')
#13 {main}
Reply
#4

(This post was last modified: 03-21-2023, 04:11 PM by kenjis.)

See https://stackoverflow.com/questions/7313...-vfsstream

I don't know the phpunit error.
Can you show your environment? OS, PHP, CI3 version?
Reply
#5

(03-21-2023, 04:09 PM)kenjis Wrote: See https://stackoverflow.com/questions/7313...-vfsstream
I had seen a lot of posts instructing one to change various lines to lowercase in composer.json but this didn't work on my machine. I eventually saw this SO post saying there's an issue with the sed command which causes a problem on MacOS. I've been unable to find a solution yet for it. However, composer appears to install phpunit, and I can get it to report its version:
Code:
$ vendor/bin/phpunit --version
PHPUnit 9.6.5 by Sebastian Bergmann and contributors.

(03-21-2023, 04:09 PM)kenjis Wrote: I don't know the phpunit error.
Can you show your environment? OS, PHP, CI3 version?

I'm running MacOS 10.15.7:
Code:
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.7
BuildVersion: 19H2026

My PHP version is 8.2.3, installed via brew:
Code:
$ php -v
PHP 8.2.3 (cli) (built: Feb 24 2023 10:25:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.3, Copyright (c), by Zend Technologies

I've tried both the CI3 dev branch from about an hour ago (I think this is a6faab2 commit from Jan 26), and the gxgpet 8.2 pull request -- both of these report CI_VERSION of 3.2.0-dev. The CI3 dev branch barfs a lot of deprecated complaints because the devs haven't applied the 8.2 fix.
Reply
#6

ci-phpunit-test works with release versions of CI3.
If APIs change in develop branch, it probably does not work.
Reply
#7

(03-21-2023, 04:59 PM)kenjis Wrote: ci-phpunit-test works with release versions of CI3.
If APIs change in develop branch, it probably does not work.

Sad! Seems to me that the dev branch is precisely where we need unit testing the most.
Reply
#8

ci-phpunit-test replaces some files in CI3,
because CI3 app is basically untestable without modifications.
All these files are located in tests/_ci_phpunit_test/replacing/

And if you want to work with CI3 develop version, you need to update these files.
See https://github.com/kenjis/ci-phpunit-test/pull/140
The PR may show you what you do.
Reply
#9

(03-21-2023, 05:24 PM)kenjis Wrote: ci-phpunit-test replaces some files in CI3,
because CI3 app is basically untestable without modifications.
All these files are located in tests/_ci_phpunit_test/replacing/

Do you mean to say that using kenjis/ci-phpunit-test requires that I replace core CodeIgniter system files? Does this happen automatically when you run ci-phpunit-test/install.php? Or must I replace these files manually? I just downloaded the latest release, CI 3.1.13, from here and ran your install instructions here and I can't see that any changes have been made to the native CodeIgniter system files (CodeIgniter.php, Common.php, etc.). The installer does report a lot of files being copied, but my git repo reports no file changes after I run your install.php.

(03-21-2023, 05:24 PM)kenjis Wrote: And if you want to work with CI3 develop version, you need to update these files.
See https://github.com/kenjis/ci-phpunit-test/pull/140
The PR may show you what you do.

Hmmm...I don't think I'm the right person to update ci-phpunit-test to work with the develop branch of CI3 (3.2-dev). I've only just attempted to use it and don't have a feel for how it works -- or why are there so many files?. It seems to me like quite an involved installation just to do some unit testing. Am I correct in thinking that most of those 650+ PHP files that you install are unit tests, and that CI3 doesn't come with any unit tests of its own?

Incidentally, I just noticed that there are no releases for CI3 on github. Seems like an oversight by the repo maintainers.
Reply
#10

(03-22-2023, 12:41 PM)sneakyimp Wrote: Does this happen automatically when you run ci-phpunit-test/install.php?

ci-phpunit-test/install.php is a just installer. It installs customized CI3 files.
And ci-phpunit-test use them when you run phpunit.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB