public function testEvent() { $server = new Server('', 0); $server->setLog(new Logger('test_application')); $server->init(); $testData = 21; $event1 = new Event(Event::TRIGGER_MAIL_NEW, null, function ($event, $from, $rcpt, $mail) use(&$testData) { #fwrite(STDOUT, 'my function: '.$event->getTrigger().', '.$testData."\n"); $testData = 24; $this->assertEquals('*****@*****.**', $from); $this->assertEquals(array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'), $rcpt); $current = array(); foreach ($mail->getTo() as $n => $address) { $current[] = $address->toString(); } $this->assertEquals(array('Joe User <*****@*****.**>', '<*****@*****.**>'), $current); $this->assertEquals('Here is the subject', $mail->getSubject()); return 42; }); $server->eventAdd($event1); $mail = ''; $mail .= 'Date: Thu, 31 Jul 2014 22:18:51 +0200' . Client::MSG_SEPARATOR; $mail .= 'To: Joe User <*****@*****.**>, to2@example.com' . Client::MSG_SEPARATOR; $mail .= 'From: Mailer <*****@*****.**>' . Client::MSG_SEPARATOR; $mail .= 'Cc: cc@example.com' . Client::MSG_SEPARATOR; $mail .= 'Reply-To: Information <*****@*****.**>' . Client::MSG_SEPARATOR; $mail .= 'Subject: Here is the subject' . Client::MSG_SEPARATOR; $mail .= 'MIME-Version: 1.0' . Client::MSG_SEPARATOR; $mail .= 'Content-Type: text/plain; charset=iso-8859-1' . Client::MSG_SEPARATOR; $mail .= 'Content-Transfer-Encoding: 8bit' . Client::MSG_SEPARATOR; $mail .= '' . Client::MSG_SEPARATOR; $mail .= 'This is the message body.' . Client::MSG_SEPARATOR; $mail .= 'END' . Client::MSG_SEPARATOR; $zmail = Message::fromString($mail); $rcpt = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'); $server->mailNew('*****@*****.**', $rcpt, $zmail); $this->assertEquals(24, $testData); $this->assertEquals(42, $event1->getReturnValue()); }