diff --git a/src/Record/Timeline_Iterator.php b/src/Record/Timeline_Iterator.php index 6ee6db7..3a3e1a8 100644 --- a/src/Record/Timeline_Iterator.php +++ b/src/Record/Timeline_Iterator.php @@ -52,6 +52,8 @@ class Timeline_Iterator implements \Iterator { } /** + * @codeCoverageIgnore + * * @return void */ public function key() { diff --git a/tests/Record/IteratorTest.php b/tests/Record/IteratorTest.php new file mode 100644 index 0000000..7effa57 --- /dev/null +++ b/tests/Record/IteratorTest.php @@ -0,0 +1,63 @@ +assertCount( 1, $iterator->getArrayCopy() ); + + foreach ( $iterator as $record ) { + $this->assertEquals( 'Parent', $record->get_name() ); + } + + $this->assertTrue( $iterator->hasChildren() ); + $children = $iterator->getChildren(); + $this->assertCount( 1, $children ); + + foreach ( $children as $record ) { + $this->assertEquals( 'Child', $record->get_name() ); + } + + return $iterator; + } + + /** + * @depends testRecord + */ + public function testTimeline( Recursive_Record_Iterator $iterator ) { + + $iterator = new Timeline_Iterator( $iterator ); + + $iterator->rewind(); + $this->assertTrue( $iterator->valid() ); + + $records = $iterator->current(); + $this->assertInternalType( 'array', $records ); + + $this->assertArrayHasKey( 'description', $records[0] ); + $this->assertArrayHasKey( 'category', $records[0] ); + $this->assertArrayHasKey( 'offset', $records[0] ); + $this->assertArrayHasKey( 'width', $records[0] ); + + $iterator->next(); + $this->assertTrue( $iterator->valid() ); + + $records = $iterator->current(); + $this->assertInternalType( 'array', $records ); + + $iterator->next(); + $this->assertFalse( $iterator->valid() ); + } +} diff --git a/tests/Record/SqlTest.php b/tests/Record/SqlTest.php new file mode 100644 index 0000000..18bebdd --- /dev/null +++ b/tests/Record/SqlTest.php @@ -0,0 +1,43 @@ +assertTrue( has_filter( 'query', [ $collector, 'query' ] ) ); + + $query = 'SELECT * FROM wp_posts'; + + $collector->query( $query ); + + global $wpdb; + + $wpdb = new \stdClass(); + $duration = 100; + $wpdb->queries[] = [ $query, $duration ]; + + $records = $collector->get_records(); + + $this->assertInternalType( 'array', $records ); + $this->assertCount( 1, $records ); + + $record = $records[0]; + + $this->assertInstanceOf( Sql_Record::class, $record ); + $this->assertEquals( $query, $record->get_name() ); + $this->assertContains( $query, $record->get_description() ); + $this->assertInternalType( 'float', $record->get_origin() ); + $this->assertEquals( $duration * 1000, $record->get_duration() ); + $this->assertEquals( 'query-read', $record->get_category() ); + } +} diff --git a/tests/Record/StubRecord.php b/tests/Record/StubRecord.php new file mode 100644 index 0000000..1831c0d --- /dev/null +++ b/tests/Record/StubRecord.php @@ -0,0 +1,38 @@ +name = $name; + $this->origin = $origin; + $this->duration = $duration; + } + + public function get_name() { + return $this->name; + } + + public function get_description() { + + } + + public function get_origin() { + return $this->origin; + } + + public function get_duration() { + return $this->duration; + } + + public function get_category() { + + } +}