<NME> SaslPlainTest.php
<BEF> ADDFILE
<MSG> add SASL plain mechanism unit tests

<DFF> @@ -0,0 +1,111 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
+// +---------------------------------------------------------------------------
+// | SWAN [ $_SWANBR_SLOGAN_$ ]
+// +---------------------------------------------------------------------------
+// | Copyright $_SWANBR_COPYRIGHT_$
+// +---------------------------------------------------------------------------
+// | Version  $_SWANBR_VERSION_$
+// +---------------------------------------------------------------------------
+// | Licensed ( $_SWANBR_LICENSED_URL_$ )
+// +---------------------------------------------------------------------------
+// | $_SWANBR_WEB_DOMAIN_$
+// +---------------------------------------------------------------------------
+
+namespace KafkaTest\Base;
+
+/**
++------------------------------------------------------------------------------
+* Kafka protocol since Kafka v0.8
++------------------------------------------------------------------------------
+*
+* @package
+* @version $_SWANBR_VERSION_$
+* @copyright Copyleft
+* @author $_SWANBR_AUTHOR_$
++------------------------------------------------------------------------------
+*/
+
+class SaslPlainTest extends \PHPUnit\Framework\TestCase
+{
+    // {{{ consts
+    // }}}
+    // {{{ members
+    // }}}
+    // {{{ functions
+    // {{{ public function testHandShake()
+
+    /**
+     * testHandShake
+     *
+     * @access public
+     * @return void
+     */
+    public function testHandShake()
+    {
+        // Create a stub for the SomeClass class.
+        $socket = $this->createMock(\Kafka\Socket::class);
+
+        $handShakeData = \hex2bin('00000011000000000004000d534352414d2d5348412d3531320005504c41494e0006475353415049000d534352414d2d5348412d323536');
+        // Configure the stub.
+        $socket->method('readBlocking')
+            ->will($this->onConsecutiveCalls(\hex2bin('00000037'), $handShakeData, \hex2bin('00000000')));
+        $socket->expects($this->exactly(2))
+            ->method('writeBlocking')
+            ->withConsecutive(
+                [$this->equalTo(\hex2bin('0000001a001100000000001100096b61666b612d7068700005504c41494e'))],
+                [$this->equalTo(\hex2bin('0000000d006e6d72656400313233343536'))]
+            );
+
+        $provider = new \Kafka\Sasl\Plain('nmred', '123456');
+        $provider->authenticate($socket);
+    }
+
+    // }}}
+    // {{{ public function testHandShakeNotSupport()
+
+    /**
+     * testHandShake
+     *
+     * @expectedException \Kafka\Exception
+     * @expectedExceptionMessage The broker does not support the requested SASL mechanism.
+     * @access public
+     * @return void
+     */
+    public function testHandShakeNotSupport()
+    {
+        // Create a stub for the SomeClass class.
+        $socket = $this->createMock(\Kafka\Socket::class);
+
+        $handShakeData = \hex2bin('00000011002100000004000d534352414d2d5348412d3531320005504c41494e0006475353415049000d534352414d2d5348412d323536');
+        // Configure the stub.
+        $socket->method('readBlocking')
+            ->will($this->onConsecutiveCalls(\hex2bin('00000037'), $handShakeData));
+        $socket->expects($this->exactly(1))
+            ->method('writeBlocking')
+            ->withConsecutive(
+                [$this->equalTo(\hex2bin('0000001a001100000000001100096b61666b612d7068700005504c41494e'))]
+            );
+
+        $provider = new \Kafka\Sasl\Plain('nmred', '123456');
+        $provider->authenticate($socket);
+    }
+
+    // }}}
+    // {{{ public function testGetMechanismName()
+
+    /**
+     * testGetMechanismName
+     *
+     * @access public
+     * @return void
+     */
+    public function testGetMechanismName()
+    {
+        $provider = new \Kafka\Sasl\Plain('nmred', '123456');
+        $this->assertSame('PLAIN', $provider->getMechanismName());
+    }
+
+    // }}}
+    // }}}
+}

{'commit': "diff --git a/example/SaslSocket.php b/example/SaslSocket.php\nindex 4719078..65adb36 100644\n--- a/example/SaslSocket.php\n+++ b/example/SaslSocket.php\n@@ -4,8 +4,8 @@ require '../vendor/autoload.php';\n use \\Kafka\\Sasl\\Scram;\n \n \\Kafka\\Protocol::init('1.0.0');\n-//$provider = new \\Kafka\\Sasl\\Plain('nmred', '123456');\n-$provider = new \\Kafka\\Sasl\\Gssapi('/etc/security/keytabs/kafkaclient.keytab', 'kafka/node1@NMREDKAFKA.COM');\n+$provider = new \\Kafka\\Sasl\\Plain('nmred', '123456');\n+//$provider = new \\Kafka\\Sasl\\Gssapi('/etc/security/keytabs/kafkaclient.keytab', 'kafka/node1@NMREDKAFKA.COM');\n //$provider = new Scram('alice', 'alice-secret', Scram::SCRAM_SHA_256);\n \n $socket = new \\Kafka\\SocketSync('127.0.0.1', '9092');\ndiff --git a/src/Config.php b/src/Config.php\nindex d5e6386..1c696d9 100644\n--- a/src/Config.php\n+++ b/src/Config.php\n@@ -229,9 +229,9 @@ abstract class Config\n     // }}}\n     // {{{ public function setSslLocalCert()\n \n-    public function setSslLocalCert($localCert)\n+    public function setSslLocalCert(string $localCert)\n     {\n-        if (! is_string($localCert) || ! file_exists($localCert)) {\n+        if (! file_exists($localCert) || ! is_file($localCert)) {\n             throw new \\Kafka\\Exception\\Config('Set ssl local cert file is invalid');\n         }\n         static::$options['sslLocalCert'] = $localCert;\n@@ -240,9 +240,9 @@ abstract class Config\n     // }}}\n     // {{{ public function setSslLocalPk()\n \n-    public function setSslLocalPk($localPk)\n+    public function setSslLocalPk(string $localPk)\n     {\n-        if (! is_string($localPk) || ! file_exists($localPk)) {\n+        if (! file_exists($localPk) || ! is_file($localPk)) {\n             throw new \\Kafka\\Exception\\Config('Set ssl local private key file is invalid');\n         }\n         static::$options['sslLocalPk'] = $localPk;\n@@ -251,21 +251,21 @@ abstract class Config\n     // }}}\n     // {{{ public function setSslCafile()\n \n-    public function setSslCafile($cafile)\n+    public function setSslCafile(string $cafile)\n     {\n-        if (! is_string($cafile) || ! file_exists($cafile)) {\n+        if (! file_exists($cafile) || ! is_file($cafile)) {\n             throw new \\Kafka\\Exception\\Config('Set ssl ca file is invalid');\n         }\n         static::$options['sslCafile'] = $cafile;\n     }\n \n     // }}}\n-    // {{{ public function setKeytab()\n+    // {{{ public function setSaslKeytab()\n \n-    public function setKeytab($keytab)\n+    public function setSaslKeytab(string $keytab)\n     {\n-        if (! is_string($keytab) || ! file_exists($keytab)) {\n-            throw new \\Kafka\\Exception\\Config('Set ssl ca file is invalid');\n+        if (! file_exists($keytab) || ! is_file($keytab)) {\n+            throw new \\Kafka\\Exception\\Config('Set sasl gssapi keytab file is invalid');\n         }\n         static::$options['saslKeytab'] = $keytab;\n     }\ndiff --git a/src/Sasl/Mechanism.php b/src/Sasl/Mechanism.php\nindex df6d266..c985e55 100644\n--- a/src/Sasl/Mechanism.php\n+++ b/src/Sasl/Mechanism.php\n@@ -49,13 +49,11 @@ abstract class Mechanism\n     {\n         $requestData = Protocol::encode(\\Kafka\\Protocol::SASL_HAND_SHAKE_REQUEST, $mechanism);\n         $socket->writeBlocking($requestData);\n-        $dataLen       = ProtocolTool::unpack(\\Kafka\\Protocol\\Protocol::BIT_B32, $socket->readBlocking(4));\n+        $dataLen = ProtocolTool::unpack(\\Kafka\\Protocol\\Protocol::BIT_B32, $socket->readBlocking(4));\n+        \n         $data          = $socket->readBlocking($dataLen);\n         $correlationId = ProtocolTool::unpack(\\Kafka\\Protocol\\Protocol::BIT_B32, substr($data, 0, 4));\n         $result        = Protocol::decode(\\Kafka\\Protocol::SASL_HAND_SHAKE_REQUEST, substr($data, 4));\n-        if (! is_array($result) || ! isset($result['errorCode'])) {\n-            throw new Exception('Sasl request hand shake response error.');\n-        }\n \n         if ($result['errorCode'] !== Protocol::NO_ERROR) {\n             throw new Exception(Protocol::getError($result['errorCode']));\ndiff --git a/tests/Base/ProducerConfigTest.php b/tests/Base/ProducerConfigTest.php\nindex b9114c4..cbc3220 100644\n--- a/tests/Base/ProducerConfigTest.php\n+++ b/tests/Base/ProducerConfigTest.php\n@@ -211,6 +211,246 @@ class ProducerConfigTest extends \\PHPUnit\\Framework\\TestCase\n         $config->setIsAsyn('-2');\n     }\n \n+    // }}}\n+    // {{{ public function testSetSslLocalCert()\n+\n+    /**\n+     * testSetSslLocalCert\n+     *\n+     * @expectedException \\Kafka\\Exception\\Config\n+     * @expectedExceptionMessage Set ssl local cert file is invalid\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSslLocalCert()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $config->setSslLocalCert('invalid_path');\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSslLocalCertNotFile()\n+\n+    /**\n+     * testSetSslLocalCert\n+     *\n+     * @expectedException \\Kafka\\Exception\\Config\n+     * @expectedExceptionMessage Set ssl local cert file is invalid\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSslLocalCertNotFile()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $config->setSslLocalCert('/tmp');\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSslLocalCertValid()\n+\n+    /**\n+     * testSetSslLocalCertValid\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSslLocalCertValid()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $path   = '/etc/passwd';\n+        $config->setSslLocalCert($path);\n+        $this->assertEquals($path, $config->getSslLocalCert());\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSslLocalPk()\n+\n+    /**\n+     * testSetSslLocalPk\n+     *\n+     * @expectedException \\Kafka\\Exception\\Config\n+     * @expectedExceptionMessage Set ssl local private key file is invalid\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSslLocalPk()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $config->setSslLocalPk('invalid_path');\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSslLocalPkValid()\n+\n+    /**\n+     * testSetSslLocalPkValid\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSslLocalPkValid()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $path   = '/etc/passwd';\n+        $config->setSslLocalPk($path);\n+        $this->assertEquals($path, $config->getSslLocalPk());\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSslCafile()\n+\n+    /**\n+     * testSetSslCafile\n+     *\n+     * @expectedException \\Kafka\\Exception\\Config\n+     * @expectedExceptionMessage Set ssl ca file is invalid\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSslCafile()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $config->setSslCafile('invalid_path');\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSslCafileValid()\n+\n+    /**\n+     * testSetSslCafile\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSslCafileValid()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $path   = '/etc/passwd';\n+        $config->setSslCafile($path);\n+        $this->assertEquals($path, $config->getSslCafile());\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSaslKeytab()\n+\n+    /**\n+     * testSetSaslKeytab\n+     *\n+     * @expectedException \\Kafka\\Exception\\Config\n+     * @expectedExceptionMessage Set sasl gssapi keytab file is invalid\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSaslKeytab()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $config->setSaslKeytab('invalid_path');\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSaslKeytabValid()\n+\n+    /**\n+     * testSetSaslKeytab\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSaslKeytabValid()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $path   = '/etc/passwd';\n+        $config->setSaslKeytab($path);\n+        $this->assertEquals($path, $config->getSaslKeytab());\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSecurityProtocol()\n+\n+    /**\n+     * testSetSecurityProtocol\n+     *\n+     * @expectedException \\Kafka\\Exception\\Config\n+     * @expectedExceptionMessage Invalid security protocol given.\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSecurityProtocol()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $config->setSecurityProtocol('xxxx');\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSecurityProtocolValid()\n+\n+    /**\n+     * testSetSecurityProtocol\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSecurityProtocolValid()\n+    {\n+        $config   = \\Kafka\\ProducerConfig::getInstance();\n+        $protocol = \\Kafka\\Config::SECURITY_PROTOCOL_PLAINTEXT;\n+        $config->setSecurityProtocol($protocol);\n+        $this->assertEquals($protocol, $config->getSecurityProtocol());\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSaslMechanism()\n+\n+    /**\n+     * testSetSaslMechanism\n+     *\n+     * @expectedException \\Kafka\\Exception\\Config\n+     * @expectedExceptionMessage Invalid security sasl mechanism given.\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSaslMechanism()\n+    {\n+        $config = \\Kafka\\ProducerConfig::getInstance();\n+        $config->setSaslMechanism('xxxx');\n+    }\n+\n+    // }}}\n+    // {{{ public function testSetSaslMechanismValid()\n+\n+    /**\n+     * testSetSaslMechanism\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testSetSaslMechanismValid()\n+    {\n+        $config    = \\Kafka\\ProducerConfig::getInstance();\n+        $mechanism = \\Kafka\\Config::SASL_MECHANISMS_GSSAPI;\n+        $config->setSaslMechanism($mechanism);\n+        $this->assertEquals($mechanism, $config->getSaslMechanism());\n+    }\n+\n+    // }}}\n+    // {{{ public function testClear()\n+\n+    /**\n+     * testClear\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testClear()\n+    {\n+        $config    = \\Kafka\\ProducerConfig::getInstance();\n+        $mechanism = \\Kafka\\Config::SASL_MECHANISMS_GSSAPI;\n+        $config->setSaslMechanism($mechanism);\n+        $this->assertEquals($mechanism, $config->getSaslMechanism());\n+        $config->clear();\n+        $this->assertEquals(\\Kafka\\Config::SASL_MECHANISMS_PLAIN, $config->getSaslMechanism());\n+    }\n+\n     // }}}\n     // }}}\n }\ndiff --git a/tests/Base/SaslPlainTest.php b/tests/Base/SaslPlainTest.php\nnew file mode 100644\nindex 0000000..bb5dcbe\n--- /dev/null\n+++ b/tests/Base/SaslPlainTest.php\n@@ -0,0 +1,111 @@\n+<?php\n+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */\n+// +---------------------------------------------------------------------------\n+// | SWAN [ $_SWANBR_SLOGAN_$ ]\n+// +---------------------------------------------------------------------------\n+// | Copyright $_SWANBR_COPYRIGHT_$\n+// +---------------------------------------------------------------------------\n+// | Version  $_SWANBR_VERSION_$\n+// +---------------------------------------------------------------------------\n+// | Licensed ( $_SWANBR_LICENSED_URL_$ )\n+// +---------------------------------------------------------------------------\n+// | $_SWANBR_WEB_DOMAIN_$\n+// +---------------------------------------------------------------------------\n+\n+namespace KafkaTest\\Base;\n+\n+/**\n++------------------------------------------------------------------------------\n+* Kafka protocol since Kafka v0.8\n++------------------------------------------------------------------------------\n+*\n+* @package\n+* @version $_SWANBR_VERSION_$\n+* @copyright Copyleft\n+* @author $_SWANBR_AUTHOR_$\n++------------------------------------------------------------------------------\n+*/\n+\n+class SaslPlainTest extends \\PHPUnit\\Framework\\TestCase\n+{\n+    // {{{ consts\n+    // }}}\n+    // {{{ members\n+    // }}}\n+    // {{{ functions\n+    // {{{ public function testHandShake()\n+\n+    /**\n+     * testHandShake\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testHandShake()\n+    {\n+        // Create a stub for the SomeClass class.\n+        $socket = $this->createMock(\\Kafka\\Socket::class);\n+\n+        $handShakeData = \\hex2bin('00000011000000000004000d534352414d2d5348412d3531320005504c41494e0006475353415049000d534352414d2d5348412d323536');\n+        // Configure the stub.\n+        $socket->method('readBlocking')\n+            ->will($this->onConsecutiveCalls(\\hex2bin('00000037'), $handShakeData, \\hex2bin('00000000')));\n+        $socket->expects($this->exactly(2))\n+            ->method('writeBlocking')\n+            ->withConsecutive(\n+                [$this->equalTo(\\hex2bin('0000001a001100000000001100096b61666b612d7068700005504c41494e'))],\n+                [$this->equalTo(\\hex2bin('0000000d006e6d72656400313233343536'))]\n+            );\n+\n+        $provider = new \\Kafka\\Sasl\\Plain('nmred', '123456');\n+        $provider->authenticate($socket);\n+    }\n+\n+    // }}}\n+    // {{{ public function testHandShakeNotSupport()\n+\n+    /**\n+     * testHandShake\n+     *\n+     * @expectedException \\Kafka\\Exception\n+     * @expectedExceptionMessage The broker does not support the requested SASL mechanism.\n+     * @access public\n+     * @return void\n+     */\n+    public function testHandShakeNotSupport()\n+    {\n+        // Create a stub for the SomeClass class.\n+        $socket = $this->createMock(\\Kafka\\Socket::class);\n+\n+        $handShakeData = \\hex2bin('00000011002100000004000d534352414d2d5348412d3531320005504c41494e0006475353415049000d534352414d2d5348412d323536');\n+        // Configure the stub.\n+        $socket->method('readBlocking')\n+            ->will($this->onConsecutiveCalls(\\hex2bin('00000037'), $handShakeData));\n+        $socket->expects($this->exactly(1))\n+            ->method('writeBlocking')\n+            ->withConsecutive(\n+                [$this->equalTo(\\hex2bin('0000001a001100000000001100096b61666b612d7068700005504c41494e'))]\n+            );\n+\n+        $provider = new \\Kafka\\Sasl\\Plain('nmred', '123456');\n+        $provider->authenticate($socket);\n+    }\n+\n+    // }}}\n+    // {{{ public function testGetMechanismName()\n+\n+    /**\n+     * testGetMechanismName\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testGetMechanismName()\n+    {\n+        $provider = new \\Kafka\\Sasl\\Plain('nmred', '123456');\n+        $this->assertSame('PLAIN', $provider->getMechanismName());\n+    }\n+\n+    // }}}\n+    // }}}\n+}\n", 'commit_subject': 'add SASL plain mechanism unit tests', 'repo_name': 'weiboad/kafka-php', 'committer': {'name': 'nmred', 'email': 'aa5c311d9f94b68dd77846eeb4fd74fb3d0acbeb@126.com', 'time_sec': '1512737051', 'tz_offset': '0', 'date': {'seconds': '1512737051'}}, 'commit_tree': 'd86a4c1ab7ab99d19760dba8e5250840b270c30e', 'commit_message': 'add SASL plain mechanism unit tests\n', 'language_name': 'PHP', 'license': 'apache-2.0', 'hunks': "@@ -0,0 +1,111 @@\n+<?php\n+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */\n+// +---------------------------------------------------------------------------\n+// | SWAN [ $_SWANBR_SLOGAN_$ ]\n+// +---------------------------------------------------------------------------\n+// | Copyright $_SWANBR_COPYRIGHT_$\n+// +---------------------------------------------------------------------------\n+// | Version  $_SWANBR_VERSION_$\n+// +---------------------------------------------------------------------------\n+// | Licensed ( $_SWANBR_LICENSED_URL_$ )\n+// +---------------------------------------------------------------------------\n+// | $_SWANBR_WEB_DOMAIN_$\n+// +---------------------------------------------------------------------------\n+\n+namespace KafkaTest\\Base;\n+\n+/**\n++------------------------------------------------------------------------------\n+* Kafka protocol since Kafka v0.8\n++------------------------------------------------------------------------------\n+*\n+* @package\n+* @version $_SWANBR_VERSION_$\n+* @copyright Copyleft\n+* @author $_SWANBR_AUTHOR_$\n++------------------------------------------------------------------------------\n+*/\n+\n+class SaslPlainTest extends \\PHPUnit\\Framework\\TestCase\n+{\n+    // {{{ consts\n+    // }}}\n+    // {{{ members\n+    // }}}\n+    // {{{ functions\n+    // {{{ public function testHandShake()\n+\n+    /**\n+     * testHandShake\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testHandShake()\n+    {\n+        // Create a stub for the SomeClass class.\n+        $socket = $this->createMock(\\Kafka\\Socket::class);\n+\n+        $handShakeData = \\hex2bin('00000011000000000004000d534352414d2d5348412d3531320005504c41494e0006475353415049000d534352414d2d5348412d323536');\n+        // Configure the stub.\n+        $socket->method('readBlocking')\n+            ->will($this->onConsecutiveCalls(\\hex2bin('00000037'), $handShakeData, \\hex2bin('00000000')));\n+        $socket->expects($this->exactly(2))\n+            ->method('writeBlocking')\n+            ->withConsecutive(\n+                [$this->equalTo(\\hex2bin('0000001a001100000000001100096b61666b612d7068700005504c41494e'))],\n+                [$this->equalTo(\\hex2bin('0000000d006e6d72656400313233343536'))]\n+            );\n+\n+        $provider = new \\Kafka\\Sasl\\Plain('nmred', '123456');\n+        $provider->authenticate($socket);\n+    }\n+\n+    // }}}\n+    // {{{ public function testHandShakeNotSupport()\n+\n+    /**\n+     * testHandShake\n+     *\n+     * @expectedException \\Kafka\\Exception\n+     * @expectedExceptionMessage The broker does not support the requested SASL mechanism.\n+     * @access public\n+     * @return void\n+     */\n+    public function testHandShakeNotSupport()\n+    {\n+        // Create a stub for the SomeClass class.\n+        $socket = $this->createMock(\\Kafka\\Socket::class);\n+\n+        $handShakeData = \\hex2bin('00000011002100000004000d534352414d2d5348412d3531320005504c41494e0006475353415049000d534352414d2d5348412d323536');\n+        // Configure the stub.\n+        $socket->method('readBlocking')\n+            ->will($this->onConsecutiveCalls(\\hex2bin('00000037'), $handShakeData));\n+        $socket->expects($this->exactly(1))\n+            ->method('writeBlocking')\n+            ->withConsecutive(\n+                [$this->equalTo(\\hex2bin('0000001a001100000000001100096b61666b612d7068700005504c41494e'))]\n+            );\n+\n+        $provider = new \\Kafka\\Sasl\\Plain('nmred', '123456');\n+        $provider->authenticate($socket);\n+    }\n+\n+    // }}}\n+    // {{{ public function testGetMechanismName()\n+\n+    /**\n+     * testGetMechanismName\n+     *\n+     * @access public\n+     * @return void\n+     */\n+    public function testGetMechanismName()\n+    {\n+        $provider = new \\Kafka\\Sasl\\Plain('nmred', '123456');\n+        $this->assertSame('PLAIN', $provider->getMechanismName());\n+    }\n+\n+    // }}}\n+    // }}}\n+}\n", 'addition_count': 111, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/tests/Base/SaslPlainTest.php', 'file_extension': '.php', 'before_file': 'ADDFILE', 'message': 'add SASL plain mechanism unit tests\n', 'author_name': 'nmred', 'lang': 'php'}