[SOLVED] SimpleTest... undefined property $_reporter.

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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

[SOLVED] SimpleTest... undefined property $_reporter.

Post by Chris Corbyn »

Code: Select all

Notice: Undefined property:  Swift_Mailer_Transport_SmtpTransportTest::$_reporter in /Users/chris/Sites/swiftmailer_v4/tests/lib/simpletest/test_case.php on line 316
Fatal error: Call to a member function getDumper() on a non-object in /Users/chris/Sites/swiftmailer_v4/tests/lib/simpletest/test_case.php on line 316
I've been trying to identify what I'm doing wrong all night and I'm now convinced this is a bug in simpletest, but has anyone encountered it before and know what causes it?

Here's the test... not that it'll make much sense to anyone but me:

Code: Select all

public function testExtensionsAreNotifiedOnCommand()
  {
    $ext1 = new Swift_Mailer_Transport_MockSmtpExtensionHandler();
    $ext1->setReturnValue('getHandledKeyword', 'AUTH');
    $ext1->setReturnValue('getPriorityOver', -1);
    $ext1->expectOnce('onCommand', array($this->_smtp, "FOO\r\n", array(250, 251)));
    
    $ext2 = new Swift_Mailer_Transport_MockSmtpExtensionHandler();
    $ext2->setReturnValue('getHandledKeyword', 'SIZE');
    $ext2->setReturnValue('getPriorityOver', 1);
    $ext2->expectOnce('onCommand', array($this->_smtp, "FOO\r\n", array(250, 251)));
    
    $ext3 = new Swift_Mailer_Transport_MockSmtpExtensionHandler();
    $ext3->setReturnValue('getHandledKeyword', 'STARTTLS');
    $ext3->expectNever('onCommand');
    
    $this->_smtp->setExtensionHandlers(array($ext1, $ext2, $ext3));
    
    $this->_buffer->setReturnValue(
      'readLine', '220 server.com foo' . "\r\n", array(0)
      );
    $this->_buffer->expectAt(
      0, 'write', array(new PatternExpectation('~^EHLO .*?\r\n$~D'))
      );
    $this->_buffer->setReturnValue(
      'write', 1, array(new PatternExpectation('~^EHLO .*?\r\n$~D'))
      );
    $this->_buffer->setReturnValueAt(1,
      'readLine', '250-ServerName.tld' . "\r\n", array(1)
      );
    $this->_buffer->setReturnValueAt(2,
      'readLine', '250-AUTH PLAIN LOGIN' . "\r\n", array(1)
      );
    $this->_buffer->setReturnValueAt(3,
      'readLine', '250 SIZE=123456' . "\r\n", array(1)
      );
    $this->_buffer->setReturnValue('write', 2, array("FOO\r\n"));
    $this->_buffer->setReturnValue('readLine', "251 Cool\r\n", array(2));
    
    $this->_finishBuffer();
    
    $this->_smtp->start();
    
    $this->_smtp->executeCommand("FOO\r\n", array(250, 251));
  }
And here's setUp() where _smtp and _buffer are created:

Code: Select all

 private $_buffer;
  private $_smtp;
  
  public function setUp()
  {
    $this->_buffer = new Swift_Mailer_Transport_MockIoBuffer();
    $this->_smtp = new Swift_Mailer_Transport_SmtpTransport($this->_buffer, array());
  }
And _finishBuffer():

Code: Select all

/**
   * Fill in any gaps <!-- s;) --><img src=\"{SMILIES_PATH}/icon_wink.gif\" alt=\";)\" title=\"Wink\" /><!-- s;) -->
   */
  private function _finishBuffer()
  {
    $this->_buffer->setReturnValue(
      'readLine', '220 server.com foo' . "\r\n", array(0)
      );
    $this->_buffer->setReturnValue(
      'write', $x = uniqid(), array(new PatternExpectation('~^EHLO .*?\r\n$~D'))
      );
    $this->_buffer->setReturnValue(
      'readLine', '250 ServerName' . "\r\n", array($x)
      );
    $this->_buffer->setReturnValue(
      'write', $x = uniqid(), array(new PatternExpectation('~^MAIL FROM: <.*?>\r\n$~D'))
      );
    $this->_buffer->setReturnValue(
      'readLine', '250 OK' . "\r\n", array($x)
      );
    $this->_buffer->setReturnValue(
      'write', $x = uniqid(), array(new PatternExpectation('~^RCPT TO: <.*?>\r\n$~D'))
      );
    $this->_buffer->setReturnValue(
      'readLine', "250 OK\r\n", array($x)
      );
    $this->_buffer->setReturnValue('write', $x = uniqid(), array("DATA\r\n"));
    $this->_buffer->setReturnValue('readLine', "354 Go ahead\r\n", array($x));
    $this->_buffer->setReturnValue('write', $x = uniqid(), array("\r\n.\r\n"));
    $this->_buffer->setReturnValue('readLine', "250 OK\r\n", array($x));
    $this->_buffer->setReturnValue('readLine', false); //default return
  }
I'll post on the SimpleTest bugs list too.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: SimpleTest... undefined property $_reporter.

Post by Jenk »

Should you not be instantiating mocks ala:

Code: Select all

$ext1 = new Swift_Mailer_Transport_MockSmtpExtensionHandler($this);
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: SimpleTest... undefined property $_reporter.

Post by Chris Corbyn »

No. That was deprecated and the constructor doesn't do anything with parameters anymore ;) The mocks use SimpleTest::getContext()->getTest() to find the currently running test.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: SimpleTest... undefined property $_reporter.

Post by Chris Corbyn »

Figured it out. I had a destructor which was running some methods on my mock objects (correctly) after SimpleTest has already finished. I just forced the running of the destructor in tearDown() instead and added a condition to the destructor to ensure it never runs twice.
lastcraft
Forum Commoner
Posts: 80
Joined: Sat Jul 12, 2003 10:31 pm
Location: London

Re: SimpleTest... undefined property $_reporter.

Post by lastcraft »

Hi...
Chris Corbyn wrote:Figured it out. I had a destructor which was running some methods on my mock objects (correctly) after SimpleTest has already finished. I just forced the running of the destructor in tearDown() instead and added a condition to the destructor to ensure it never runs twice.
SimpletTest should have run the destructor at the correct time (by going out of scope) whilst within the exception and error traps, even after a test failure. The good news is that it now does this. You could check out the latest SVN release to tidy up your test.

yours, Marcus
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: SimpleTest... undefined property $_reporter.

Post by Chris Corbyn »

lastcraft wrote:Hi...
Chris Corbyn wrote:Figured it out. I had a destructor which was running some methods on my mock objects (correctly) after SimpleTest has already finished. I just forced the running of the destructor in tearDown() instead and added a condition to the destructor to ensure it never runs twice.
SimpletTest should have run the destructor at the correct time (by going out of scope) whilst within the exception and error traps, even after a test failure. The good news is that it now does this. You could check out the latest SVN release to tidy up your test.

yours, Marcus
Cheers Marcus :)

Am I using the correct path in my external since you moved to svn?

Code: Select all

w3style:se chris$ svn info test-suite/lib/simpletest-svn
Path: test-suite/lib/simpletest-svn
URL: https://simpletest.svn.sourceforge.net/ ... test/trunk
Repository Root: https://simpletest.svn.sourceforge.net/ ... simpletest
Repository UUID: 9ad96551-d73f-0410-9433-afe301b4b3ac
Revision: 1659
Node Kind: directory
Schedule: normal
Last Changed Author: pp11
Last Changed Rev: 1659
Last Changed Date: 2008-02-18 23:42:54 +1100 (Mon, 18 Feb 2008)
Post Reply