Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QueueTest.php
Go to the documentation of this file.
1 <?php
7 
11 
13 use Magento\Framework\Locale\ResolverInterface as LocaleResolver;
15 use Psr\Log\LoggerInterface;
16 
17 use PHPUnit_Framework_MockObject_MockObject as Mock;
18 
24 class QueueTest extends \PHPUnit\Framework\TestCase
25 {
29  private $queue;
30 
34  private $appState;
35 
39  private $localeResolver;
40 
44  private $resourceConnection;
45 
49  private $logger;
50 
54  private $deployPackageService;
55 
59  protected function setUp()
60  {
61  $this->appState = $this->createMock(AppState::class);
62  $this->localeResolver = $this->getMockForAbstractClass(
63  LocaleResolver::class,
64  ['setLocale'],
65  '',
66  false
67  );
68  $this->resourceConnection = $this->createMock(ResourceConnection::class);
69  $this->logger = $this->getMockForAbstractClass(
70  LoggerInterface::class,
71  ['notice', 'info'],
72  '',
73  false
74  );
75  $this->deployPackageService = $this->createPartialMock(DeployPackage::class, ['deploy']);
76 
77  $this->queue = new Queue(
78  $this->appState,
79  $this->localeResolver,
80  $this->resourceConnection,
81  $this->logger,
82  $this->deployPackageService,
83  [],
84  1
85  );
86  }
87 
91  public function testAdd()
92  {
93  $package = $this->createMock(Package::class);
94  $package->expects($this->once())->method('getPath')->willReturn('path');
95 
96  $this->assertEquals(true, $this->queue->add($package));
97  $packages = $this->queue->getPackages();
98  $this->assertEquals(
99  $package,
100  isset($packages['path']['package']) ? $packages['path']['package'] : null
101  );
102  }
103 
107  public function testProcess()
108  {
109  $package = $this->createMock(Package::class);
110  $package->expects($this->any())->method('getState')->willReturn(0);
111  $package->expects($this->exactly(2))->method('getParent')->willReturn(true);
112  $package->expects($this->any())->method('getArea')->willReturn('area');
113  $package->expects($this->any())->method('getPath')->willReturn('path');
114  $package->expects($this->any())->method('getFiles')->willReturn([]);
115 
116  $this->appState->expects($this->once())->method('emulateAreaCode');
117 
118  $this->queue->add($package, []);
119 
120  $this->resourceConnection->expects(self::never())->method('closeConnection');
121 
122  $this->assertEquals(0, $this->queue->process());
123  }
124 }