UpdateOperationTest.php 1.5 KB

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