Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThrowsTest.php
Go to the documentation of this file.
1 <?php
7 
9 
12 class ThrowsTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $throws;
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_THROW, 'throw'],
43  1 => [T_WHITESPACE, ' '],
44  2 => [T_NEW, 'new'],
45  3 => [T_WHITESPACE, ' '],
46  4 => [T_NS_SEPARATOR, '\\'],
47  5 => [T_STRING, 'Exception'],
48  6 => '(',
49  ];
50 
51  $this->tokens->expects($this->any())->method('getTokenCodeByKey')->will(
52  $this->returnCallback(
53  function ($k) use ($tokens) {
54  return $tokens[$k][0];
55  }
56  )
57  );
58 
59  $this->tokens->expects($this->any())->method('getTokenValueByKey')->will(
60  $this->returnCallback(
61  function ($k) use ($tokens) {
62  return $tokens[$k][1];
63  }
64  )
65  );
66 
67  $throws = new Throws($this->tokens);
68  foreach ($tokens as $k => $token) {
69  $throws->parse($token, $k);
70  }
71 
72  $uses = $this->getMockBuilder(
73  \Magento\TestFramework\Integrity\Library\PhpParser\Uses::class
74  )->disableOriginalConstructor()->getMock();
75 
76  $uses->expects($this->once())->method('hasUses')->will($this->returnValue(true));
77 
78  $uses->expects($this->once())->method('getClassNameWithNamespace')->will($this->returnValue('\Exception'));
79 
80  $this->assertEquals(['\Exception'], $throws->getDependencies($uses));
81  }
82 }