?
avatar venomDeved
venomDeved
4 Apr 2018

Steps to reproduce the issue

Run composer install from fresh git clone.
Run /libraries/vendor/bin/phpunit

Expected result

PHPunit to run all tests through til the end

Actual result

stops at test 61 with a $_SERVER['SCRIPT_NAME'] error

Additional comments

I suspect that the $_SERVER['SCRIPT_NAME'] is being cleared in one of the included Joomla required files for the PHPunit tests.

PHPunit output

➜  joomla-cms git:(phpunit) ✗ libraries/vendor/bin/phpunit
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS......SS   61 / 5834 (  1%)
SSSSSSSSSSSSSSS.......SSSSSSSSSSSSSSSSSEUndefined index: SCRIPT_NAME

User deprecation notices (85)

JError::setErrorHandling() is deprecated: 84x
    21x in JComponentRouterViewconfigurationTest::setUp
    21x in JComponentRouterViewconfigurationTest::tearDown
    12x in JComponentRouterLegacyTest::setUp
    12x in JComponentRouterLegacyTest::tearDown
    6x in JComponentRouterBaseTest::setUp
    6x in JComponentRouterBaseTest::tearDown
    3x in JComponentRouterRulesNomenuTest::setUp
    3x in JComponentRouterRulesNomenuTest::tearDown

JApplication is deprecated: 1x
    1x in JComponentRouterBaseTest::testConstruct
avatar venomDeved venomDeved - open - 4 Apr 2018
avatar joomla-cms-bot joomla-cms-bot - change - 4 Apr 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 4 Apr 2018
avatar venomDeved venomDeved - change - 4 Apr 2018
The description was changed
avatar venomDeved venomDeved - edited - 4 Apr 2018
avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Apr 2018
Category Libraries
avatar laoneo
laoneo - comment - 5 Apr 2018

Does it work with composer install?

avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Apr 2018
Status New Information Required
avatar venomDeved
venomDeved - comment - 5 Apr 2018

No, I've done composer install and composer update both from a fresh git clone in a new branch called phpunit.

avatar rdeutz
rdeutz - comment - 5 Apr 2018

Can't reposduce the problem locally, please add "--testdox" to the phpunit call so we seen which test is falling. What's your PHP version and OS?

avatar venomDeved
venomDeved - comment - 6 Apr 2018

PHP 7.2 running on linux mint 18.2
I had an issue running PHPunit on PHP 7.1, one of the required libraries in the vendor directory threw an exception.

joomla-cms git:(phpunit) ✗ php --version
PHP 7.2.4-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Apr  5 2018 08:53:57) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.4-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

PHPunit with the --testdox option

joomla-cms git:(phpunit) ✗ libraries/vendor/bin/phpunit --testdox
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

JApplicationAdministrator
 [ ] Get client id
 [ ] Get name
 [ ] Get menu
 [ ] Get pathway
 [ ] Get router
 [ ] Get template
 [ ] Is admin
 [ ] Is site
 [ ] Is client
 [ ] Render

JApplicationCms
 [ ] construct
 [ ] constructDependancyInjection
 [ ] Execute without document
 [ ] Execute with document
 [ ] Get
 [ ] Get cfg
 [ ] Get instance
 [ ] Get menu
 [ ] Get pathway
 [ ] Get router
 [ ] Get template
 [ ] Is admin
 [ ] Is site
 [ ] Is client
 [ ] Redirect
 [ ] Redirect legacy
 [ ] Redirect legacy with empty message and empty status
 [ ] Redirect with headers sent
 [ ] Redirect with javascript redirect
 [ ] Redirect with moved
 [ ] Redirect with url
 [ ] Render

JApplicationSite
 [ ] Get client id
 [ ] Get name
 [ ] Get menu
 [ ] Get params
 [ ] Get pathway
 [ ] Get router
 [ ] Get template
 [ ] Is admin
 [ ] Is site
 [ ] Is client
 [ ] Render
 [ ] Set get detect browser
 [ ] Set get language filter
 [ ] Set template

JComponentHelper
 [ ] Get component
 [ ] GetComponent falseComponent
 [ ] GetComponent falseComponent strict
 [ ] Is enabled
 [ ] Is installed
 [ ] Get params

JComponentRouterBase
 [x] Construct
 [x] Preprocess

JComponentRouterLegacy
 [x] Construct
 [x] Preprocess
 [x] Build
 [x] Parse

JComponentRouterView
 [ ] Register view
 [ ] Get views
 [ ] Get path
 [ ] Get rules
 [ ] Attach rules
 [ ] Attach rule
 [ ] Detach rule
 [ ] Preprocess
 [ ] Build
 [ ] Parse
 [ ] Get name
 [ ] Get name exception

JComponentRouterViewconfiguration
 [x] Construct
 [x] Set name
 [x] Set key
 [x] Set parent
 [x] Set nestable
 [x] Add layout
 [x] Remove layout

JComponentRouterRulesMenu
 [ ] Construct
 [ ] Preprocess
 [ ] Preprocess language
 [ ] Preprocess active
 [ ] Preprocess layout
 [ ] Build lookup

JComponentRouterRulesNomenu
Undefined index: SCRIPT_NAME

User deprecation notices (85)

JError::setErrorHandling() is deprecated: 84x
    21x in JComponentRouterViewconfigurationTest::setUp
    21x in JComponentRouterViewconfigurationTest::tearDown
    12x in JComponentRouterLegacyTest::setUp
    12x in JComponentRouterLegacyTest::tearDown
    6x in JComponentRouterBaseTest::setUp
    6x in JComponentRouterBaseTest::tearDown
    3x in JComponentRouterRulesNomenuTest::setUp
    3x in JComponentRouterRulesNomenuTest::tearDown

JApplication is deprecated: 1x
    1x in JComponentRouterBaseTest::testConstruct
avatar csthomas
csthomas - comment - 6 Apr 2018

Do you have configuration.php file created? Unit test does not require it.

avatar venomDeved
venomDeved - comment - 6 Apr 2018

There's no configuration.php, this is pretty much a fresh clone from the joomla-cms repo with a new branch called phpunit and then running the command composer install

avatar csthomas
csthomas - comment - 6 Apr 2018

I had the same in J3.x but I do not remember what I did to fix that.
Maybe you have some (untracked) files from other branch: 4.0-dev vs staging

avatar venomDeved
venomDeved - comment - 6 Apr 2018

I have cloned the joomla-cms main branch which seems to be staging. I haven't checked out any other branches or mixed this with another branch. Strictly followed these steps

git clone https://github.com/joomla/joomla-cms.git joomla-cms
cd joomla-cms
git checkout -b phpunit
composer install
libraries/vendor/bin/phpunit --testdox
avatar franz-wohlkoenig franz-wohlkoenig - change - 7 Apr 2018
Status Information Required Discussion
avatar rdeutz
rdeutz - comment - 7 Apr 2018

I don't have a good idea besides using a debugger and finding out what is the problem.

avatar zero-24
zero-24 - comment - 7 Apr 2018

@venomDeved can you try to execute a script that checks if $_SERVER['SCRIPT_NAME'] is defined in your setup? Maybe there is a problem in the server config that SCRIPT_NAME is not defined at all by the server. ;)

avatar csthomas
csthomas - comment - 7 Apr 2018

Maybe some php module is missing, ex: sqlite3, xml

avatar venomDeved
venomDeved - comment - 7 Apr 2018

So I made a quick die() debug in tests/unit/core/case/case.php with 2 additional parts

This is a new function added to case.php taken from
libraries/vendor/phpunit/phpunit/src/framework/TestCase.php

    public function __construct($name = null, array $data = array(), $dataName = '') {

		parent::__construct($name, $data, $dataName);
		echo "\$_SERVER:\n";
		print_r($_SERVER);
	}

and then this code is added to case.php in the setUp function

	protected function setUp()
	{
		echo "\$_SERVER:\n";
		print_r($_SERVER);
		die();		
		

		$this->setExpectedError();

		parent::setUp();
	}

output for __construct()

$_SERVER:
...
    [PHP_SELF] => libraries/vendor/bin/phpunit
    [SCRIPT_NAME] => libraries/vendor/bin/phpunit
    [SCRIPT_FILENAME] => libraries/vendor/bin/phpunit
    [PATH_TRANSLATED] => libraries/vendor/bin/phpunit
...

output for setUp()

JComponentRouterBase
$_SERVER:

which means $_SERVER has been completely wiped out at some point

avatar jpomer
jpomer - comment - 4 Jun 2018

Finally i found the problem.
In my case was a missing php extension.

Is common to be missing sqlite3 and zip. In my case was on only php7.1-zip.

You can check your modules using this linux command.
dpkg --get-selections | grep php

Here are my php modules for php 7.1
php7.1-cli install
php7.1-common install
php7.1-curl install
php7.1-gd install
php7.1-intl deinstall
php7.1-json install
php7.1-ldap install
php7.1-mbstring install
php7.1-mcrypt install
php7.1-mysql install
php7.1-opcache install
php7.1-readline install
php7.1-soap deinstall
php7.1-sqlite3 install
php7.1-xml install
php7.1-zip install

sudo apt-get install php7.1-sqlite3 php7.1-zip to fix the problem ;)

Remember restart apache

avatar brianteeman
brianteeman - comment - 4 Jun 2018

Glad to hear you found the problem

avatar brianteeman brianteeman - change - 4 Jun 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-06-04 08:13:55
Closed_By brianteeman
avatar brianteeman brianteeman - close - 4 Jun 2018
avatar csthomas
csthomas - comment - 4 Jun 2018

It would be good practice to inform you (Joomla should do that) which php extensions are required on starting unit tests.

avatar venomDeved
venomDeved - comment - 4 Jun 2018

Yep solved, thanks

avatar byungwook-kim
byungwook-kim - comment - 20 Jun 2018

I faced with the same problem.
$_SERVER variable is null at setUp().
Please, explain the way how to solve this problem.

avatar csthomas
csthomas - comment - 20 Jun 2018

You have to install or/and enable some missing php modules on your server, check if you have:
php-zip
php-xml
php-sqlite3

To see the list of enabled modules, you can run the php -m command.

My installed php version contains a lot of optional modules:

[PHP Modules]
apcu
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
json
ldap
libxml
mbstring
mcrypt
memcached
msgpack
mysqli
mysqlnd
openssl                                                                                                                                                      
pcntl                                                                                                                                                        
pcre                                                                                                                                                         
PDO                                                                                                                                                          
pdo_dblib                                                                                                                                                    
pdo_mysql                                                                                                                                                    
pdo_pgsql                                                                                                                                                    
pdo_sqlite                                                                                                                                                   
pdo_sqlsrv                                                                                                                                                   
pgsql                                                                                                                                                        
Phar                                                                                                                                                         
posix                                                                                                                                                        
readline                                                                                                                                                     
redis
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
sqlsrv
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache
avatar byungwook-kim
byungwook-kim - comment - 20 Jun 2018

Yes, my PHP modules have the followings: by "php -m"

[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mhash
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
readline
Reflection
session
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zip
zlib

avatar csthomas
csthomas - comment - 20 Jun 2018

@byungwook-kim Did you solve the problem?

avatar byungwook-kim
byungwook-kim - comment - 20 Jun 2018

Not yet.
I can't find a way to solve the problem.

avatar byungwook-kim
byungwook-kim - comment - 21 Jun 2018

@venomDeved Could you explain how to solve this problem?

avatar venomDeved
venomDeved - comment - 21 Jun 2018

Installing the sqlite3 module worked for me.

What version of PHP are you using?

Are you also using the PHPUnit file in the libraries/vendor/bin folder?

avatar byungwook-kim
byungwook-kim - comment - 28 Jun 2018

@venomDeved
In my case, the sqlite3 module is already installed on PHP version 5.6.31
I didn't install the PHPUnit on libraries/vendor/bin folder.
It's needed to install the PHPUnit on libraries/vendor/bin folder ?

avatar venomDeved
venomDeved - comment - 28 Jun 2018

I think you might need PHP v7 but yeah definitely run composer install and use the libraries/vendor/bin/PHPUnit for testing

avatar byungwook-kim
byungwook-kim - comment - 5 Jul 2018

@venomDeved
I installed PHP v7 (7.1.9) and libraries/vendor/bin/PHPUnit using composer.
But the above issue was not solved.

avatar venomDeved
venomDeved - comment - 5 Jul 2018

Are all the modules now installed for PHP v7?

And is PHP v7 your default run version?

avatar byungwook-kim
byungwook-kim - comment - 5 Jul 2018

@venomDeved

Sure, I checked already some PHP functions for version 7.
for "php --version " displayed as following:

PHP 7.1.19 (cli) (built: Jun 21 2018 07:32:04) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

Add a Comment

Login with GitHub to post a comment