ricbra / php-discogs-api

PHP 5.4 Implementation of the Discogs API
MIT License
152 stars 95 forks source link

GetInventory : per_page not working #59

Closed garrigou closed 3 years ago

garrigou commented 3 years ago

The _perpage parameter doesn't work in the GetInventory function.

public function testGetInventory()
    {
        $client = $this->createClient('get_inventory', $history = new History());
        $response = $client->getInventory([
            'username'      => '360vinyl',
            'per_page'      => 100,
            'sort'          => 'price',
            'sort_order'    => 'asc'
        ]);

        $this->assertArrayHasKey('pagination', $response);
        $this->assertArrayHasKey('listings', $response);
        $this->assertCount(100, $response['listings']);
        $this->assertSame('GET', $history->getLastRequest()->getMethod());
        $this->assertSame('https://api.discogs.com/users/360vinyl/inventory?sort=price&sort_order=asc', $history->getLastRequest()->getUrl());
    }

Phpunit result :

PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

.............F...........

Time: 2.7 seconds, Memory: 10.00MB

There was 1 failure:

1) Discogs\Test\ClientTest::testGetInventory
Failed asserting that actual size 50 matches expected size 100.

/home/clement/test_php_discogs/php-discogs-api/tests/Discogs/Test/ClientTest.php:197
/usr/share/php/PHPUnit/TextUI/Command.php:186
/usr/share/php/PHPUnit/TextUI/Command.php:138

FAILURES!
Tests: 25, Assertions: 113, Failures: 1.

Do you have an idea why it is not working ?

Thanks

Clement

AnssiAhola commented 3 years ago

https://github.com/ricbra/php-discogs-api/blob/846f341d3c7c6e811479823daf981b585fa3cd62/tests/fixtures/get_inventory#L15 This is the response that the testcase gets everytime, it will always have per_page=50 and even though the "items" says 479, the response contains only 50 actual listings

Have you tried calling the function with real data? like getting your own discogs inventory?

garrigou commented 3 years ago

Thanks for your explanation. Everything works fine ! Sorry !

<?php
require('vendor/autoload.php');
$client = Discogs\ClientFactory::factory([]);

$response = $client->getInventory(['username' => '360vinyl', 'per_page' => 13]);
var_dump($response['pagination']);

Output :

array(5) {
  ["page"]=>
  int(1)
  ["pages"]=>
  int(208)
  ["per_page"]=>
  int(13)
  ["items"]=>
  int(2697)
  ["urls"]=>
  array(2) {
    ["last"]=>
    string(69) "https://api.discogs.com/users/360vinyl/inventory?per_page=13&page=208"
    ["next"]=>
    string(67) "https://api.discogs.com/users/360vinyl/inventory?per_page=13&page=2"
  }
}