Skip to content

Commit

Permalink
Merge pull request #102 from ronaldjesse/add-to-array-methods
Browse files Browse the repository at this point in the history
Add toArray() methods to ArrayObject and Endpoint
  • Loading branch information
aaronklaassen authored Aug 14, 2019
2 parents af907f6 + 5362f98 commit 4cc5f5f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/ArrayObject.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,15 @@ public function rateLimitRemaining()
{
return intval($this->headers[self::RATE_LIMIT_REMAINING][0]);
}

/**
* Return array with all available Endpoint resources.
* @return array
*/
public function toArray()
{
return array_map(function(Endpoint $endpoint) {
return $endpoint->toArray();
}, $this->getArrayCopy());
}
}
9 changes: 9 additions & 0 deletions src/Endpoint.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,13 @@ private function addUtmSource(array $parameters)

return $parameters;
}

/**
* Return all parameters.
* @return array
*/
public function toArray()
{
return $this->parameters;
}
}
16 changes: 16 additions & 0 deletions tests/ArrayObjectTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,20 @@ public function testRateLimitRemaining()

$this->assertEquals(10, $arrayObject->rateLimitRemaining());
}

public function testCanMakeArray()
{
$headers = [];
$arrayObject = new Unsplash\ArrayObject([new Unsplash\Endpoint(['test' => 'mock', 'test_1' => 'mock_1']), new Unsplash\Endpoint(['test_2' => 'mock_2', 'test_3' => 'mock_3'])], $headers);

$this->assertEquals($arrayObject->toArray(), [
[
'test' => 'mock',
'test_1' => 'mock_1',
], [
'test_2' => 'mock_2',
'test_3' => 'mock_3'
]
]);
}
}
9 changes: 8 additions & 1 deletion tests/EndpointTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Crew\Unsplash\Tests;

use Crew\Unsplash;
use \VCR\VCR;
use VCR\VCR;

/**
* Class EndpointTest
Expand Down Expand Up @@ -75,4 +75,11 @@ public function testRateLimitResponseExists()

$this->assertEquals('4984', $headers['X-RateLimit-Remaining'][0]);
}

public function testCanMakeArray()
{
$endpoint = new Unsplash\Endpoint(['test' => 'mock', 'test_1' => 'mock_1']);

$this->assertEquals($endpoint->toArray(), ['test' => 'mock', 'test_1' => 'mock_1']);
}
}

0 comments on commit 4cc5f5f

Please sign in to comment.