/** * Authenticate with the Whatsapp Server. * * @param Connection $connection * @param Identity $identity * @param string $challengeData * @return string Returns binary string */ protected function getAuthData(Connection $connection, Identity $identity, $challengeData) { $keys = KeyStream::generateKeys(base64_decode($identity->getPassword()), $challengeData); $connection->setInputKey($this->createKeyStream($keys[2], $keys[3])); $connection->setOutputKey($this->createKeyStream($keys[0], $keys[1])); $array = "" . $identity->getPhone()->getPhoneNumber() . $challengeData; $response = $connection->getOutputKey()->encodeMessage($array, 0, 4, strlen($array) - 4); return $response; }
public function testReadDataMethod() { $data = 'mydata'; $adapterMock = m::mock('Tmv\\WhatsApi\\Connection\\Adapter\\AdapterInterface'); $adapterMock->shouldReceive('readData')->once()->andReturn($data); $object = new Connection($adapterMock); $ret = $object->readData(); $this->assertEquals($data, $ret); }