Skip to content

Commit

Permalink
Finish changes for event handling and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Abramowitz committed Dec 21, 2013
1 parent 153cbfb commit 8c8cd6e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 35 deletions.
23 changes: 9 additions & 14 deletions src/php/whatsprot.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WhatsProt
protected $phoneNumber; // The user phone number including the country code without '+' or '00'.
protected $reader; // An instance of the BinaryTreeNodeReader class.
protected $serverReceivedId; // Confirm that the *server* has received your command.
public $socket; // A socket to connect to the WhatsApp network.
protected $socket; // A socket to connect to the WhatsApp network.
protected $writer; // An instance of the BinaryTreeNodeWriter class.

/**
Expand Down Expand Up @@ -357,7 +357,7 @@ public function connect()
);
} else {
if ($this->debug) {
echo "Firing onConnectError\n";
print_r("Firing onConnectError\n");
}
$this->eventManager()->fireConnectError(
$this->phoneNumber,
Expand Down Expand Up @@ -426,7 +426,7 @@ public function login($profileSubscribe = false)
$this->accountInfo = (array) $this->checkCredentials();
if ($this->accountInfo['status'] == 'ok') {
if ($this->debug) {
echo "New password received: " . $this->accountInfo['pw'] . "\r\n";
print_r("New password received: " . $this->accountInfo['pw'] . "\n");
}
$this->password = $this->accountInfo['pw'];
}
Expand Down Expand Up @@ -1541,8 +1541,6 @@ protected function doLogin($profileSubscribe = false)
if($this->loginStatus != static::CONNECTED_STATUS) {
$data = $this->createAuthResponseNode();
$this->sendNode($data);

file_put_contents('inputKey', serialize($this->inputKey));
$this->reader->setKey($this->inputKey);
$this->writer->setKey($this->outputKey);
}
Expand Down Expand Up @@ -1735,8 +1733,6 @@ protected function processChallenge($node)
*/
protected function processInboundData($data)
{
file_put_contents('messageTest', $data, FILE_APPEND);

try {
$node = $this->reader->nextTree($data);
if( $node != null ) {
Expand Down Expand Up @@ -2230,13 +2226,12 @@ protected function processUploadResponse($node)
$messageNode = @$this->mediaQueue[$id];
if ($messageNode == null) {
//message not found, can't send!
$this->eventManager()->fire ("onMediaUploadFailed", array(
$this->phoneNumber,
$id,
$node,
$messageNode,
"Message node not found in queue"
)
$this->eventManager()->fireMediaUploadFailed(
$this->phoneNumber,
$id,
$node,
$messageNode,
"Message node not found in queue"
);
return false;
}
Expand Down
13 changes: 1 addition & 12 deletions tests/TestWhatsProt.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?php
require_once '../src/php/whatsprot.class.php';

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of WhatsProtTest
*
* @author daniel
* Used to expose protected methods to the testing framework.
*/
class TestWhatsProt extends WhatsProt {
public function processInboundDataNode(ProtocolNode $node) {
parent::processInboundDataNode($node);
}
public function setKey($key) {
$this->reader->setKey($key);
}
}
11 changes: 2 additions & 9 deletions tests/WhatsAppEventListenerCapture.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<?php
require_once '../src/php/events/WhatsAppEventListenerProxy.php';

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of WhatsAppEventListenerCapture
*
* @author daniel
* Records all calls to the WhatsAppEventListener so they can be analyzed
* and asserted by the testing framework.
*/
class WhatsAppEventListenerCapture extends WhatsAppEventListenerProxy {
private $capture = array();
Expand Down

0 comments on commit 8c8cd6e

Please sign in to comment.