Skip to content

Commit

Permalink
wip: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-san committed Jul 11, 2017
1 parent aa6956f commit 712c831
Show file tree
Hide file tree
Showing 23 changed files with 748 additions and 20 deletions.
16 changes: 0 additions & 16 deletions src/API/REST/DTO/UserIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ private function __construct($id, $screenName)
$this->screenName = $screenName;
}

/**
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* @return string
*/
public function getScreenName()
{
return $this->screenName;
}

/**
* @param int $id
*
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/API/Exception/TwitterExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Twitter\Test\API\Exception;

use Twitter\API\Exception\TwitterException;

class TwitterExceptionTest extends \PHPUnit_Framework_TestCase
{
/**
* Init
*/
public function setUp()
{
}

/**
* Close
*/
public function tearDown()
{
\Mockery::close();
}

/**
* @test
*/
public function itShouldCreateAnException()
{
$exception = new TwitterException('message');

$this->assertEquals('message', $exception->getMessage());
}
}
44 changes: 44 additions & 0 deletions tests/unit/API/Exception/TwitterRateLimitExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Twitter\Test\API\Exception;

use Twitter\API\Exception\TwitterException;
use Twitter\API\Exception\TwitterRateLimitException;
use Twitter\API\REST\DTO\Coordinates;
use Twitter\API\REST\Response\LimitedApiRate;
use Twitter\API\REST\Response\UnlimitedApiRate;

class TwitterRateLimitExceptionTest extends \PHPUnit_Framework_TestCase
{
/**
* Init
*/
public function setUp()
{
}

/**
* Close
*/
public function tearDown()
{
\Mockery::close();
}

/**
* @test
*/
public function itShouldCreateAnException()
{
$rate = new LimitedApiRate(5, 0, time());
$exception = TwitterRateLimitException::create('category', $rate);

$this->assertEquals(
'You have reached rate limit. You cannot make an API call yet.',
$exception->getMessage()
);

$this->assertEquals('category', $exception->getCategory());
$this->assertEquals($rate->nextWindow(), $exception->nextWindow());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Twitter\Test\API\REST;
namespace Twitter\Test\API\REST\Client;

use Mockery\Mock;
use Psr\Log\LoggerInterface;
Expand All @@ -23,7 +23,7 @@
use Twitter\API\REST\TwitterApiGateway;
use Twitter\API\REST\TwitterClient;

class RestApiTest extends \PHPUnit_Framework_TestCase
class TwitterClientTest extends \PHPUnit_Framework_TestCase
{
/** @var int */
private $from;
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/API/REST/DTO/CoordinatesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Twitter\Test\API\REST\DTO;

use Twitter\API\REST\DTO\Coordinates;

class CoordinatesTest extends \PHPUnit_Framework_TestCase
{
/**
* Init
*/
public function setUp()
{
}

/**
* Close
*/
public function tearDown()
{
\Mockery::close();
}

/**
* @test
*/
public function itShouldSerialize()
{
$coordinates = new Coordinates(54, 42);

$this->assertEquals(['lat' => 54, 'long' => 42], $coordinates->toArray());
}
}
43 changes: 43 additions & 0 deletions tests/unit/API/REST/DTO/DeleteDirectMessageParametersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Twitter\Test\API\REST\DTO;

use Twitter\API\REST\DTO\DeleteDirectMessageParameters;

class DeleteDirectMessageParametersTest extends \PHPUnit_Framework_TestCase
{
/**
* Init
*/
public function setUp()
{
}

/**
* Close
*/
public function tearDown()
{
\Mockery::close();
}

/**
* @test
*/
public function itShouldSerializeWithTrueValue()
{
$parameters = new DeleteDirectMessageParameters(33, true);

$this->assertEquals(['id' => 33, 'include_entities' => 'true'], $parameters->toArray());
}

/**
* @test
*/
public function itShouldSerializeWithFalseValue()
{
$parameters = new DeleteDirectMessageParameters(33, false);

$this->assertEquals(['id' => 33, 'include_entities' => 'false'], $parameters->toArray());
}
}
43 changes: 43 additions & 0 deletions tests/unit/API/REST/DTO/DeleteTweetParametersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Twitter\Test\API\REST\DTO;

use Twitter\API\REST\DTO\DeleteTweetParameters;

class DeleteTweetParametersTest extends \PHPUnit_Framework_TestCase
{
/**
* Init
*/
public function setUp()
{
}

/**
* Close
*/
public function tearDown()
{
\Mockery::close();
}

/**
* @test
*/
public function itShouldSerializeWithTrueValue()
{
$parameters = new DeleteTweetParameters(33, true);

$this->assertEquals(['id' => 33, 'trim_user' => 'true'], $parameters->toArray());
}

/**
* @test
*/
public function itShouldSerializeWithFalseValue()
{
$parameters = new DeleteTweetParameters(33, false);

$this->assertEquals(['id' => 33, 'trim_user' => 'false'], $parameters->toArray());
}
}
50 changes: 50 additions & 0 deletions tests/unit/API/REST/DTO/DirectMessageParametersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Twitter\Test\API\REST\DTO;

use Twitter\API\REST\DTO\DirectMessageParameters;
use Twitter\API\REST\DTO\UserIdentifier;

class DirectMessageParametersTest extends \PHPUnit_Framework_TestCase
{
/**
* Init
*/
public function setUp()
{
}

/**
* Close
*/
public function tearDown()
{
\Mockery::close();
}

/**
* @test
*/
public function itShouldSerializeWithIdIdentifier()
{
$parameters = new DirectMessageParameters(
UserIdentifier::fromId(33),
'message'
);

$this->assertEquals(['user_id' => 33, 'text' => 'message'], $parameters->toArray());
}

/**
* @test
*/
public function itShouldSerializeWithNameIdentifier()
{
$parameters = new DirectMessageParameters(
UserIdentifier::fromScreenName('username'),
'message'
);

$this->assertEquals(['screen_name' => 'username', 'text' => 'message'], $parameters->toArray());
}
}
50 changes: 50 additions & 0 deletions tests/unit/API/REST/DTO/FollowParametersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Twitter\Test\API\REST\DTO;

use Twitter\API\REST\DTO\FollowParameters;
use Twitter\API\REST\DTO\UserIdentifier;

class FollowParametersTest extends \PHPUnit_Framework_TestCase
{
/**
* Init
*/
public function setUp()
{
}

/**
* Close
*/
public function tearDown()
{
\Mockery::close();
}

/**
* @test
*/
public function itShouldSerializeWithIdIdentifierAndTrueValue()
{
$parameters = new FollowParameters(
UserIdentifier::fromId(33),
true
);

$this->assertEquals(['user_id' => 33, 'follow' => 'true'], $parameters->toArray());
}

/**
* @test
*/
public function itShouldSerializeWithNameIdentifierAndFalseValue()
{
$parameters = new FollowParameters(
UserIdentifier::fromScreenName('username'),
false
);

$this->assertEquals(['screen_name' => 'username', 'follow' => 'false'], $parameters->toArray());
}
}

0 comments on commit 712c831

Please sign in to comment.