Set('developer_mode.enabled', false); $this->mockFileLog = $this->createMock('FileLog'); $this->oMetaModelConfig = $this->createMock('Config'); } /** * @dataProvider LogApiProvider * @test * @backupGlobals disabled */ public function TestLogApi($oConfigObject, $sMessage, $Channel, $sExpectedLevel, $sExpectedMessage, $sExpectedChannel = '') { \IssueLog::MockStaticObjects($this->mockFileLog, $oConfigObject); $this->mockFileLog->expects($this->exactly(1)) ->method($sExpectedLevel) ->with($sExpectedMessage, $sExpectedChannel); \IssueLog::Error($sMessage, $Channel); } public function LogApiProvider() { return [ [$this->oMetaModelConfig, "log msg", '', "Error", "log msg"], [$this->oMetaModelConfig, "log msg", 'PoudlardChannel', "Error", "log msg", 'PoudlardChannel'], [null, "log msg", '', "Error", "log msg"], ]; } /** * @dataProvider LogWarningWithASpecificChannelProvider * @test * @backupGlobals disabled */ public function TestLogWarningWithASpecificChannel($expectedCallNb, $sExpectedLevel, $ConfigReturnedObject, $bExceptionRaised=false) { $this->oMetaModelConfig ->method("Get") ->willReturnMap([ [\LogAPI::ENUM_CONFIG_PARAM_FILE, $ConfigReturnedObject], [\LogAPI::ENUM_CONFIG_PARAM_DB, $ConfigReturnedObject], ]); \IssueLog::MockStaticObjects($this->mockFileLog, $this->oMetaModelConfig); $this->mockFileLog->expects($this->exactly($expectedCallNb)) ->method($sExpectedLevel) ->with("log msg", "GaBuZoMeuChannel"); try{ \IssueLog::Warning("log msg", "GaBuZoMeuChannel"); if ($bExceptionRaised) { $this->fail("raised should have been raised"); } } catch(\Exception $e) { if (!$bExceptionRaised) { $this->fail("raised should NOT have been raised"); } } } public function LogWarningWithASpecificChannelProvider() { return [ "empty config" => [ 0, "Ok", ''], "Default Unknown Level" => [ 0, "Ok", 'TotoLevel', true], "Info as Default Level" => [ 1 , "Warning", 'Info'], "Error as Default Level" => [ 0, "Warning", 'Error'], "Empty array" => [ 0, "Ok", array()], "Channel configured on an undefined level" => [ 0, "Ok", ["GaBuZoMeuChannel" => "TotoLevel"], true], "Channel defined with Error" => [ 0, "Warning", ["GaBuZoMeuChannel" => "Error"]], "Channel defined with Info" => [ 1, "Warning", ["GaBuZoMeuChannel" => "Info"]], ]; } /** * @dataProvider LogOkWithASpecificChannel * @test * @backupGlobals disabled */ public function TestLogOkWithASpecificChannel($expectedCallNb, $sExpectedLevel, $ConfigReturnedObject, $bExceptionRaised=false) { $this->oMetaModelConfig ->method("Get") ->willReturnMap([ [\LogAPI::ENUM_CONFIG_PARAM_FILE, $ConfigReturnedObject], [\LogAPI::ENUM_CONFIG_PARAM_DB, $ConfigReturnedObject], ]); \IssueLog::MockStaticObjects($this->mockFileLog, $this->oMetaModelConfig); $this->mockFileLog->expects($this->exactly($expectedCallNb)) ->method($sExpectedLevel) ->with("log msg", "GaBuZoMeuChannel"); try { \IssueLog::Ok("log msg", "GaBuZoMeuChannel"); if ($bExceptionRaised) { $this->fail("raised should have been raised"); } } catch (\Exception $e) { if (!$bExceptionRaised) { $this->fail("raised should NOT have been raised"); } } } public function LogOkWithASpecificChannel() { return [ "empty config" => [1, "Ok", ''], "Empty array" => [1, "Ok", array()], ]; } /** * Tests that we are creating a valid object, with all its mandatory fields set ! * * @throws \CoreException */ public function testGetEventIssue(): void { $oEventIssue = $this->InvokeNonPublicStaticMethod(\LogAPI::class, 'GetEventIssue', [ 'My message', \LogChannels::CORE, ['context' => 'hop'], ]); // Finding mandatory fields in EventIssue class $aEventIssueAllAttributes = \MetaModel::ListAttributeDefs(\EventIssue::class); $aEventIssueMandatoryAttributes = array_filter($aEventIssueAllAttributes, static function ($oAttDef, $sAttCode) { if (false === $oAttDef->IsNullAllowed()) { return $oAttDef; } }, ARRAY_FILTER_USE_BOTH); // remove fields set in the OnInsert method unset($aEventIssueMandatoryAttributes['page']); foreach ($aEventIssueMandatoryAttributes as $sAttCode => $oAttDef) { $this->assertNotEmpty($oEventIssue->Get($sAttCode), "In the EventIssue instance returned by LogAPI the '$sAttCode' mandatory attr is empty :("); } } }