Use getMessageType and getMessage to parse a message
public getMessages ( ) : array | ||
return | array |
public function testMessageBag() { $messageBag = new MessageBag(); $messageBag->writeInfo(' <blah>this is a line</blah> '); $messageBag->writeLine(' <blah>this is a line</blah> '); $messageBag->writeError(' <blah>this is a line</blah> '); $messageBag->writeComment(' <blah>this is a line</blah> '); $messageBag->writeQuestion(' <blah>this is a line</blah> '); $messages = $messageBag->getMessages(); $this->assertTrue($messageBag->hasMessages()); $this->assertInternalType('array', $messages); $message = current($messages); $this->assertEquals(MessageBag::INFO, $messageBag->getMessageType($message)); $this->assertEquals('this is a line', $messageBag->getMessage($message)); $message = next($messages); $this->assertEquals(MessageBag::LINE, $messageBag->getMessageType($message)); $this->assertEquals('this is a line', $messageBag->getMessage($message)); $message = next($messages); $this->assertEquals(MessageBag::ERROR, $messageBag->getMessageType($message)); $this->assertEquals('this is a line', $messageBag->getMessage($message)); $message = next($messages); $this->assertEquals(MessageBag::COMMENT, $messageBag->getMessageType($message)); $this->assertEquals('this is a line', $messageBag->getMessage($message)); $message = next($messages); $this->assertEquals(MessageBag::QUESTION, $messageBag->getMessageType($message)); $this->assertEquals('this is a line', $messageBag->getMessage($message)); $messageBag->deleteMessages(); $this->assertFalse($messageBag->hasMessages()); }
/** * */ public function testSearchForRegexLemma() { /** @noinspection PhpVoidFunctionResultUsedInspection */ $return = Artisan::call('localization:find', array('lemma' => 'message\\.lemma.*', '--verbose' => true, '--short' => true, '--regex' => true)); $this->assertEquals(1, $return); $this->assertContains('The argument is not a valid regular expression:', Artisan::output()); /** @noinspection PhpVoidFunctionResultUsedInspection */ $return = Artisan::call('localization:find', array('lemma' => '@message\\.lemma.*@', '--verbose' => true, '--short' => true, '--regex' => true)); $this->assertEquals(0, $return); $this->assertContains('has been found in', Artisan::output()); $messageBag = new MessageBag(); $manager = new Localization($messageBag); $trans_methods = array('trans' => array('@trans\\(\\s*(\'.*\')\\s*(,.*)*\\)@U', '@trans\\(\\s*(".*")\\s*(,.*)*\\)@U'), 'Lang::Get' => array('@Lang::Get\\(\\s*(\'.*\')\\s*(,.*)*\\)@U', '@Lang::Get\\(\\s*(".*")\\s*(,.*)*\\)@U', '@Lang::get\\(\\s*(\'.*\')\\s*(,.*)*\\)@U', '@Lang::get\\(\\s*(".*")\\s*(,.*)*\\)@U'), 'trans_choice' => array('@trans_choice\\(\\s*(\'.*\')\\s*,.*\\)@U', '@trans_choice\\(\\s*(".*")\\s*,.*\\)@U'), 'Lang::choice' => array('@Lang::choice\\(\\s*(\'.*\')\\s*,.*\\)@U', '@Lang::choice\\(\\s*(".*")\\s*,.*\\)@U'), '@lang' => array('@\\@lang\\(\\s*(\'.*\')\\s*(,.*)*\\)@U', '@\\@lang\\(\\s*(".*")\\s*(,.*)*\\)@U'), '@choice' => array('@\\@choice\\(\\s*(\'.*\')\\s*,.*\\)@U', '@\\@choice\\(\\s*(".*")\\s*,.*\\)@U')); $return = $manager->findLemma('not a valid regex', $manager->getPath(self::MOCK_DIR_PATH_GLOBAL), $trans_methods, true, true); $messages = $messageBag->getMessages(); $this->assertFalse($return); $this->assertContains('The argument is not a valid regular expression:', $messages[0][1]); }