DataSift\Storyplayer\PlayerLib\Action_LogItem::startAction PHP Method

startAction() public method

public startAction ( mixed $message, array | null $codeLine = null ) : Action_LogItem
$message mixed the message to log. if it isn't a string, we'll convert it and apply the user's -V preference before logging
$codeLine array | null metadata about the line of code that we're logging about
return Action_LogItem return $this for fluent interfaces
    public function startAction($message, $codeLine = null)
    {
        // when did this happen?
        $this->startTime = microtime(true);
        $this->endTime = null;
        // only log the top-level item
        if ($this->nestLevel > 1) {
            $codeLine = null;
        }
        // convert to string if required
        //
        // if the user hasn't used -V from the command-line, then this
        // will also truncate the output
        if (is_array($message)) {
            $text = $this->dataFormatter->convertMessageArray($message);
        } else {
            $text = $this->dataFormatter->convertData($message);
        }
        // write to screen
        $this->writeToLog($text, $codeLine);
        // all done
        return $this;
    }

Usage Example

Example #1
0
 /**
  * @covers DataSift\Storyplayer\PlayerLib\Action_LogItem::startStep
  * @covers DataSift\Storyplayer\PlayerLib\Action_LogItem::endStep
  * @covers DataSift\Storyplayer\PlayerLib\Action_LogItem::getOpenAction
  */
 public function testAddAStepWithoutUsingACallable()
 {
     // ----------------------------------------------------------------
     // setup your test
     // the messages we are logging
     $startMsg1 = "This is a test message";
     $startMsg2 = "This is the nested test message";
     // our DI container
     $i = new Injectables();
     // our mocked output object
     $i->output = Mockery::mock("DataSift\\Storyplayer\\Output");
     $i->output->shouldReceive('logPhaseActivity')->once()->with($startMsg1, null);
     $i->output->shouldReceive('logPhaseActivity')->once()->with('  ' . $startMsg2, null);
     // our real data formatter
     $i->dataFormatter = new DataFormatter();
     // our unit under test
     $obj = new Action_LogItem($i, 1);
     $obj->startAction($startMsg1);
     // make sure the message started
     $this->assertTrue($obj->getIsOpen());
     // ----------------------------------------------------------------
     // perform the change
     $obj->startStep($startMsg2);
     $nestedObj = $obj->getOpenAction();
     $this->assertNotSame($obj, $nestedObj);
     $this->assertTrue($nestedObj->getIsOpen());
     $obj->endStep();
     $this->assertTrue($nestedObj->getIsComplete());
     // ----------------------------------------------------------------
     // test the results
     Mockery::close();
 }
All Usage Examples Of DataSift\Storyplayer\PlayerLib\Action_LogItem::startAction