Skip to content

Commit

Permalink
Added additional test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvdvleuten committed Dec 2, 2016
1 parent 8e6ff67 commit f95c842
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 106 deletions.
11 changes: 3 additions & 8 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,14 @@ public function authenticate($username, $password = null)
/**
* {@inheritdoc}
*/
public function connectAndAuthenticate($username = null, $password = null)
public function connectAndAuthenticate($username, $password = null)
{
$response = $this->connect();

if (!in_array($response->getStatusCode(), [Response::$codes['PostingAllowed'], Response::$code['PostingProhibited']])) {
if (!in_array($response->getStatusCode(), [Response::$codes['PostingAllowed'], Response::$codes['PostingProhibited']])) {
throw new RuntimeException(sprintf('Unsuccessful response received: %s', (string) $response));
}

if ($username === null) {
return $response;
}

return $this->authenticate($username, $password);
}

Expand Down Expand Up @@ -155,8 +151,7 @@ public function overviewFormat()
*/
public function post($groups, $subject, $body, $from, $headers = null)
{
$command = $this->sendCommand(new Command\PostCommand());
$response = $command->getResponse();
$response = $this->sendCommand(new Command\PostCommand());

if ($response->getStatusCode() === Response::$codes['SendArticle']) {
$response = $this->postArticle($groups, $subject, $body, $from, $headers);
Expand Down
8 changes: 4 additions & 4 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function disconnect();
public function authenticate($username, $password = null);

/**
* Connect and optionally authenticate with the NNTP server if
* a username and/or password are given.
* Connect and optionally authenticate with the server if
* a username and optional password are given.
*
* @param string|null $username
* @param string $username
* @param string|null $password
*
* @return ResponseInterface
*/
public function connectAndAuthenticate($username = null, $password = null);
public function connectAndAuthenticate($username, $password = null);

/**
* Send the AUTHINFO command.
Expand Down
2 changes: 1 addition & 1 deletion src/Command/BodyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BodyCommand extends Command implements CommandInterface
/**
* Constructor.
*
* @param string $article the number or msg-id of the article
* @param string $article
*/
public function __construct($article)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function sendCommand(CommandInterface $command)
$commandString = $command();

// NNTP/RFC977 only allows command up to 512 (-2 \r\n) chars.
if (!strlen($commandString) > 510) {
if (strlen($commandString) > 510) {
throw new InvalidArgumentException('Failed to write to socket: command exceeded 510 characters');
}

Expand Down

0 comments on commit f95c842

Please sign in to comment.