Site du proximo, utilisé pour gérer le stock.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApiPetTest.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. use OpenFoodFacts\FilesystemTrait;
  3. use PHPUnit\Framework\TestCase;
  4. use OpenFoodFacts\Api;
  5. use OpenFoodFacts\Collection;
  6. use OpenFoodFacts\Document\PetDocument;
  7. use OpenFoodFacts\Document;
  8. use OpenFoodFacts\Exception\{
  9. ProductNotFoundException,
  10. BadRequestException
  11. };
  12. use Monolog\Logger;
  13. use Monolog\Handler\StreamHandler;
  14. class ApiPetTest extends TestCase
  15. {
  16. use FilesystemTrait;
  17. private $api;
  18. protected function setUp()
  19. {
  20. $log = new Logger('name');
  21. $log->pushHandler(new StreamHandler('log/test.log'));
  22. $this->api = new Api('pet', 'fr', $log);
  23. foreach (glob('tests/images/*') as $file) {
  24. unlink($file);
  25. }
  26. }
  27. public function testApi()
  28. {
  29. $prd = $this->api->getProduct('7613035799738');
  30. $this->assertInstanceOf(PetDocument::class, $prd);
  31. $this->assertInstanceOf(Document::class, $prd);
  32. $this->assertTrue(isset($prd->product_name));
  33. $this->assertNotEmpty($prd->product_name);
  34. }
  35. public function testApiAddImage()
  36. {
  37. try {
  38. $this->api->uploadImage('7613035799738', 'fronts', 'nothing');
  39. $this->assertTrue(false);
  40. } catch (BadRequestException $e) {
  41. $this->assertEquals($e->getMessage(), 'not Available yet');
  42. $this->markTestSkipped(
  43. $e->getMessage()
  44. );
  45. }
  46. }
  47. public function testApiSearch()
  48. {
  49. $collection = $this->api->search('chat', 3, 30);
  50. $this->assertInstanceOf(Collection::class, $collection);
  51. $this->assertEquals($collection->pageCount(), 30);
  52. $this->assertGreaterThan(100, $collection->searchCount());
  53. }
  54. protected function tearDown()
  55. {
  56. $this->recursiveDeleteDirectory('tests/tmp');
  57. }
  58. }