FeaturesPluginsDocs & SupportCommunityPartners

NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

PHPUnit - No tests executed

 
Post new topic   Reply to topic    NetBeans Forums -> PHP Users
View previous topic :: View next topic  
Author Message
laurin1



Joined: 20 Nov 2008
Posts: 52

PostPosted: Thu Oct 08, 2009 3:47 pm    Post subject: PHPUnit - No tests executed Reply with quote

I am new to PHPUnit, and cannot seem to get it to work. I seem to have it all set up correctly, but I get "No tests executed".

This is my sample PHPUnit test file:

Code:

<?php
require_once 'PHPUnit/Framework.php';

class ApplicationsTest extends PHPUnit_Framework_Assert{

   private $sUserName   = 'keithdavis';
   private $iUserID   = 1;

   public function testArrays(){

      $this->assertTrue(UserIDByName($this->sUserName) == $this->iUserID, "Failed!");

   }
   
}
?>


It's in a file called ApplicationsTest.php and I have a class called Applications in Applications.php.

Yet, nothing. Any hints to what I might be doing wrong?
Back to top
View user's profile Send private message
Tomas Mysik
Posted via mailing list.





PostPosted: Fri Oct 09, 2009 7:17 am    Post subject: PHPUnit - No tests executed Reply with quote

Hi,

Dne čtvrtek 08 října 2009 17:47:35 laurin1 napsal(a):
Quote:
class ApplicationsTest extends PHPUnit_Framework_Assert{

this is not correct, you want to extend PHPUnit_Framework_TestCase.
BTW on any PHP file (in Projects view), it is possible to invoke context menu
and call Tools > Create PHPUnit tests.

Tomas
--
Tomas Mysik
address-removed
Back to top
laurin1



Joined: 20 Nov 2008
Posts: 52

PostPosted: Fri Oct 09, 2009 12:48 pm    Post subject: Reply with quote

The why do the examples in the documentation have it like this? Here is example 4.1 from the docs:
Code:

<?php
require_once 'PHPUnit/Framework.php';
class StackTest extends PHPUnit_Framework_TestCase{   

public function testPushAndPop()    {       

$stack = array();       
$this->assertEquals(0, count($stack));         
array_push($stack, 'foo');       
$this->assertEquals('foo', $stack[count($stack)-1]);       
$this->assertEquals(1, count($stack));         
$this->assertEquals('foo', array_pop($stack));       
$this->assertEquals(0, count($stack));   

}

}

?>
Back to top
View user's profile Send private message
laurin1



Joined: 20 Nov 2008
Posts: 52

PostPosted: Fri Oct 09, 2009 12:58 pm    Post subject: Reply with quote

I am trying to use the create tests option, but I get lots of errors. Initially, it was a function that is normally loaded in common.php was not found. I added a require_once for common.php in my source that I want to create tests for, and now I get a bunch of warnings, and two fatal errors:

PHP Fatal error: require_once(): Failed opening required '/library/classes/adLDAP.php' (include_path='.;C:\PHP\PEAR\pear;C:\PHP\pear;C:\inetpub\3rd Party Apps;c:\php\includes') in c:\inetpub\intranet_local\library\common.php on line 336

PHP Fatal error: require_once(): Failed opening required '/library/classes/Table.php' (include_path='.;C:\PHP\PEAR\pear;C:\PHP\pear;C:\inetpub\3rd Party Apps;c:\php\includes') in c:\inetpub\intranet_local\library\common.php on line 336

These classes are loaded with _autoload():

Code:

function __autoload($sClassName){

   if(substr($sClassName, -6) == '_class') $sClassName = str_ireplace('_class', '', $sClassName);

   require_once $_SERVER['DOCUMENT_ROOT'].'/library/classes/'.$sClassName.'.php';

}


All of this works fine normally. It looks like the create tests function does not have access to the server variables.
Back to top
View user's profile Send private message
laurin1



Joined: 20 Nov 2008
Posts: 52

PostPosted: Fri Oct 09, 2009 1:01 pm    Post subject: Reply with quote

Oh, and then the path I had to use for my source file to load common.php (../common.php), is invalid during normal usage, and so it fails to load during normal usage. I don't understand.
Back to top
View user's profile Send private message
Tomas Mysik
Posted via mailing list.





PostPosted: Fri Oct 09, 2009 1:13 pm    Post subject: PHPUnit - No tests executed Reply with quote

Hi,

Dne pátek 09 října 2009 14:48:36 laurin1 napsal(a):
Quote:
class StackTest extends PHPUnit_Framework_TestCase{

documentation is apparently correct, your code is not.

Tomas
--
Tomas Mysik
address-removed
Back to top
Tomas Mysik
Posted via mailing list.





PostPosted: Fri Oct 09, 2009 1:15 pm    Post subject: PHPUnit - No tests executed Reply with quote

Hi,

Dne pátek 09 října 2009 14:58:41 laurin1 napsal(a):
Quote:
PHP Fatal error: require_once(): Failed opening required
'/library/classes/adLDAP.php'
(include_path='.;C:\PHP\PEAR\pear;C:\PHP\pear;C:\inetpub\3rd Party
Apps;c:\php\includes') in c:\inetpub\intranet_local\library\common.php on
line 336

PHP Fatal error: require_once(): Failed opening required
'/library/classes/Table.php'
(include_path='.;C:\PHP\PEAR\pear;C:\PHP\pear;C:\inetpub\3rd Party
Apps;c:\php\includes') in c:\inetpub\intranet_local\library\common.php on
line 336

These classes are loaded with _autoload():

of course, I don't know your particular use case, but you likely want to
provide a bootstrap file, see our blog [1] and PHPUnit documentation for more
information.

Tomas
[1]
http://blogs.sun.com/netbeansphp/entry/recent_improvements_in_phpunit_support
--
Tomas Mysik
address-removed
Back to top
laurin1



Joined: 20 Nov 2008
Posts: 52

PostPosted: Fri Oct 09, 2009 1:16 pm    Post subject: Reply with quote

Hmm, that wasn't the example I was looking for....darn. Anyway, that's fine, I can fix that part, but I don't know how to get around these require_once errors.
Back to top
View user's profile Send private message
Tomas Mysik
Posted via mailing list.





PostPosted: Fri Oct 09, 2009 1:43 pm    Post subject: PHPUnit - No tests executed Reply with quote

Hi,

Dne pátek 09 října 2009 15:16:15 laurin1 napsal(a):
Quote:
I don't know how to get around these require_once errors.

see my previous email (about the bootstrap file).

Tomas
--
Tomas Mysik
address-removed
Back to top
laurin1



Joined: 20 Nov 2008
Posts: 52

PostPosted: Fri Oct 09, 2009 2:09 pm    Post subject: Reply with quote

What version of NB is that? I don't have those options:

Back to top
View user's profile Send private message
Tomas Mysik
Posted via mailing list.





PostPosted: Mon Oct 12, 2009 9:48 am    Post subject: PHPUnit - No tests executed Reply with quote

Hi,

Dne pátek 09 října 2009 16:09:34 laurin1 napsal(a):
Quote:
What version of NB is that? I don't have those options:

NB 6.8 Milestone 2 (just released).

Tomas
--
Tomas Mysik
address-removed
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> PHP Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB