| View previous topic :: View next topic |
| Author |
Message |
laurin1
Joined: 20 Nov 2008 Posts: 52
|
Posted: Thu Oct 08, 2009 3:47 pm Post subject: PHPUnit - No tests executed |
|
|
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 |
|
 |
Tomas Mysik Posted via mailing list.
|
Posted: Fri Oct 09, 2009 7:17 am Post subject: PHPUnit - No tests executed |
|
|
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
|
Posted: Fri Oct 09, 2009 12:48 pm Post subject: |
|
|
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 |
|
 |
laurin1
Joined: 20 Nov 2008 Posts: 52
|
Posted: Fri Oct 09, 2009 12:58 pm Post subject: |
|
|
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 |
|
 |
laurin1
Joined: 20 Nov 2008 Posts: 52
|
Posted: Fri Oct 09, 2009 1:01 pm Post subject: |
|
|
| 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 |
|
 |
Tomas Mysik Posted via mailing list.
|
Posted: Fri Oct 09, 2009 1:13 pm Post subject: PHPUnit - No tests executed |
|
|
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.
|
Posted: Fri Oct 09, 2009 1:15 pm Post subject: PHPUnit - No tests executed |
|
|
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
|
Posted: Fri Oct 09, 2009 1:16 pm Post subject: |
|
|
| 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 |
|
 |
Tomas Mysik Posted via mailing list.
|
Posted: Fri Oct 09, 2009 1:43 pm Post subject: PHPUnit - No tests executed |
|
|
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
|
Posted: Fri Oct 09, 2009 2:09 pm Post subject: |
|
|
What version of NB is that? I don't have those options:
 |
|
| Back to top |
|
 |
Tomas Mysik Posted via mailing list.
|
Posted: Mon Oct 12, 2009 9:48 am Post subject: PHPUnit - No tests executed |
|
|
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 |
|
 |
|