Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6bb7fadaa | ||
|
|
bd42c7b6a1 | ||
|
|
bbc7ff1ada | ||
|
|
7bffa1f49e | ||
|
|
ba72763486 | ||
|
|
739ed7dd90 | ||
|
|
59a17105ae | ||
|
|
e5079ce186 | ||
|
|
657fccb2de | ||
|
|
cc8c8a4756 | ||
|
|
2700d83208 | ||
|
|
8be22411f7 | ||
|
|
a678997c44 |
No files matched your search
@@ -6,6 +6,31 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 3.3 - 2019-03-27
|
||||
|
||||
### Added
|
||||
- plotting of early SQL queries (WP 5.1+)
|
||||
- tracking load of individual plugin load (WP 5.1+)
|
||||
|
||||
### Changed
|
||||
- unit tests for PHPUnit 8
|
||||
|
||||
### Fixed
|
||||
- error when formatting empty hook.
|
||||
|
||||
## 3.2 - 2019-01-30
|
||||
|
||||
### Added
|
||||
- Beaver Builder events
|
||||
- error message on unsupported PHP version
|
||||
|
||||
### Fixed
|
||||
- handling of reoccurring hook events
|
||||
- tracking of load events when network–activated
|
||||
|
||||
### Deprecated
|
||||
- dedicated classes for extension events
|
||||
|
||||
## 3.1 - 2019-01-22
|
||||
|
||||
### Added
|
||||
|
||||
@@ -42,6 +42,14 @@ API requests need to be authenticated as admin for performance data to be sent.
|
||||
| -------------------------------------------------- | -------- |
|
||||
| `composer require rarst/laps` | [](https://www.rarst.net/download/laps) |
|
||||
|
||||
## Tests
|
||||
|
||||
Tests require [Brain Monkey](https://github.com/Brain-WP/BrainMonkey) (included in dependencies) and PHPUnit 8 (not included).
|
||||
|
||||
```bash
|
||||
phpunit
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
Generated
+12
-12
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "185526a596d05cc666426641f175a314",
|
||||
"content-hash": "a72036af9e80358500e4274847500bcc",
|
||||
"packages": [
|
||||
{
|
||||
"name": "composer/installers",
|
||||
@@ -434,16 +434,16 @@
|
||||
},
|
||||
{
|
||||
"name": "brain/monkey",
|
||||
"version": "2.2.0",
|
||||
"version": "2.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Brain-WP/BrainMonkey.git",
|
||||
"reference": "ed9e0698bc1292f33698719da8ca1aa2e18acc51"
|
||||
"reference": "326a537bf518edd61bc57ab275e8b075ebb8a1a9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Brain-WP/BrainMonkey/zipball/ed9e0698bc1292f33698719da8ca1aa2e18acc51",
|
||||
"reference": "ed9e0698bc1292f33698719da8ca1aa2e18acc51",
|
||||
"url": "https://api.github.com/repos/Brain-WP/BrainMonkey/zipball/326a537bf518edd61bc57ab275e8b075ebb8a1a9",
|
||||
"reference": "326a537bf518edd61bc57ab275e8b075ebb8a1a9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -494,7 +494,7 @@
|
||||
"test",
|
||||
"testing"
|
||||
],
|
||||
"time": "2017-12-01T16:32:09+00:00"
|
||||
"time": "2019-03-15T13:42:24+00:00"
|
||||
},
|
||||
{
|
||||
"name": "hamcrest/hamcrest-php",
|
||||
@@ -546,16 +546,16 @@
|
||||
},
|
||||
{
|
||||
"name": "mockery/mockery",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mockery/mockery.git",
|
||||
"reference": "100633629bf76d57430b86b7098cd6beb996a35a"
|
||||
"reference": "0eb0b48c3f07b3b89f5169ce005b7d05b18cf1d2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/mockery/mockery/zipball/100633629bf76d57430b86b7098cd6beb996a35a",
|
||||
"reference": "100633629bf76d57430b86b7098cd6beb996a35a",
|
||||
"url": "https://api.github.com/repos/mockery/mockery/zipball/0eb0b48c3f07b3b89f5169ce005b7d05b18cf1d2",
|
||||
"reference": "0eb0b48c3f07b3b89f5169ce005b7d05b18cf1d2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -564,7 +564,7 @@
|
||||
"php": ">=5.6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~5.7.10|~6.5|~7.0"
|
||||
"phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
@@ -607,7 +607,7 @@
|
||||
"test double",
|
||||
"testing"
|
||||
],
|
||||
"time": "2018-10-02T21:52:37+00:00"
|
||||
"time": "2019-02-13T09:37:52+00:00"
|
||||
},
|
||||
{
|
||||
"name": "pds/skeleton",
|
||||
|
||||
@@ -5,7 +5,7 @@ Plugin Name: Laps
|
||||
Plugin URI: https://github.com/Rarst/laps
|
||||
Description: Light WordPress profiler.
|
||||
Author: Andrey “Rarst” Savchenko
|
||||
Version: 3.1
|
||||
Version: 3.3
|
||||
Author URI: https://www.rarst.net/
|
||||
Text Domain: laps
|
||||
Domain Path: /lang
|
||||
@@ -20,6 +20,10 @@ if ( ! class_exists( '\Rarst\Laps\Plugin' ) ) {
|
||||
trigger_error( 'Laps not fully installed! Please install with Composer or download full release archive.', E_USER_ERROR );
|
||||
}
|
||||
|
||||
if ( PHP_VERSION_ID < 70103 ) {
|
||||
trigger_error( 'Laps requires PHP version >=7.1.3.', E_USER_ERROR );
|
||||
}
|
||||
|
||||
$laps = new \Rarst\Laps\Plugin();
|
||||
|
||||
$laps->run();
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Event;
|
||||
|
||||
/**
|
||||
* Events for third party themes and plugins.
|
||||
*/
|
||||
class Extension_Events implements Hook_Event_Config_Interface {
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_events(): array {
|
||||
|
||||
return $this->beaver_builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Beaver Builder events.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function beaver_builder(): array {
|
||||
|
||||
$plugin = class_exists( 'FLBuilderLoader' ) ? [
|
||||
[
|
||||
'Beaver Builder Post Content',
|
||||
'plugin',
|
||||
'fl_builder_before_render_content',
|
||||
'fl_builder_after_render_content',
|
||||
],
|
||||
[
|
||||
'Beaver Builder Module',
|
||||
'plugin',
|
||||
'fl_builder_before_render_module',
|
||||
'fl_builder_after_render_module',
|
||||
],
|
||||
] : [];
|
||||
|
||||
$theme = class_exists( 'FLTheme' ) ? [
|
||||
[ 'Beaver Builder Top Bar', 'theme', 'fl_before_top_bar', 'fl_after_top_bar' ],
|
||||
[ 'Beaver Builder Header', 'theme', 'fl_before_header', 'fl_after_header' ],
|
||||
[ 'Beaver Builder Page Content', 'theme', 'fl_before_content', 'fl_after_content' ],
|
||||
[ 'Beaver Builder Post', 'theme', 'fl_before_post', 'fl_after_post' ],
|
||||
[ 'Beaver Builder Footer Widgets', 'theme', 'fl_before_footer_widgets', 'fl_after_footer_widgets' ],
|
||||
[ 'Beaver Builder Footer', 'theme', 'fl_before_footer', 'fl_after_footer' ],
|
||||
] : [];
|
||||
|
||||
return array_merge( $plugin, $theme );
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ namespace Rarst\Laps\Event;
|
||||
* Events for Genesis Framework based themes
|
||||
*
|
||||
* @link http://my.studiopress.com/themes/genesis/
|
||||
*
|
||||
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
|
||||
*/
|
||||
class Genesis_Events implements Hook_Event_Config_Interface {
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace Rarst\Laps\Event;
|
||||
* Events for Hybrid Core based themes
|
||||
*
|
||||
* @link http://themehybrid.com/hybrid-core
|
||||
*
|
||||
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
|
||||
*/
|
||||
class Hybrid_Events implements Hook_Event_Config_Interface {
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace Rarst\Laps\Event;
|
||||
* Events for Theme Hook Alliance
|
||||
*
|
||||
* @link http://zamoose.github.io/themehookalliance/
|
||||
*
|
||||
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
|
||||
*/
|
||||
class THA_Events implements Hook_Event_Config_Interface {
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace Rarst\Laps\Event;
|
||||
|
||||
/**
|
||||
* Events for WooCommerce plugin
|
||||
*
|
||||
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
|
||||
*/
|
||||
class WooCommerce_Events implements Hook_Event_Config_Interface {
|
||||
|
||||
@@ -16,6 +18,7 @@ class WooCommerce_Events implements Hook_Event_Config_Interface {
|
||||
return class_exists( 'WooCommerce' ) ? [
|
||||
[ 'WooCommerce Init', 'plugin', 'before_woocommerce_init', 'woocommerce_init' ],
|
||||
[ 'WooCommerce Shop Loop', 'plugin', 'woocommerce_before_shop_loop', 'woocommerce_after_shop_loop' ],
|
||||
[ 'WooCommerce Shop Item', 'plugin', 'woocommerce_before_shop_loop_item', 'woocommerce_after_shop_loop_item' ],
|
||||
[ 'WooCommerce Single Product', 'plugin', 'woocommerce_before_single_product', 'woocommerce_after_single_product' ],
|
||||
[ 'WooCommerce Cart', 'plugin', 'woocommerce_before_cart', 'woocommerce_after_cart' ],
|
||||
[ 'WooCommerce Checkout', 'plugin', 'woocommerce_before_checkout_form', 'woocommerce_after_checkout_form' ],
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace Rarst\Laps\Event;
|
||||
|
||||
/**
|
||||
* Events for Yoast plugins
|
||||
*
|
||||
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
|
||||
*/
|
||||
class Yoast_Events implements Hook_Event_Config_Interface {
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class Hook_Formatter {
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
// TODO inject paths instead of reaching for global constants.
|
||||
$this->truncate_paths = [
|
||||
wp_normalize_path( WP_CONTENT_DIR ),
|
||||
wp_normalize_path( ABSPATH ),
|
||||
@@ -35,6 +36,11 @@ class Hook_Formatter {
|
||||
if ( $hook instanceof \WP_Hook ) {
|
||||
$hook = $hook->callbacks;
|
||||
}
|
||||
|
||||
if ( empty( $hook ) ) {
|
||||
return $callbacks;
|
||||
}
|
||||
|
||||
ksort( $hook );
|
||||
|
||||
$functions = array_merge( ...$hook );
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Rarst\Laps\Provider;
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Event\Core_Events;
|
||||
use Rarst\Laps\Event\Extension_Events;
|
||||
use Rarst\Laps\Event\Genesis_Events;
|
||||
use Rarst\Laps\Event\Hybrid_Events;
|
||||
use Rarst\Laps\Event\THA_Events;
|
||||
@@ -25,6 +26,7 @@ class Hook_Event_Provider implements ServiceProviderInterface {
|
||||
$pimple['hook.events'] = function (): array {
|
||||
return [
|
||||
'core' => new Core_Events(),
|
||||
'extension' => new Extension_Events(),
|
||||
'genesis' => new Genesis_Events(),
|
||||
'hybrid' => new Hybrid_Events(),
|
||||
'tha' => new THA_Events(),
|
||||
|
||||
@@ -10,6 +10,7 @@ use Rarst\Laps\Record\Collector\Core_Load_Collector;
|
||||
use Rarst\Laps\Record\Collector\Hook_Collector;
|
||||
use Rarst\Laps\Record\Collector\Http_Collector;
|
||||
use Rarst\Laps\Record\Collector\Lazy_Proxy_Collector;
|
||||
use Rarst\Laps\Record\Collector\Plugin_Load_Collector;
|
||||
use Rarst\Laps\Record\Collector\Sql_Collector;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
@@ -31,6 +32,7 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int
|
||||
return [
|
||||
'core' => new Core_Load_Collector(),
|
||||
'hook' => new Hook_Collector( $laps['stopwatch'], $laps['hook.events'] ),
|
||||
'plugins' => new Plugin_Load_Collector(),
|
||||
'http' => new Http_Collector( $laps['stopwatch'] ),
|
||||
'sql' => new Sql_Collector(),
|
||||
];
|
||||
|
||||
@@ -14,11 +14,15 @@ class Core_Load_Collector implements Record_Collector_Interface {
|
||||
/** @var float $timeload */
|
||||
protected $timeload;
|
||||
|
||||
/** @var bool Flag if Laps is network activated. */
|
||||
private $network_activated;
|
||||
|
||||
/**
|
||||
* Store core load end, plugin load start mark.
|
||||
* Store plugin load start mark.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->timeload = microtime( true );
|
||||
$this->network_activated = ! did_action( 'muplugins_loaded' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,14 +41,15 @@ class Core_Load_Collector implements Record_Collector_Interface {
|
||||
$php .= empty( $zend_status['opcache_enabled'] ) ? '' : ' – OPcache';
|
||||
}
|
||||
|
||||
$load = $this->network_activated ? 'Core Load' : 'Core & MU Plugins Load';
|
||||
|
||||
/**
|
||||
* @var float $request_time
|
||||
* @var float $timestart
|
||||
*/
|
||||
return [
|
||||
new Record( $php, $request_time, $timestart - $request_time, '', 'php' ),
|
||||
// TODO This includes network plugins on multisite, need conditional label if Laps is network–activated.
|
||||
new Record( 'Core and MU Plugins Load', $timestart, $this->timeload - $timestart, '', 'core' ),
|
||||
new Record( $load, $timestart, $this->timeload - $timestart, '', 'core' ),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,9 @@ class Hook_Collector extends Stopwatch_Collector {
|
||||
/** @var Hook_Formatter */
|
||||
protected $formatter;
|
||||
|
||||
/** @var array $calls Tracks number of calls for recurrent events. */
|
||||
private $calls = [];
|
||||
|
||||
/**
|
||||
* @param Stopwatch $stopwatch Stopwatch instance.
|
||||
* @param Hook_Event_Config_Interface[] $event_configs Starts and stops configuration.
|
||||
@@ -34,7 +37,12 @@ class Hook_Collector extends Stopwatch_Collector {
|
||||
|
||||
parent::__construct( $stopwatch );
|
||||
|
||||
if ( did_action( 'muplugins_loaded' ) ) {
|
||||
$this->start( 'Plugins Load', 'plugin' );
|
||||
} else {
|
||||
$this->start( 'Network & MU Plugins Load', 'plugin' );
|
||||
add_action( 'muplugins_loaded', [ $this, 'muplugins_loaded' ], PHP_INT_MAX );
|
||||
}
|
||||
$this->add_events( $event_configs['core']->get_events() );
|
||||
unset( $event_configs['core'] );
|
||||
$this->event_configs = $event_configs;
|
||||
@@ -44,6 +52,14 @@ class Hook_Collector extends Stopwatch_Collector {
|
||||
$this->formatter = new Hook_Formatter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Time the point between network/MU plugins and regular if network activated.
|
||||
*/
|
||||
public function muplugins_loaded() {
|
||||
$this->stop( 'Network & MU Plugins Load' );
|
||||
$this->start( 'Plugins Load', 'plugin' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook events by name and priority from array.
|
||||
*
|
||||
@@ -97,6 +113,8 @@ class Hook_Collector extends Stopwatch_Collector {
|
||||
if ( '' !== $start ) {
|
||||
add_action( $start, function ( $input = null ) use ( $event, $category, $start, $stop ) {
|
||||
|
||||
$event .= $this->get_count_suffix( $event, true );
|
||||
|
||||
if ( 'Sidebar' === $event ) {
|
||||
$event = $input;
|
||||
}
|
||||
@@ -115,6 +133,8 @@ class Hook_Collector extends Stopwatch_Collector {
|
||||
if ( '' !== $stop ) {
|
||||
add_action( $stop, function ( $input = null ) use ( $event ) {
|
||||
|
||||
$event .= $this->get_count_suffix( $event );
|
||||
|
||||
if ( 'Sidebar' === $event ) {
|
||||
$event = $input;
|
||||
}
|
||||
@@ -126,6 +146,29 @@ class Hook_Collector extends Stopwatch_Collector {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the suffix to use if event occurs multiple times.
|
||||
*
|
||||
* @param string $event Event name.
|
||||
* @param boolean $increment Flag to increment count.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_count_suffix( string $event, bool $increment = false ): string {
|
||||
|
||||
if ( ! isset( $this->calls[ $event ] ) ) {
|
||||
$this->calls[ $event ] = 0;
|
||||
}
|
||||
|
||||
if ( $increment ) {
|
||||
$this->calls[ $event ] ++;
|
||||
}
|
||||
|
||||
$count = (int) $this->calls[ $event ];
|
||||
|
||||
return $count > 1 ? " ({$count})" : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* When theme is done possibly add vendor-specific events.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record\Collector;
|
||||
|
||||
use Rarst\Laps\Record\Record;
|
||||
use Rarst\Laps\Record\Record_Interface;
|
||||
|
||||
/**
|
||||
* Tracks load time of individual plugins.
|
||||
*/
|
||||
class Plugin_Load_Collector implements Record_Collector_Interface {
|
||||
|
||||
/** @var float */
|
||||
private $last;
|
||||
|
||||
/** @var array */
|
||||
private $entries = [];
|
||||
|
||||
/**
|
||||
* Sets up start time and tracking callbacks.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->last = microtime( true );
|
||||
|
||||
add_action( 'network_plugin_loaded', [ $this, 'plugin_loaded' ] );
|
||||
add_action( 'plugin_loaded', [ $this, 'plugin_loaded' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Records time for a plugin that just finished loading.
|
||||
*
|
||||
* @param string $plugin Plugin file path.
|
||||
*/
|
||||
public function plugin_loaded( string $plugin ): void {
|
||||
|
||||
$time = microtime( true );
|
||||
$this->entries[] = [
|
||||
'name' => $plugin,
|
||||
'origin' => $this->last,
|
||||
'duration' => $time - $this->last,
|
||||
];
|
||||
$this->last = $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Record_Interface[]
|
||||
*/
|
||||
public function get_records(): array {
|
||||
return array_map( [ $this, 'create_record' ], $this->entries );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts recorded information into a Record instance.
|
||||
*
|
||||
* @param array $entry Data entry for the plugin.
|
||||
*
|
||||
* @return Record_Interface
|
||||
*/
|
||||
private function create_record( array $entry ): Record_Interface {
|
||||
return new Record(
|
||||
plugin_basename( $entry['name'] ),
|
||||
$entry['origin'],
|
||||
$entry['duration'],
|
||||
'',
|
||||
'plugin'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class Sql_Collector implements Record_Collector_Interface {
|
||||
$this->formatter = new Backtrace_Formatter();
|
||||
|
||||
if ( $this->is_savequeries() ) {
|
||||
add_filter( 'query', [ $this, 'query' ], 20 ); // TODO refactor when core provides time start data in 5.0.
|
||||
add_filter( 'query', [ $this, 'query' ], 20 ); // TODO Drop recording time if dropping support for WP <5.1.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,9 @@ class Sql_Collector implements Record_Collector_Interface {
|
||||
}
|
||||
|
||||
/** @var array $wpdb->queries */
|
||||
return array_map( [ $this, 'transform' ], array_keys( $wpdb->queries ), $wpdb->queries );
|
||||
$records = array_filter( array_map( [ $this, 'transform' ], array_keys( $wpdb->queries ), $wpdb->queries ) );
|
||||
|
||||
return $records;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,25 +82,24 @@ class Sql_Collector implements Record_Collector_Interface {
|
||||
*
|
||||
* @param int $key Query key in captured data.
|
||||
* @param array $query_data Array of captured query data.
|
||||
* @psalm-param array{0: string, 1: float, 2: string} $query_data
|
||||
* @psalm-param array{0: string, 1: float, 2: string, 3: float} $query_data
|
||||
*
|
||||
* @return Record
|
||||
*/
|
||||
protected function transform( int $key, array $query_data ): Record {
|
||||
|
||||
static $last_query_end = 0;
|
||||
protected function transform( int $key, array $query_data ): ?Record {
|
||||
|
||||
[ $sql, $duration, $caller ] = $query_data;
|
||||
|
||||
/** @var float $query_start */
|
||||
$query_start = $this->query_starts[ $key ] ?? $last_query_end;
|
||||
$query_start = $query_data[3] ?? $this->query_starts[ $key ] ?? 0;
|
||||
if ( empty( $query_start ) ) {
|
||||
return null;
|
||||
}
|
||||
$sql = trim( $sql );
|
||||
$category = 'sql-read';
|
||||
if ( 0 === stripos( $sql, 'INSERT' ) || 0 === stripos( $sql, 'UPDATE' ) ) {
|
||||
$category = 'sql-write';
|
||||
}
|
||||
$last_query_end = $query_start + $duration;
|
||||
|
||||
$desc_duration = round( $duration * 1000 );
|
||||
$backtrace = $this->formatter->format( $caller );
|
||||
$description = $sql . ' – ' . $desc_duration . 'ms<hr />' . implode( '<br />', $backtrace );
|
||||
|
||||
@@ -17,7 +17,7 @@ class EventTest extends LapsTestCase {
|
||||
|
||||
$events = ( new Core_Events() )->get_events();
|
||||
|
||||
$this->assertInternalType( 'array', $events );
|
||||
$this->assertIsArray( $events );
|
||||
$this->assertNotEmpty( $events );
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class EventTest extends LapsTestCase {
|
||||
Functions\expect( 'genesis' )->zeroOrMoreTimes();
|
||||
$events = $genesis->get_events();
|
||||
|
||||
$this->assertInternalType( 'array', $events );
|
||||
$this->assertIsArray( $events );
|
||||
$this->assertNotEmpty( $events );
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class EventTest extends LapsTestCase {
|
||||
|
||||
$events = $hybrid->get_events();
|
||||
|
||||
$this->assertInternalType( 'array', $events );
|
||||
$this->assertIsArray( $events );
|
||||
$this->assertNotEmpty( $events );
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class EventTest extends LapsTestCase {
|
||||
|
||||
$events = $tha->get_events();
|
||||
|
||||
$this->assertInternalType( 'array', $events );
|
||||
$this->assertIsArray( $events );
|
||||
$this->assertNotEmpty( $events );
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class EventTest extends LapsTestCase {
|
||||
|
||||
$events = $woocommerce->get_events();
|
||||
|
||||
$this->assertInternalType( 'array', $events );
|
||||
$this->assertIsArray( $events );
|
||||
$this->assertNotEmpty( $events );
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class EventTest extends LapsTestCase {
|
||||
|
||||
$events = $yoast->get_events();
|
||||
|
||||
$this->assertInternalType( 'array', $events );
|
||||
$this->assertIsArray( $events );
|
||||
$this->assertNotEmpty( $events );
|
||||
}
|
||||
}
|
||||
@@ -51,8 +51,10 @@ class BacktraceTest extends LapsTestCase {
|
||||
|
||||
$result = $formatter->format( $backtrace );
|
||||
|
||||
$this->assertInternalType( 'array', $result );
|
||||
$this->assertArraySubset( [ 'foo', 'path.php' ], array_values( $result ) );
|
||||
$this->assertIsArray( $result );
|
||||
$result = array_values( $result );
|
||||
$this->assertEquals( 'foo', $result[0] );
|
||||
$this->assertEquals( 'path.php', $result[1] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +50,13 @@ class HookTest extends LapsTestCase {
|
||||
|
||||
$result = $formatter->format( $hook );
|
||||
|
||||
$this->assertInternalType( 'array', $result );
|
||||
$this->assertArraySubset( [ 'function(2)', 'class::method' ], $result );
|
||||
$this->assertIsArray( $result );
|
||||
$this->assertEquals( 'function(2)', $result[0] );
|
||||
$this->assertEquals( 'class::method', $result[1] );
|
||||
$this->assertStringStartsWith( 'closure from', $result[2] );
|
||||
$this->assertStringStartsWith( 'anonymous class from', $result[3] );
|
||||
|
||||
$this->assertEquals( [], $formatter->format( [] ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ class LapsTestCase extends TestCase {
|
||||
|
||||
use MockeryPHPUnitIntegration;
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp():void {
|
||||
parent::setUp();
|
||||
Monkey\setUp();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
protected function tearDown(): void {
|
||||
Monkey\tearDown();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class LoadOrderTest extends LapsTestCase {
|
||||
|
||||
$plugins = $manager->pre_update_option_active_plugins( $plugins );
|
||||
|
||||
$this->assertInternalType( 'array', $plugins );
|
||||
$this->assertIsArray( $plugins );
|
||||
$this->assertCount( 3, $plugins );
|
||||
$this->assertEquals( 'laps/laps.php', $plugins[0] );
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class CoreTest extends LapsTestCase {
|
||||
|
||||
$records = $collector->get_records();
|
||||
|
||||
$this->assertInternalType( 'array', $records );
|
||||
$this->assertIsArray( $records );
|
||||
$this->assertCount( 2, $records );
|
||||
$this->assertInstanceOf( Record_Interface::class, $records[0] );
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ class HookTest extends LapsTestCase {
|
||||
$stopwatch = new Stopwatch();
|
||||
$collector = new Hook_Collector( $stopwatch, [ 'core' => new Core_Events() ] );
|
||||
|
||||
$this->assertTrue( $stopwatch->isStarted( 'Plugins Load' ) );
|
||||
$this->assertTrue( has_action( 'after_setup_theme', [ $collector, 'after_setup_theme' ] ) );
|
||||
|
||||
$this->assertTrue( has_action( 'plugins_loaded', 'function ($input)' ) );
|
||||
|
||||
@@ -53,7 +53,7 @@ class IteratorTest extends LapsTestCase {
|
||||
$this->assertTrue( $iterator->valid() );
|
||||
|
||||
$records = $iterator->current();
|
||||
$this->assertInternalType( 'array', $records );
|
||||
$this->assertIsArray( $records );
|
||||
|
||||
$this->assertArrayHasKey( 'description', $records[0] );
|
||||
$this->assertArrayHasKey( 'category', $records[0] );
|
||||
@@ -64,7 +64,7 @@ class IteratorTest extends LapsTestCase {
|
||||
$this->assertTrue( $iterator->valid() );
|
||||
|
||||
$records = $iterator->current();
|
||||
$this->assertInternalType( 'array', $records );
|
||||
$this->assertIsArray( $records );
|
||||
|
||||
$iterator->next();
|
||||
$this->assertFalse( $iterator->valid() );
|
||||
|
||||
@@ -24,8 +24,8 @@ class RecordTest extends LapsTestCase {
|
||||
$this->assertEquals( $name, $record->get_name() );
|
||||
$this->assertEquals( $origin, $record->get_origin() );
|
||||
$this->assertEquals( $duration, $record->get_duration() );
|
||||
$this->assertContains( $name, $record->get_description() );
|
||||
$this->assertContains( (string) ( $duration * 1000 ), $record->get_description() );
|
||||
$this->assertStringContainsString( $name, $record->get_description() );
|
||||
$this->assertStringContainsString( (string) ( $duration * 1000 ), $record->get_description() );
|
||||
$this->assertEmpty( $record->get_category() );
|
||||
|
||||
$record = new Record( $name, $origin, $duration, $description, $category );
|
||||
|
||||
@@ -38,15 +38,15 @@ class SqlTest extends LapsTestCase {
|
||||
|
||||
$records = $collector->get_records();
|
||||
|
||||
$this->assertInternalType( 'array', $records );
|
||||
$this->assertIsArray( $records );
|
||||
$this->assertCount( 1, $records );
|
||||
|
||||
$record = $records[0];
|
||||
|
||||
$this->assertInstanceOf( Record::class, $record );
|
||||
$this->assertEquals( $query, $record->get_name() );
|
||||
$this->assertContains( $query, $record->get_description() );
|
||||
$this->assertInternalType( 'float', $record->get_origin() );
|
||||
$this->assertStringContainsString( $query, $record->get_description() );
|
||||
$this->assertIsFloat( $record->get_origin() );
|
||||
$this->assertEquals( $duration, $record->get_duration() );
|
||||
$this->assertEquals( 'sql-read', $record->get_category() );
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class StopwatchTest extends LapsTestCase {
|
||||
|
||||
$records = $collector->get_records();
|
||||
|
||||
$this->assertInternalType( 'array', $records );
|
||||
$this->assertIsArray( $records );
|
||||
$this->assertCount( 1, $records );
|
||||
$this->assertInstanceOf( Stopwatch_Record::class, $records[0] );
|
||||
|
||||
@@ -47,6 +47,6 @@ class StopwatchTest extends LapsTestCase {
|
||||
$this->assertEquals( 'info', $record->get_category() );
|
||||
$this->assertEquals( $event->getOrigin() / 1000, $record->get_origin() );
|
||||
$this->assertEquals( $event->getDuration() / 1000, $record->get_duration() );
|
||||
$this->assertContains( 'Event', $record->get_description() );
|
||||
$this->assertStringContainsString( 'Event', $record->get_description() );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user