Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PackageTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\Config\Composer\Package;
10 
11 class PackageTest extends \PHPUnit\Framework\TestCase
12 {
13  const SAMPLE_DATA =
14  '{"foo":"1","bar":"2","baz":["3","4"],"nested":{"one":"5","two":"6",
15  "magento/theme-adminhtml-backend":7, "magento/theme-frontend-luma":8}}';
16 
20  private $sampleJson;
21 
25  private $object;
26 
27  protected function setUp()
28  {
29  $this->sampleJson = json_decode(self::SAMPLE_DATA);
30  $this->object = new Package($this->sampleJson);
31  }
32 
33  public function testGetJson()
34  {
35  $this->assertInstanceOf('\StdClass', $this->object->getJson(false));
36  $this->assertEquals($this->sampleJson, $this->object->getJson(false));
37  $this->assertSame($this->sampleJson, $this->object->getJson(false));
38  $this->assertEquals(
39  json_encode($this->sampleJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n",
40  $this->object->getJson(true, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
41  );
42  }
43 
44  public function testGet()
45  {
46  $this->assertSame('1', $this->object->get('foo'));
47  $this->assertSame(['3', '4'], $this->object->get('baz'));
48  $nested = $this->object->get('nested');
49  $this->assertInstanceOf('\StdClass', $nested);
50  $this->assertObjectHasAttribute('one', $nested);
51  $this->assertEquals('5', $nested->one);
52  $this->assertEquals('5', $this->object->get('nested->one'));
53  $this->assertObjectHasAttribute('two', $nested);
54  $this->assertEquals('6', $nested->two);
55  $this->assertEquals('6', $this->object->get('nested->two'));
56  $this->assertEquals(
57  ['magento/theme-adminhtml-backend' => 7, 'magento/theme-frontend-luma' => 8],
58  (array)$this->object->get('nested', '/^magento\/theme/')
59  );
60  }
61 }