Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions
TestLoggingUtil Class Reference
Inheritance diagram for TestLoggingUtil:

Public Member Functions

 setMockLoggingUtil ()
 
 validateMockLogStatement ($type, $message, $context)
 
 validateMockLogStatmentRegex ($type, $regex, $context)
 
 clearMockLoggingUtil ()
 

Static Public Member Functions

static getInstance ()
 

Detailed Description

Definition at line 16 of file TestLoggingUtil.php.

Member Function Documentation

◆ clearMockLoggingUtil()

clearMockLoggingUtil ( )

Function which clears the test logger context from the LogginUtil class. Should be run after a test class has executed.

Returns
void

Definition at line 101 of file TestLoggingUtil.php.

102  {
103  AspectMock::clean(LoggingUtil::class);
104  }

◆ getInstance()

static getInstance ( )
static

Static singleton get function

Returns
TestLoggingUtil

Definition at line 41 of file TestLoggingUtil.php.

42  {
43  if (self::$INSTANCE == null) {
44  self::$INSTANCE = new TestLoggingUtil();
45  }
46 
47  return self::$INSTANCE;
48  }

◆ setMockLoggingUtil()

setMockLoggingUtil ( )

Function which sets a mock instance of the logger for testing purposes.

Returns
void

Definition at line 55 of file TestLoggingUtil.php.

56  {
57  $this->testLogHandler = new TestHandler();
58  $testLogger = new MftfLogger('testLogger');
59  $testLogger->pushHandler($this->testLogHandler);
60  $mockLoggingUtil = AspectMock::double(
61  LoggingUtil::class,
62  ['getLogger' => $testLogger]
63  )->make();
64  $property = new \ReflectionProperty(LoggingUtil::class, 'INSTANCE');
65  $property->setAccessible(true);
66  $property->setValue($mockLoggingUtil);
67  }

◆ validateMockLogStatement()

validateMockLogStatement (   $type,
  $message,
  $context 
)

Function which validates messages have been logged as intended during test execution.

Parameters
string$type
string$message
array$context
Returns
void

Definition at line 77 of file TestLoggingUtil.php.

78  {
79  $records = $this->testLogHandler->getRecords();
80  $record = $records[count($records)-1]; // we assume the latest record is what requires validation
81  $this->assertEquals(strtoupper($type), $record['level_name']);
82  $this->assertEquals($message, $record['message']);
83  $this->assertEquals($context, $record['context']);
84  }
$message
$type
Definition: item.phtml:13

◆ validateMockLogStatmentRegex()

validateMockLogStatmentRegex (   $type,
  $regex,
  $context 
)

Definition at line 86 of file TestLoggingUtil.php.

87  {
88  $records = $this->testLogHandler->getRecords();
89  $record = $records[count($records)-1]; // we assume the latest record is what requires validation
90  $this->assertEquals(strtoupper($type), $record['level_name']);
91  $this->assertRegExp($regex, $record['message']);
92  $this->assertEquals($context, $record['context']);
93  }
$type
Definition: item.phtml:13

The documentation for this class was generated from the following file: