Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    908
    Thanks
    301
    Thanked 2 Times in 2 Posts

    Question Calling a method of a Test Class from another Test class

    I am using PHPUnit to unit test my application (using Zend Framework 2). I am stuck in a situation where I need to call a method that is in one test class from another test class. Let me explain myself with a small example:

    PHP Code:
    <?php
    // TestUser.php
    namespace TestUser;

    class 
    UserTest extends PHPUnit_Framework_TestCase
    {

        public static function 
    GetUserCount(){

            
    // some code here

        
    }

    }

    ?>

    <?php
    // TestAdmin.php
    namespace TestAdmin;

    use 
    TestUser;

    class 
    AdminTest extends PHPUnit_Framework_TestCase
    {

        public static function 
    AdminAction(){

            
    TestUser::GetUserCount();

        }

    }

    ?>
    When I call the Test\User::GetUserCount(); or User::GetUserCount(); I get the following error:

    PHP Fatal error: Class 'Test\User' not found in path/to/TestAdmin.php on line 11

    Any idea if the method is callable from one test class to another test class? If yes, how?

    Thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You'd need to import using use \TestUser\UserTest; for starters, but that also assumes that its registered to autoload via namespace.

    Otherwise, none of the errors you have posted match these classes.

    I haven't a clue if PHPUnit works that way or not though.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

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