Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PhpUnitTest.php
Go to the documentation of this file.
1 <?php
10 namespace Magento\Test\Event;
11 
12 class PhpUnitTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $_object;
18 
22  protected $_eventManager;
23 
24  protected function setUp()
25  {
26  $this->_eventManager = $this->getMockBuilder(\Magento\TestFramework\EventManager::class)
27  ->setMethods(['fireEvent'])
28  ->setConstructorArgs([[]])
29  ->getMock();
30  $this->_object = new \Magento\TestFramework\Event\PhpUnit($this->_eventManager);
31  }
32 
33  protected function tearDown()
34  {
36  }
37 
39  {
41  $this->_object = new \Magento\TestFramework\Event\PhpUnit();
43  }
44 
48  public function testConstructorException()
49  {
50  new \Magento\TestFramework\Event\Magento();
51  }
52 
57  public function testDoNotFireEvent($method)
58  {
59  $this->_eventManager->expects($this->never())->method('fireEvent');
60  $this->_object->{$method}($this, new \PHPUnit\Framework\AssertionFailedError(), 0);
61  }
62 
63  public function doNotFireEventDataProvider()
64  {
65  return [
66  'method "addError"' => ['addError'],
67  'method "addFailure"' => ['addFailure'],
68  'method "addIncompleteTest"' => ['addIncompleteTest'],
69  'method "addSkippedTest"' => ['addSkippedTest']
70  ];
71  }
72 
73  public function testStartTestSuiteFireEvent()
74  {
75  $this->_eventManager->expects($this->once())->method('fireEvent')->with('startTestSuite');
76  $this->_object->startTestSuite(new \PHPUnit\Framework\TestSuite());
77  }
78 
80  {
81  $this->_eventManager->expects($this->never())->method('fireEvent');
82  $this->_object->startTestSuite(new \PHPUnit\Framework\DataProviderTestSuite());
83  }
84 
85  public function testEndTestSuiteFireEvent()
86  {
87  $this->_eventManager->expects($this->once())->method('fireEvent')->with('endTestSuite');
88  $this->_object->endTestSuite(new \PHPUnit\Framework\TestSuite());
89  }
90 
92  {
93  $this->_eventManager->expects($this->never())->method('fireEvent');
94  $this->_object->endTestSuite(new \PHPUnit\Framework\DataProviderTestSuite());
95  }
96 
97  public function testStartTestFireEvent()
98  {
99  $this->_eventManager->expects($this->once())->method('fireEvent')->with('startTest');
100  $this->_object->startTest($this);
101  }
102 
103  public function testStartTestDoNotFireEvent()
104  {
105  $this->_eventManager->expects($this->never())->method('fireEvent');
106  // $this->_object->startTest(new \PHPUnit\Framework\Warning());
107  $this->_object->startTest($this->createMock(\PHPUnit\Framework\Test::class));
108  }
109 
110  public function testEndTestFireEvent()
111  {
112  $this->_eventManager->expects($this->once())->method('fireEvent')->with('endTest');
113  $this->_object->endTest($this, 0);
114  }
115 
116  public function testEndTestDoNotFireEvent()
117  {
118  $this->_eventManager->expects($this->never())->method('fireEvent');
119  // $this->_object->endTest(new \PHPUnit\Framework\Warning(), 0);
120  $this->_object->endTest($this->createMock(\PHPUnit\Framework\Test::class), 0);
121  }
122 }
static setDefaultEventManager(\Magento\TestFramework\EventManager $eventManager=null)
Definition: PhpUnit.php:31
$method
Definition: info.phtml:13