Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Senior Member tha_Gsheep's Avatar
    Join Date
    Feb 2003
    Location
    Scotland
    Posts
    188
    Member #
    780
    Heres the problem, I know the classes are working fine individually but when I try and call one as a return value from another I get:

    E_USER_ERROR: Cannot set return reference as no getEvent()
    and
    PHP Fatal error: Call to undefined method MockEventMgr::getEvent()

    The functions are defined in the class. Could someone point out whats wrong please? Thanks.

    PHP Code:
    require_once(class_EventMgr.php);
    require_once(
    class_Event.php);
    require_once(
    simpletest/mockobjects.php);

    Mock::generate('Event');
    Mock::generate('EventMgr');

    class 
    TestEventMgr extends UnitTestCase{
           public 
    $returnedEvent;
           public 
    $mockEventMgr;

    function 
    TestEventMgr(){
        
    $this->UnitTestcase('EventManager');
    }

    function 
    setUp(){
         
    $this->returnedEvent = &new MockEvent($this);
         
    $this->returnedEvent->setReturnedValue('getId'1);
                 
    $this->returnedEvent->setReturnedValue('getName',"amazingMockoEvent");


    $this->mockEventMgr = &new MockEventMgr($this);
    $this->mockEventMgr->setReturnReference('getEvent'$this->returnedEvent1);
    }


    function 
    testGettingAnEvent(){
          
    $this->assertNotNull($this->mockEventMgr->getEvent(1));
    }

    www.appletv.co.uk

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    What's the code that causes the error?

  4. #3
    Senior Member tha_Gsheep's Avatar
    Join Date
    Feb 2003
    Location
    Scotland
    Posts
    188
    Member #
    780
    $this->assertNotNull($this->mockEventMgr->getEvent(1));

    This line causes the error because it claims that getEvent is not Defined. But I set the return reference as the object and there is a function in evenMgr that exists called getvent()
    www.appletv.co.uk

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Are you sure your capitalization and everything is right? Is there any chance you could attach some PHP files with the relevant classes?

  6. #5
    Senior Member tha_Gsheep's Avatar
    Join Date
    Feb 2003
    Location
    Scotland
    Posts
    188
    Member #
    780
    I think I introduced an additional problem by commenting which meant that the getEvent was not being set but the problem remains that the returned object does not seem to work. I've included the exact outputs. There just deosn't seem to be an object of MockEvent being called.

    Here is the terminal output:
    [05-Oct-2006 19:11:31] PHP Fatal error: Call to a member function getEvent() on a non-object in /Applications/MAMP/htdocs/fruity/testarea/simpletests/TestEventMgr.php on line 48


    Here is the TestEventMgr class:
    http://phpfi.com/160589

    Here is the Event Class
    http://phpfi.com/160591
    www.appletv.co.uk

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well, if you're doing unit tests, that indicates that you should probably first assertNotNull on $this->mockEventMgr.

    Are you sure setUp is being called before the test? It looks to me like mockEventMgr is null, which means setUp hasn't run. Maybe, if this is handled by the framework, the method should be called setup instead?

  8. #7
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Also, is MockEventMgr a class that has the same methods as EventMgr?

  9. #8
    Senior Member tha_Gsheep's Avatar
    Join Date
    Feb 2003
    Location
    Scotland
    Posts
    188
    Member #
    780
    I took out the original assertation because I was just adding another layer to the problem. No, the Event class is just a bunch of setters and getters while the EventMgr class is retrieving results from the DB table. There is no real physical implementation of MockEventMgr since I'm using simpletest's Mock::generate('EventMgr'). I was previously using a class based implementation but I understand from the documentation this is the correct way.
    www.appletv.co.uk

  10. #9
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Hmm... I'm not sure what's up, then. It looks like using Mock::generate should take care of creating the associated method, too...

  11. #10
    Senior Member tha_Gsheep's Avatar
    Join Date
    Feb 2003
    Location
    Scotland
    Posts
    188
    Member #
    780
    There was an out of place $this-> call. Pesky things, a most unsatisfying answer. From now on I'll try and write my tests in the scope of just one function before moving them to the setup method to remove the need for $this calls. Thanks for your help and attention shadowfiend.
    www.appletv.co.uk


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:00 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com