Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for connection authentication
- Loading branch information
Showing
13 changed files
with
307 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
namespace Disque\Command; | ||
|
||
use Disque\Command\Response\AuthResponse; | ||
|
||
class Auth extends BaseCommand implements CommandInterface | ||
{ | ||
/** | ||
* Tells the argument types for this command | ||
* | ||
* @var int | ||
*/ | ||
protected $argumentsType = self::ARGUMENTS_TYPE_STRING; | ||
|
||
/** | ||
* Get command | ||
* | ||
* @return string Command | ||
*/ | ||
public function getCommand() | ||
{ | ||
return 'AUTH'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
namespace Disque\Connection; | ||
|
||
class AuthenticationException extends ConnectionException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
namespace Disque\Test\Command; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use Disque\Command\Argument\InvalidCommandArgumentException; | ||
use Disque\Command\CommandInterface; | ||
use Disque\Command\Auth; | ||
use Disque\Command\Response\InvalidResponseException; | ||
|
||
class AuthTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testInstance() | ||
{ | ||
$c = new Auth(); | ||
$this->assertInstanceOf(CommandInterface::class, $c); | ||
} | ||
|
||
public function testGetCommand() | ||
{ | ||
$c = new Auth(); | ||
$result = $c->getCommand(); | ||
$this->assertSame('AUTH', $result); | ||
} | ||
|
||
public function testIsBlocking() | ||
{ | ||
$c = new Auth(); | ||
$result = $c->isBlocking(); | ||
$this->assertFalse($result); | ||
} | ||
|
||
public function testBuildInvalidArgumentsEmpty() | ||
{ | ||
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\Auth: []'); | ||
$c = new Auth(); | ||
$c->setArguments([]); | ||
} | ||
|
||
public function testBuildInvalidArgumentsEmptyTooMany() | ||
{ | ||
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\Auth: ["test","stuff"]'); | ||
$c = new Auth(); | ||
$c->setArguments(['test', 'stuff']); | ||
} | ||
|
||
public function testBuildInvalidArgumentsEmptyNonNumeric() | ||
{ | ||
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\Auth: {"test":"stuff"}'); | ||
$c = new Auth(); | ||
$c->setArguments(['test' => 'stuff']); | ||
} | ||
|
||
public function testBuildInvalidArgumentsNumericNon0() | ||
{ | ||
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\Auth: {"1":"stuff"}'); | ||
$c = new Auth(); | ||
$c->setArguments([1 => 'stuff']); | ||
} | ||
|
||
public function testBuildInvalidArgumentsNonString() | ||
{ | ||
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\Auth: [false]'); | ||
$c = new Auth(); | ||
$c->setArguments([false]); | ||
} | ||
|
||
public function testBuild() | ||
{ | ||
$c = new Auth(); | ||
$c->setArguments(['test']); | ||
$result = $c->getArguments(); | ||
$this->assertSame(['test'], $result); | ||
} | ||
|
||
public function testParseInvalidNonString() | ||
{ | ||
$this->setExpectedException(InvalidResponseException::class, 'Invalid command response. Command Disque\\Command\\Auth got: 10'); | ||
$c = new Auth(); | ||
$c->parse(10); | ||
} | ||
|
||
public function testParseInvalidNonStringBoolTrue() | ||
{ | ||
$this->setExpectedException(InvalidResponseException::class, 'Invalid command response. Command Disque\\Command\\Auth got: true'); | ||
$c = new Auth(); | ||
$c->parse(true); | ||
} | ||
|
||
public function testParse() | ||
{ | ||
$c = new Auth(); | ||
$result = $c->parse('OK'); | ||
$this->assertSame('OK', $result); | ||
} | ||
} |
Oops, something went wrong.