Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StaticCallsTest.php
Go to the documentation of this file.
1 <?php
7 
9 
12 class StaticCallsTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $staticCalls;
18 
22  protected $tokens;
23 
27  public function setUp()
28  {
29  $this->tokens = $this->getMockBuilder(
30  \Magento\TestFramework\Integrity\Library\PhpParser\Tokens::class
31  )->disableOriginalConstructor()->getMock();
32  }
33 
39  public function testGetDependencies()
40  {
41  $tokens = [
42  0 => [T_WHITESPACE, ' '],
43  1 => [T_NS_SEPARATOR, '\\'],
44  2 => [T_STRING, 'Object'],
45  3 => [T_PAAMAYIM_NEKUDOTAYIM, '::'],
46  ];
47 
48  $this->tokens->expects($this->any())->method('getPreviousToken')->will(
49  $this->returnCallback(
50  function ($k) use ($tokens) {
51  return $tokens[$k - 1];
52  }
53  )
54  );
55 
56  $this->tokens->expects($this->any())->method('getTokenCodeByKey')->will(
57  $this->returnCallback(
58  function ($k) use ($tokens) {
59  return $tokens[$k][0];
60  }
61  )
62  );
63 
64  $this->tokens->expects($this->any())->method('getTokenValueByKey')->will(
65  $this->returnCallback(
66  function ($k) use ($tokens) {
67  return $tokens[$k][1];
68  }
69  )
70  );
71 
72  $throws = new StaticCalls($this->tokens);
73  foreach ($tokens as $k => $token) {
74  $throws->parse($token, $k);
75  }
76 
77  $uses = $this->getMockBuilder(
78  \Magento\TestFramework\Integrity\Library\PhpParser\Uses::class
79  )->disableOriginalConstructor()->getMock();
80 
81  $uses->expects($this->once())->method('hasUses')->will($this->returnValue(true));
82 
83  $uses->expects($this->once())->method('getClassNameWithNamespace')->will($this->returnValue('\Object'));
84 
85  $this->assertEquals(['\Object'], $throws->getDependencies($uses));
86  }
87 }