Missing argument 1 for PicturesTest::testAddition() in

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Missing argument 1 for PicturesTest::testAddition() in

Post by kpraman »

Code: Select all

<?php


  $pictureName=$_FILES['photo']['name'];
  $tmp_filename=$_FILES['photo']['tmp_name'];


  class PicturesTest extends PHPUnit_TestCase {
 
           function testAddition($pictureName)
                   {
                        echo $pictureName;
                    }

}

 $suite  = new PHPUnit_TestSuite('PicturesTest');
 $result = PHPUnit::run($suite);
 
 print $result->toHTML();

$new=new PicturesTest;

$new->testAddition($pictureName);

?>
I am getting error

Missing argument 1 for PicturesTest::testAddition()
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

PHPUnit is trying to run the method because it starts with "test". PHPUnit does not pass arguments to test methods (why would it?).

What exactly are you trying to test?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

It doesn't look like $pictureName is being set before you call testAddition()
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

aaronhall wrote:It doesn't look like $pictureName is being set before you call testAddition()
No, that's not the problem. Unit testing frameworks blindly run any methods which start with the name "test" such as "testFoo" "testing" etc etc. They don't pass arguments, they just run them. That's where the error comes from. Since the method is part of the test suite (i.e. it extends PHPUnit_TestCase) then it's being run automatically.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Gotcha -- sorry to make you repeat yourself.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

I made a mistake,

function testAddition($pictureName)


No need of parameter.
Post Reply