john_doemoor Posted June 11, 2012 Share Posted June 11, 2012 Hello guys, I need help with this: public function getUserLogLines($logLines, $householdId) { // Parse using parseLogLines // Append result to userLogLines member // Return userLogLines } So i should use previous function: public function parseLogLines($logLines, $householdId) { $matchingLines = ""; foreach(preg_split("/\n|\r/", $logLines) as $logLine) { if (preg_match("/$householdId/", $logLine) > 0) { $matchingLines .= trim($logLine) . "\n"; } } return trim($matchingLines); } to parse this: function testParseLogLines() { $logLine = "clientId:h-1-JG26D2S-s-0 refdata:sessionId: bv41h6ulfju3pg2sqe7j8r09f5;\r\n"; $logLine .= "This line doesn't contain the householdId\n"; $logLine .= "1-JG26D2S asd asd asd asas\n"; $expectedLogLines = "clientId:h-1-JG26D2S-s-0 refdata:sessionId: bv41h6ulfju3pg2sqe7j8r09f5;\n"; $expectedLogLines .= "1-JG26D2S asd asd asd asas"; $this->assertEquals($expectedLogLines, $this->logLiveView->parseLogLines($logLine, "1-JG26D2S")); } function testGetUserLogLines() { $logLine = "clientId:h-1-JG26D2S-s-0 refdata:sessionId: bv41h6ulfju3pg2sqe7j8r09f5;\r\n"; $logLine .= "This line doesn't contain the householdId\n"; $logLine .= "1-JG26D2S asd asd asd asas\n"; $expectedLogLines = "clientId:h-1-JG26D2S-s-0 refdata:sessionId: bv41h6ulfju3pg2sqe7j8r09f5;\n"; $expectedLogLines .= "1-JG26D2S asd asd asd asas"; $this->assertEquals($expectedLogLines, $this->logLiveView->getUserLogLines($logLine, "1-JG26D2S")); $logLine = "assd asd asdasdasdasd"; $this->assertEquals($expectedLogLines, $this->logLiveView->getUserLogLines($logLine, "1-JG26D2S")); $logLine = "asdf asdasdas h-1-JG26D2S-s-0 asdasasdasd\n"; $logLine .= "1223445\n"; $expectedLogLines .= "asdf asdasdas h-1-JG26D2S-s-0 asdasasdasd\n"; $this->assertEquals($expectedLogLines, $this->logLiveView->getUserLogLines($logLine, "1-JG26D2S")); } Any suggetions on how to do it? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/264004-how-do-i-use-function-from-the-same-class/ Share on other sites More sharing options...
scootstah Posted June 11, 2012 Share Posted June 11, 2012 I don't really understand your question. The $this object exists to use methods from within an instantiated class object. To illustrate that, take a look at this example: class Person { public function get_first_name() { return 'John'; } public function get_last_name() { return 'Doe'; } public function get_full_name() { return $this->get_first_name() . $this->get_last_name(); } } Quote Link to comment https://forums.phpfreaks.com/topic/264004-how-do-i-use-function-from-the-same-class/#findComment-1352972 Share on other sites More sharing options...
john_doemoor Posted June 11, 2012 Author Share Posted June 11, 2012 So my question was how do i use "parseLogLines" function to return loglines including specific "$householdId" as "userLogLines" on "getUserLogLines" function? logLines are given on PHPUnit's testcase... Quote Link to comment https://forums.phpfreaks.com/topic/264004-how-do-i-use-function-from-the-same-class/#findComment-1352992 Share on other sites More sharing options...
KevinM1 Posted June 11, 2012 Share Posted June 11, 2012 Are you looking for something like the following (took a guess with the $userLogLines field): public function getUserLogLines($logLines, $householdId) { $this->userLogLines .= $this->parseUserLogLines($logLines, $householdId); return $userLogLines; } ?? Quote Link to comment https://forums.phpfreaks.com/topic/264004-how-do-i-use-function-from-the-same-class/#findComment-1352996 Share on other sites More sharing options...
john_doemoor Posted June 11, 2012 Author Share Posted June 11, 2012 Yeah, you got the idea! gonna test it tomorrow, cause don't have testing enviroment on this pc... THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/264004-how-do-i-use-function-from-the-same-class/#findComment-1353000 Share on other sites More sharing options...
john_doemoor Posted June 12, 2012 Author Share Posted June 12, 2012 The first one worked, when i returned $this->userLogLines; and thanks for that! Still need help, i need to make a comparison in that function that lines haven't multiplied. function testGetUserLogLines_SameLogLinesAreNotMultiplied() { $loglines = "3294051,Sun Jun 10 17:59:59 2012,NFO,HB,10.111.221.30,RealGoldRush2,h-1-JG26D2S-s0\n"; $loglines .= "3294052,asdö aölköaslklk,RealGoldRush2,h-1-JG26D2S-s0\n"; $loglines .= "3294053,Sun Jun 10 17:59:59 2012,NFO,qwpjqwrepoqwe poqiwepoiqwe\n"; $expectedLoglines = "3294051,Sun Jun 10 17:59:59 2012,NFO,HB,10.111.221.30,RealGoldRush2,h-1-JG26D2S-s0\n"; $expectedLoglines .= "3294052,asdö aölköaslklk,RealGoldRush2,h-1-JG26D2S-s0"; $this->assertEquals($expectedLoglines, $this->schedulerLogLiveView->getUserLogLines($loglines, "1-JG26D2S")); $this->assertEquals($expectedLoglines, $this->schedulerLogLiveView->getUserLogLines($loglines, "1-JG26D2S")); } Quote Link to comment https://forums.phpfreaks.com/topic/264004-how-do-i-use-function-from-the-same-class/#findComment-1353097 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.