public function JsonLogDataTest::testCanConstructDefaultDataClass in JSONlog 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/JsonLogDataTest.php \Drupal\Tests\jsonlog\Unit\JsonLogDataTest::testCanConstructDefaultDataClass()
- 3.x tests/src/Unit/JsonLogDataTest.php \Drupal\Tests\jsonlog\Unit\JsonLogDataTest::testCanConstructDefaultDataClass()
Test default initialisation of JsonLogData class
File
- tests/
src/ Unit/ JsonLogDataTest.php, line 48
Class
- JsonLogDataTest
- Unit tests for JsonLogData class
Namespace
Drupal\Tests\jsonlog\UnitCode
public function testCanConstructDefaultDataClass() {
$this->data = new JsonLogData('test_site_id', 'test_canonical');
$this
->assertEquals('test_site_id', $this->data
->getSiteId());
$this
->assertEquals('test_canonical', $this->data
->getCanonical());
$this
->assertEquals('drupal', $this->data
->getType());
$this
->assertEquals(1, $this->data
->getData()['@version'], '@version set to 1');
$this
->assertEmpty($this->data
->getTrunc(), 'Trunc empty by default');
$this
->assertNotEmpty($this->data
->getData()['@timestamp']);
$this
->assertTrue(stripos($this->data
->getMessageId(), 'test_site_id') !== FALSE, 'Message ID set and contains site-id.');
$this
->assertTrue(strlen($this->data
->getMessageId()) > strlen('test_site_id'), 'Message ID string is longer than site-id.');
$first_timestamp = $this->data
->getData()['@timestamp'];
$first_message_id = $this->data
->getMessageId();
//microsleep because some fast CI environments might run tests so fast the timestamp does not differ.
usleep(100);
$this->data = new JsonLogData('test_site_id', 'test_canonical');
$this
->assertFalse($first_timestamp == $this->data
->getData()['@timestamp'], 'Timestamps always regenerated.');
$this
->assertFalse($first_message_id == $this->data
->getMessageId(), 'Message ID unique.');
}