UpdateOperationTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Tests\Unit\Service\Rest\Operation;
  3. use App\Service\Rest\Operation\UpdateOperation;
  4. use PHPUnit\Framework\TestCase;
  5. class UpdateOperationTest extends TestCase
  6. {
  7. /**
  8. * @see UpdateOperation::__construct()
  9. * @see UpdateOperation::getMethod()
  10. * @see UpdateOperation::getEntityName()
  11. * @see UpdateOperation::getPath()
  12. * @see UpdateOperation::getInitialData()
  13. * @see UpdateOperation::getData()
  14. * @see UpdateOperation::__toString()
  15. */
  16. public function testGetters(): void
  17. {
  18. $operation = new UpdateOperation(
  19. 'Update a dinosaur',
  20. 'dinosaur',
  21. 1,
  22. ['weight' => 1800],
  23. ['weight' => 1600]
  24. );
  25. $this->assertEquals('PUT', $operation->getMethod());
  26. $this->assertEquals('dinosaur', $operation->getEntityName());
  27. $this->assertEquals('dinosaur/1', $operation->getPath());
  28. $this->assertEquals(['weight' => 1600], $operation->getInitialData());
  29. $this->assertEquals(['weight' => 1800], $operation->getData());
  30. $this->assertEquals('PUT dinosaur/1', (string) $operation);
  31. }
  32. /**
  33. * @see UpdateOperation::getChangeLog()
  34. */
  35. public function testGetChangeLog(): void
  36. {
  37. $operation = new UpdateOperation(
  38. 'Update a dinosaur',
  39. 'dinosaur',
  40. 1,
  41. ['weight' => 1800, 'attrs' => ['vision' => 'movement-based', 'teeth' => '99', 'adn' => ['1' => 'b'], 'color' => 'green']],
  42. ['weight' => 1600, 'attrs' => ['vision' => 'movement-based', 'teeth' => '100', 'adn' => ['1' => 'a']]]
  43. );
  44. $this->assertEquals(
  45. [
  46. '[PUT dinosaur/1]',
  47. 'weight : `1600` => `1800`',
  48. 'attrs.teeth : `100` => `99`',
  49. 'attrs.adn.1 : `a` => `b`',
  50. 'attrs.color : (new) => `green`',
  51. ],
  52. $operation->getChangeLog()
  53. );
  54. }
  55. }