PackageTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Config\Test\Unit\Composer;
  7. use \Magento\Framework\Config\Composer\Package;
  8. class PackageTest extends \PHPUnit\Framework\TestCase
  9. {
  10. const SAMPLE_DATA =
  11. '{"foo":"1","bar":"2","baz":["3","4"],"nested":{"one":"5","two":"6",
  12. "magento/theme-adminhtml-backend":7, "magento/theme-frontend-luma":8}}';
  13. /**
  14. * @var \StdClass
  15. */
  16. private $sampleJson;
  17. /**
  18. * @var Package
  19. */
  20. private $object;
  21. protected function setUp()
  22. {
  23. $this->sampleJson = json_decode(self::SAMPLE_DATA);
  24. $this->object = new Package($this->sampleJson);
  25. }
  26. public function testGetJson()
  27. {
  28. $this->assertInstanceOf('\StdClass', $this->object->getJson(false));
  29. $this->assertEquals($this->sampleJson, $this->object->getJson(false));
  30. $this->assertSame($this->sampleJson, $this->object->getJson(false));
  31. $this->assertEquals(
  32. json_encode($this->sampleJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n",
  33. $this->object->getJson(true, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
  34. );
  35. }
  36. public function testGet()
  37. {
  38. $this->assertSame('1', $this->object->get('foo'));
  39. $this->assertSame(['3', '4'], $this->object->get('baz'));
  40. $nested = $this->object->get('nested');
  41. $this->assertInstanceOf('\StdClass', $nested);
  42. $this->assertObjectHasAttribute('one', $nested);
  43. $this->assertEquals('5', $nested->one);
  44. $this->assertEquals('5', $this->object->get('nested->one'));
  45. $this->assertObjectHasAttribute('two', $nested);
  46. $this->assertEquals('6', $nested->two);
  47. $this->assertEquals('6', $this->object->get('nested->two'));
  48. $this->assertEquals(
  49. ['magento/theme-adminhtml-backend' => 7, 'magento/theme-frontend-luma' => 8],
  50. (array)$this->object->get('nested', '/^magento\/theme/')
  51. );
  52. }
  53. }