Skip to content

Commit

Permalink
Merge pull request #86 from GetStream/feature/replace-abandoned-packages
Browse files Browse the repository at this point in the history
upgrade dependencies, drop php5.x support, update tests
  • Loading branch information
tbarbugli committed Nov 25, 2019
2 parents 979325b + 00cf81c commit fdb33a4
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 67 deletions.
14 changes: 4 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@ sudo: false

matrix:
include:
- php: 5.6
env: TEST_SUITE="Unit Test Suite"
- php: 7.0
- php: 7.2
env: TEST_SUITE="Unit Test Suite"
- php: 7.1
- php: 7.3
env: TEST_SUITE="Unit Test Suite"
- php: 7.2
env: TEST_SUITE="Unit Test Suite" COLLECT_COVERAGE=true
- php: 7.2
- php: 7.3
env: TEST_SUITE="Integration Test Suite"
allow_failures:
- php: 7.2
- php: 7.3
env: TEST_SUITE="Integration Test Suite"

before_script:
- travis_retry composer install --no-interaction
script:
- vendor/bin/phpunit --testsuite "$TEST_SUITE"
after_script:
- if [[ "$COLLECT_COVERAGE" == "true" ]]; then vendor/bin/coveralls; fi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Composer will install our latest version automatically.

#### PHP compatibility

Current releases require PHP `5.5` or higher, and depends on Guzzle version 6.
Current releases require PHP `7.2` or higher, and depends on Guzzle version 6.

If you need to use the client with PHP 5.4 or earlier versions of Guzzle, you can grab an earlier version of this package:

Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
}
],
"require": {
"php": ">=5.5",
"guzzlehttp/guzzle": "^6.0",
"firebase/php-jwt": "~3.0|~4.0|~5.0"
"php": ">=7.2",
"guzzlehttp/guzzle": "^6.3.3",
"firebase/php-jwt": "^v5.0.0"
},
"require-dev": {
"phpunit/phpunit": "^4.3",
"satooshi/php-coveralls": "^1.0",
"ramsey/uuid": "^3.7"
"phpunit/phpunit": "^8.2.1",
"ramsey/uuid": "^3.8"
},
"autoload": {
"psr-0": {
Expand Down
29 changes: 13 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@
processIsolation="false"
bootstrap="vendor/autoload.php"
>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">lib/</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="Unit Test Suite">
<directory>tests/unit</directory>
</testsuite>
<testsuite name="Integration Test Suite">
<directory>tests/integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">lib/</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="Unit Test Suite">
<directory>tests/unit</directory>
</testsuite>
<testsuite name="Integration Test Suite">
<directory>tests/integration</directory>
</testsuite>
</testsuites>
</phpunit>
20 changes: 9 additions & 11 deletions tests/integration/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CollectionTest extends TestCase
*/
protected $collections;

protected function setUp()
protected function setUp():void
{
$this->client = new Client(
getenv('STREAM_API_KEY'),
Expand All @@ -78,9 +78,10 @@ public function cleanUp(){

public function testUpsert()
{
$collection = $this->collections->upsert('animals', ['id' => '1', 'name' => 'bear', 'color' => 'blue']);
$collection = $this->collections->upsert('items', ['id' => '42', 'name' => 'towel']);

$collection = $this->collections->upsert('animals', [['id' => '1', 'name' => 'bear', 'color' => 'blue']]);
$this->assertSame($collection['data']['animals'][0]['name'], 'bear');
$collection = $this->collections->upsert('items', [['id' => '42', 'name' => 'towel']]);
$this->assertSame($collection['data']['items'][0]['name'], 'towel');
}

public function testAddCollection()
Expand All @@ -105,12 +106,10 @@ public function testAddCollectionWithId()
$this->assertSame($response['data']['name'], 'Cheese Burger');
}

/**
* @expectedException \GetStream\Stream\StreamFeedException
*/
public function testAddCollectionAgain()
{
// Adding again should throw error
$this->expectException(\GetStream\Stream\StreamFeedException::class);
$response = $this->collections->add(
"food", ["name" => "Cheese Burger", "rating" => "4 stars"], "cheese-burger"
);
Expand All @@ -119,13 +118,12 @@ public function testAddCollectionAgain()
public function testDeleteCollection()
{
$response = $this->collections->delete("food","cheese-burger");
$this->assertTrue(array_key_exists("duration", $response));
}

/**
* @expectedException \GetStream\Stream\StreamFeedException
*/
public function testDeleteCollectionAgain()
{
$this->expectException(\GetStream\Stream\StreamFeedException::class);
$response = $this->collections->delete("food","cheese-burger");
}

Expand Down Expand Up @@ -174,7 +172,7 @@ public function testDeleteManyCollection()
"food", ["name" => "Cheese Burger", "rating" => "4 stars"], "cheese-burger-2"
);
$response = $this->collections->deleteMany("food",["cheese-burger-1", "cheese-burger-2"]);

$this->assertTrue(array_key_exists("duration", $response));
}

}
26 changes: 18 additions & 8 deletions tests/integration/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FeedTest extends TestCase
*/
protected $flat3;

protected function setUp()
protected function setUp():void
{
$this->client = new Client(
getenv('STREAM_API_KEY'),
Expand Down Expand Up @@ -72,6 +72,9 @@ public function testRedirectUrl()
];
$events = [$impression, $engagement];
$finalUrl = $this->client->createRedirectUrl($targetUrl, $events);
$this->assertTrue(strpos($finalUrl, "google.com") > 0);
$this->assertTrue(strpos($finalUrl, "feed_id") > 0);
$this->assertTrue(strpos($finalUrl, "flat%3Atommaso") > 0);
}

public function testUpdateActivity()
Expand All @@ -86,9 +89,12 @@ public function testUpdateActivity()
'popularity' => 100
];

$this->client->updateActivity($activity);
$response = $this->client->updateActivity($activity);
$activity['popularity'] = 10;
$this->client->updateActivity($activity);
$response = $this->client->getActivities(null, [[$activity['foreign_id'], $now]]);
$check = $response['results'][0];
$this->assertSame($activity['popularity'], $check['popularity']);
}

public function testBatchPartialUpdateActivity()
Expand Down Expand Up @@ -524,8 +530,13 @@ public function testGet()

public function testVerifyOff()
{
$activities_before = $this->user1->getActivities(0, 2);
$this->user1->setGuzzleDefaultOption('verify', true);
$activities = $this->user1->getActivities(0, 2);
$activities_after = $this->user1->getActivities(0, 2);
$this->assertSame(
$activities_before['results'][0]['id'],
$activities_after['results'][0]['id'],
);
}

public function testMarkRead()
Expand Down Expand Up @@ -781,7 +792,8 @@ public function testUpdateActivitiesToReplaceTargets()

public function testUpdateActivitiesWithZeroActivitiesShouldNotFail()
{
$this->client->updateActivities([]);
$response = $this->client->updateActivities([]);
$this->assertNull($response);
}

public function testEnrichment(){
Expand All @@ -796,7 +808,7 @@ public function testEnrichment(){
$feed->addActivity($activity);
$response = $feed->getActivities(0, 3, [], $enrich=true);
$this->assertSame($response["results"][0]["actor"], $user);
$bear = ["id" => "1", "type" => "bear", "color" => "blue"];
$bear = [["id" => "1", "type" => "bear", "color" => "blue"]];
$respone = $this->client->collections()->upsert("animals", $bear);
unset($bear['duration']);
$activity = [
Expand All @@ -806,9 +818,7 @@ public function testEnrichment(){
];
$feed->addActivity($activity);
$response = $feed->getActivities(0, 1, [], $enrich=true);
$this->assertSame($response["results"][0]["object"]['id'], $bear['id']);
unset($bear['id']);
$this->assertEquals($response["results"][0]["object"]['data'], $bear, $canonicalize=true);
$this->assertSame($response["results"][0]["object"]['id'], $bear[0]['id']);
}

public function testGetActivities(){
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/ReactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ReactionTest extends TestCase
*/
protected $reactions;

protected function setUp()
protected function setUp():void
{
$this->client = new Client(
getenv('STREAM_API_KEY'),
Expand Down Expand Up @@ -139,10 +139,8 @@ public function testGetReaction(){
$this->assertSame($created_reaction['created_at'], $retrieved_reaction['created_at']);
}

/**
* @expectedException \GetStream\Stream\StreamFeedException
*/
public function testDeleteReaction(){
$this->expectException(\GetStream\Stream\StreamFeedException::class);
$created_reaction = $this->reactions->add('like', $this->activity_id, 'bob');
$retrieved_reaction = $this->reactions->get($created_reaction['id']);
$this->reactions->delete($created_reaction['id']);
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UserTest extends TestCase
*/
protected $users;

protected function setUp()
protected function setUp():void
{
$this->client = new Client(
getenv('STREAM_API_KEY'),
Expand Down Expand Up @@ -110,10 +110,8 @@ public function testGetUser(){
$this->assertSame($created_user['data'], array());
}

/**
* @expectedException \GetStream\Stream\StreamFeedException
*/
public function testDeleteUser(){
$this->expectException(\GetStream\Stream\StreamFeedException::class);
$uuid = Uuid::uuid4()->toString();
$created_user = $this->users->add($uuid);
$retrieved_user = $this->users->get($created_user['id']);
Expand Down
11 changes: 4 additions & 7 deletions tests/unit/BaseFeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,25 @@ public function testClientFeedAddActivity()
$this->assertSame('feed/feed/1/', $response['uri']);
}

/**
* @expectedException \GetStream\Stream\StreamFeedException
*/
public function testValidateSlug()
{
$this->expectException(\GetStream\Stream\StreamFeedException::class);
$client = $this->createClientMock();
new BaseFeedStub($client, 'feed-ko', '1', 'api', 'token');
}

/**
* @expectedException \GetStream\Stream\StreamFeedException
*/
public function testValidateUserId()
{
$this->expectException(\GetStream\Stream\StreamFeedException::class);
$client = $this->createClientMock();
new BaseFeedStub($client, 'feed_ko', 'ko:1', 'api', 'token');
}

public function testDashIsOkUserId()
{
$client = $this->createClientMock();
new BaseFeedStub($client, 'feed_ko', 'ko-1', 'api', 'token');
$feed = new BaseFeedStub($client, 'feed_ko', 'ko-1', 'api', 'token');
$this->assertSame($feed->getUserId(), 'ko-1');
}

public function testGetToken()
Expand Down
1 change: 1 addition & 0 deletions tests/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testClientFeed()
{
$client = new Client('key', 'secret', $location='qa');
$feed1 = $client->feed('flat', '1');
$this->assertSame($feed1->getId(), 'flat:1');
}

public function testCreateReference()
Expand Down

0 comments on commit fdb33a4

Please sign in to comment.