SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    737
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Question PHPUnit: Calling methods inside dataprovider

    Is there anyway I can call a method within the dataprovider method? I tried doing it but the value passed from the dataProvider to the testAdd() method won't just pass. How do I do this?

    PS: I do not want to call this from setUp() or setUpBeforeClass(), any way out?


    PHP Code:
    <?php
    class DataTest extends PHPUnit_Framework_TestCase
    {
        
    /**
         * @dataProvider additionProvider
         */
        
    public function testAdd($a$b$expected$someValue)
        {
            echo 
    $someValue;
            
    $this->assertEquals($expected$a $b);
        }

        public function 
    additionProvider()
        {
            
    $someValue $this->doSomething();

            return array(
              array(
    000$someValue),
              array(
    011$someValue),
              array(
    101$someValue),
              array(
    113$someValue)
            );
        }

        protected function 
    doSomething(){

          return 
    6;

        }
    }
    ?>

    Thanks

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,395
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    This works fine for me. What output are you getting when you run the test?
    "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •