39 Commits
Author SHA1 Message Date
Andrey Savchenko cc7670f3c3 Released version 3.3.2 2020-03-11 13:19:54 +02:00
Andrey Savchenko f62eff890a Fixed large server timing headers breaking proxies.
Fixes #40
2020-03-11 13:18:41 +02:00
Andrey Savchenko b0584dea0a Fixed type crash when URL passed to network request filters is invalid.
Fixes #42
2020-03-11 12:58:12 +02:00
Andrey Savchenko dc88dcce1e Adjusted bunch of inline doc to make Psalm pass again. 2020-02-21 18:22:53 +02:00
Andrey Savchenko f4f659c95a Changed bootable interface to inherit so mock can work on PHPUnit 9. 2020-02-21 17:19:02 +02:00
Andrey Savchenko 6be80cc832 Updated dependencies (Mustache.php 2.13) 2020-02-21 17:15:00 +02:00
Andrey Savchenko 4930979989 Dropped no longer used version in file name from readme badges. 2020-02-21 17:11:24 +02:00
Andrey Savchenko 168a226859 Changed download links to native github redirect 2019-12-31 16:14:23 +02:00
Andrey Savchenko 588b597f99 Released version 3.3.1 2019-07-02 14:46:13 +03:00
Andrey Savchenko 54ba716ba8 Fixed crash from broken plugin loaded hook input from global
Fixes #35
2019-07-02 14:46:13 +03:00
Ramon Fincken e2f85f44d2 [TASK] Update link to wp-config define (#38) 2019-07-01 08:03:32 +03:00
Andrey Savchenko a2ae665dd2 Disabled Mixed Psalm errors because I quit. 2019-06-16 00:24:03 +03:00
Andrey Savchenko f8f5e436e5 Fixed global and data Psalm errors. 2019-06-16 00:23:12 +03:00
Andrey Savchenko 6cab9bbd6b Changed Psalm template attempt to type. 2019-06-16 00:22:45 +03:00
Andrey Savchenko 1e9a600096 Psalm cleanup pass. 2019-06-15 10:11:50 +03:00
Andrey Savchenko cc1cdc577a Disabled Psalm error for known deprecated class use. 2019-06-14 20:15:39 +03:00
Andrey Savchenko d3e352d9f3 Adjusted PHPDoc on event classes. 2019-06-14 20:09:54 +03:00
Andrey Savchenko e6bb7fadaa Released version 3.3 2019-03-27 21:42:16 +02:00
Andrey Savchenko bd42c7b6a1 Added tracking load of individual plugin load (WP 5.1+)
Fixes #24
2019-03-27 21:40:52 +02:00
Andrey Savchenko bbc7ff1ada Dropped queries with unknown start time (that never worked). 2019-03-25 19:19:18 +02:00
Andrey Savchenko 7bffa1f49e Added plotting of early SQL queries (WP 5.1+)
Fixes #19
2019-03-24 21:20:55 +02:00
Andrey Savchenko ba72763486 Fixed error when formatting empty hook.
Prop @kellymears Closes #30
2019-03-24 19:52:42 +02:00
Andrey Savchenko 739ed7dd90 Updated unit tests for PHPUnit 8. 2019-03-24 19:32:33 +02:00
Andrey Savchenko 59a17105ae Released version 3.2. 2019-01-30 19:06:55 +02:00
Andrey Savchenko e5079ce186 Added error message on unsupported PHP version. 2019-01-30 19:06:40 +02:00
Andrey Savchenko 657fccb2de Deprecated dedicated classes for extension events. 2019-01-30 19:01:15 +02:00
Andrey Savchenko cc8c8a4756 Added Beaver Builder events. 2019-01-30 18:57:49 +02:00
Andrey Savchenko 2700d83208 Fixed tracking of load events when network–activated. 2019-01-29 17:42:10 +02:00
Andrey Savchenko 8be22411f7 Added WooCommerce loop item event. 2019-01-29 16:34:08 +02:00
Andrey Savchenko a678997c44 Fixed handling of reoccurring hook events. 2019-01-29 16:23:49 +02:00
Andrey Savchenko b4c49f3c67 Released version 3.1 2019-01-22 16:39:05 +02:00
Andrey Savchenko 4d93d2542d Corrected class description. 2019-01-22 16:35:15 +02:00
Andrey Savchenko e1176b7f67 Added error message on incomplete install. 2019-01-22 16:34:25 +02:00
Andrey Savchenko 828d70cdd1 Added PHP version and OPcache status information. 2019-01-22 16:27:38 +02:00
Andrey Savchenko 15ff72afb0 Added WooCommerce events.
Fixes #29
2019-01-22 16:14:14 +02:00
Andrey Savchenko ad246ad1bc Fixed headers error from new line in Server Timing.
Fixes #28
2019-01-22 15:12:21 +02:00
Andrey Savchenko c1a389dc17 Fixed fatal error when HTTP request is pre–filtered. 2019-01-09 19:04:15 +02:00
Andrey Savchenko d724958dec Rounded memory value, saw a screenshot with it blowing up (hadn't seen on my systems). 2019-01-02 23:22:31 +02:00
Andrey Savchenko 950031bbaf Dropped Bootstrap bits from ignore to stop production build complaining. 2019-01-01 22:06:43 +02:00
42 changed files with 519 additions and 195 deletions

No files matched your search

+55
View File
@@ -6,6 +6,61 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
## 3.3.2 - 2020-03-11
### Changed
- `Bootable_Provider_Interface` to extend `ServiceProviderInterface`, so that it can be mocked in PHPUnit 9
### Fixed
- Mustache.php version to resolve issues on PHP 7.4
- type crash when URL passed to network request filters is invalid
- large server timing headers breaking proxies
## 3.3.1 - 2019-07-02
### Fixed
- crash from broken plugin loaded hook input from global
## 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
- WooCommerce events
- PHP version and OPcache status information
- error message on incomplete install
### Fixed
- headers error from new line in Server Timing
## 3.0.1 - 2019-01-09
### Fixed
- fatal error when HTTP request is pre–filtered
## 3.0 - 2018-12-28
### Added
+11 -3
View File
@@ -11,7 +11,7 @@ _Make a site, make it fast._
[![Latest Stable Version](https://img.shields.io/packagist/v/rarst/laps.svg?label=version)](https://packagist.org/packages/rarst/laps)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/rarst/laps.svg)](https://packagist.org/packages/rarst/laps)
[![PDS Skeleton](https://img.shields.io/badge/pds-skeleton-blue.svg)](https://github.com/php-pds/skeleton)
[![Download Laps](https://img.shields.io/badge/dynamic/json.svg?label=download&url=https://api.github.com/repos/rarst/laps/releases/latest&query=$.assets%5B0%5D.name)](https://www.rarst.net/download/laps)
[![Download Laps](https://img.shields.io/badge/download-laps.zip-blue)](https://github.com/Rarst/laps/releases/latest/download/laps.zip)
Laps is a plugin that **shows performance information** about WordPress page load.
@@ -21,7 +21,7 @@ It provides a visual summary in toolbar that is quick and easy to inspect.
Laps automatically tracks many events, such as:
- PHP, core, plugins, and themes load, main posts loop, sidebars
- database queries (with [`SAVEQUERIES` constant](http://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis) enabled)
- database queries (with [`SAVEQUERIES` defined constant set to true](https://wordpress.org/support/article/editing-wp-config-php/#save-queries-for-analysis))
- network requests to other sites
## API profiling
@@ -40,7 +40,15 @@ API requests need to be authenticated as admin for performance data to be sent.
| [Composer](https://getcomposer.org/) (recommended) | Release archive |
| -------------------------------------------------- | -------- |
| `composer require rarst/laps` | [![Download Laps](https://img.shields.io/badge/dynamic/json.svg?label=download&url=https%3A%2F%2Fapi.github.com%2Frepos%2Frarst%2Flaps%2Freleases%2Flatest&query=%24.assets[0].name&style=for-the-badge)](https://www.rarst.net/download/laps) |
| `composer require rarst/laps` | [![Download Laps](https://img.shields.io/badge/download-laps.zip-blue?style=for-the-badge)](https://github.com/Rarst/laps/releases/latest/download/laps.zip) |
## Tests
Tests require [Brain Monkey](https://github.com/Brain-WP/BrainMonkey) (included in dependencies) and PHPUnit 8 (not included).
```bash
phpunit
```
## License
-5
View File
@@ -47,11 +47,6 @@
],
"symfony/stopwatch": [
"Tests"
],
"twbs/bootstrap" : [
"docs",
"grunt",
"js/tests"
]
}
}
Generated
+63 -64
View File
@@ -4,20 +4,20 @@
"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",
"version": "v1.6.0",
"version": "v1.8.0",
"source": {
"type": "git",
"url": "https://github.com/composer/installers.git",
"reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b"
"reference": "7d610d50aae61ae7ed6675e58efeabdf279bb5e3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/installers/zipball/cfcca6b1b60bc4974324efb5783c13dca6932b5b",
"reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b",
"url": "https://api.github.com/repos/composer/installers/zipball/7d610d50aae61ae7ed6675e58efeabdf279bb5e3",
"reference": "7d610d50aae61ae7ed6675e58efeabdf279bb5e3",
"shasum": ""
},
"require": {
@@ -65,6 +65,7 @@
"Kanboard",
"Lan Management System",
"MODX Evo",
"MantisBT",
"Mautic",
"Maya",
"OXID",
@@ -73,6 +74,7 @@
"RadPHP",
"SMF",
"Thelia",
"Whmcs",
"WolfCMS",
"agl",
"aimeos",
@@ -95,6 +97,7 @@
"installer",
"itop",
"joomla",
"known",
"kohana",
"laravel",
"lavalite",
@@ -117,6 +120,7 @@
"shopware",
"silverstripe",
"sydes",
"sylius",
"symfony",
"typo3",
"wordpress",
@@ -124,20 +128,20 @@
"zend",
"zikula"
],
"time": "2018-08-27T06:10:37+00:00"
"time": "2020-02-07T10:39:20+00:00"
},
{
"name": "mustache/mustache",
"version": "v2.12.0",
"version": "v2.13.0",
"source": {
"type": "git",
"url": "https://github.com/bobthecow/mustache.php.git",
"reference": "fe8fe72e9d580591854de404cc59a1b83ca4d19e"
"reference": "e95c5a008c23d3151d59ea72484d4f72049ab7f4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bobthecow/mustache.php/zipball/fe8fe72e9d580591854de404cc59a1b83ca4d19e",
"reference": "fe8fe72e9d580591854de404cc59a1b83ca4d19e",
"url": "https://api.github.com/repos/bobthecow/mustache.php/zipball/e95c5a008c23d3151d59ea72484d4f72049ab7f4",
"reference": "e95c5a008c23d3151d59ea72484d4f72049ab7f4",
"shasum": ""
},
"require": {
@@ -170,7 +174,7 @@
"mustache",
"templating"
],
"time": "2017-07-11T12:54:05+00:00"
"time": "2019-11-23T21:40:31+00:00"
},
{
"name": "pimple/pimple",
@@ -272,46 +276,36 @@
"time": "2017-02-14T16:28:37+00:00"
},
{
"name": "symfony/contracts",
"version": "v1.0.2",
"name": "symfony/service-contracts",
"version": "v2.0.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/contracts.git",
"reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf"
"url": "https://github.com/symfony/service-contracts.git",
"reference": "144c5e51266b281231e947b51223ba14acf1a749"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf",
"reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf",
"url": "https://api.github.com/repos/symfony/service-contracts/zipball/144c5e51266b281231e947b51223ba14acf1a749",
"reference": "144c5e51266b281231e947b51223ba14acf1a749",
"shasum": ""
},
"require": {
"php": "^7.1.3"
},
"require-dev": {
"psr/cache": "^1.0",
"php": "^7.2.5",
"psr/container": "^1.0"
},
"suggest": {
"psr/cache": "When using the Cache contracts",
"psr/container": "When using the Service contracts",
"symfony/cache-contracts-implementation": "",
"symfony/service-contracts-implementation": "",
"symfony/translation-contracts-implementation": ""
"symfony/service-implementation": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Contracts\\": ""
},
"exclude-from-classmap": [
"**/Tests/"
]
"Symfony\\Contracts\\Service\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -327,7 +321,7 @@
"homepage": "https://symfony.com/contributors"
}
],
"description": "A set of abstractions extracted out of the Symfony components",
"description": "Generic abstractions related to writing services",
"homepage": "https://symfony.com",
"keywords": [
"abstractions",
@@ -337,30 +331,30 @@
"interoperability",
"standards"
],
"time": "2018-12-05T08:06:11+00:00"
"time": "2019-11-18T17:27:11+00:00"
},
{
"name": "symfony/stopwatch",
"version": "v4.2.1",
"version": "v4.4.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
"reference": "ec076716412274e51f8a7ea675d9515e5c311123"
"reference": "abc08d7c48987829bac301347faa10f7e8bbf4fb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/ec076716412274e51f8a7ea675d9515e5c311123",
"reference": "ec076716412274e51f8a7ea675d9515e5c311123",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/abc08d7c48987829bac301347faa10f7e8bbf4fb",
"reference": "abc08d7c48987829bac301347faa10f7e8bbf4fb",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/contracts": "^1.0"
"symfony/service-contracts": "^1.0|^2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
"dev-master": "4.4-dev"
}
},
"autoload": {
@@ -387,27 +381,30 @@
],
"description": "Symfony Stopwatch Component",
"homepage": "https://symfony.com",
"time": "2018-11-11T19:52:12+00:00"
"time": "2020-01-04T13:00:46+00:00"
}
],
"packages-dev": [
{
"name": "antecedent/patchwork",
"version": "2.1.8",
"version": "2.1.12",
"source": {
"type": "git",
"url": "https://github.com/antecedent/patchwork.git",
"reference": "3bb81ace3914c220aa273d1c0603d5e1b454c0d7"
"reference": "b98e046dd4c0acc34a0846604f06f6111654d9ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/antecedent/patchwork/zipball/3bb81ace3914c220aa273d1c0603d5e1b454c0d7",
"reference": "3bb81ace3914c220aa273d1c0603d5e1b454c0d7",
"url": "https://api.github.com/repos/antecedent/patchwork/zipball/b98e046dd4c0acc34a0846604f06f6111654d9ea",
"reference": "b98e046dd4c0acc34a0846604f06f6111654d9ea",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": ">=4"
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -430,20 +427,20 @@
"runkit",
"testing"
],
"time": "2018-02-19T18:52:50+00:00"
"time": "2019-12-22T17:52:09+00:00"
},
{
"name": "brain/monkey",
"version": "2.2.0",
"version": "2.4.0",
"source": {
"type": "git",
"url": "https://github.com/Brain-WP/BrainMonkey.git",
"reference": "ed9e0698bc1292f33698719da8ca1aa2e18acc51"
"reference": "b3ce8b619c26db6abd01b9dcfd6a2c0254060956"
},
"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/b3ce8b619c26db6abd01b9dcfd6a2c0254060956",
"reference": "b3ce8b619c26db6abd01b9dcfd6a2c0254060956",
"shasum": ""
},
"require": {
@@ -452,7 +449,9 @@
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7.9"
"dealerdirect/phpcodesniffer-composer-installer": "^0.4",
"phpcompatibility/php-compatibility": "^9.3.0",
"phpunit/phpunit": "^5.7.9 || ^6.0 || ^7.0"
},
"type": "library",
"extra": {
@@ -494,7 +493,7 @@
"test",
"testing"
],
"time": "2017-12-01T16:32:09+00:00"
"time": "2019-11-24T16:03:21+00:00"
},
{
"name": "hamcrest/hamcrest-php",
@@ -546,16 +545,16 @@
},
{
"name": "mockery/mockery",
"version": "1.2.0",
"version": "1.3.1",
"source": {
"type": "git",
"url": "https://github.com/mockery/mockery.git",
"reference": "100633629bf76d57430b86b7098cd6beb996a35a"
"reference": "f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mockery/mockery/zipball/100633629bf76d57430b86b7098cd6beb996a35a",
"reference": "100633629bf76d57430b86b7098cd6beb996a35a",
"url": "https://api.github.com/repos/mockery/mockery/zipball/f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be",
"reference": "f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be",
"shasum": ""
},
"require": {
@@ -564,12 +563,12 @@
"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": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.3.x-dev"
}
},
"autoload": {
@@ -607,7 +606,7 @@
"test double",
"testing"
],
"time": "2018-10-02T21:52:37+00:00"
"time": "2019-12-26T09:49:15+00:00"
},
{
"name": "pds/skeleton",
@@ -642,16 +641,16 @@
},
{
"name": "twbs/bootstrap",
"version": "v3.4.0",
"version": "v3.4.1",
"source": {
"type": "git",
"url": "https://github.com/twbs/bootstrap.git",
"reference": "4c547f2175b9a05aa43551f6927da83fe249ce42"
"reference": "68b0d231a13201eb14acd3dc84e51543d16e5f7e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twbs/bootstrap/zipball/4c547f2175b9a05aa43551f6927da83fe249ce42",
"reference": "4c547f2175b9a05aa43551f6927da83fe249ce42",
"url": "https://api.github.com/repos/twbs/bootstrap/zipball/68b0d231a13201eb14acd3dc84e51543d16e5f7e",
"reference": "68b0d231a13201eb14acd3dc84e51543d16e5f7e",
"shasum": ""
},
"replace": {
@@ -689,7 +688,7 @@
"responsive",
"web"
],
"time": "2018-12-13T23:45:51+00:00"
"time": "2019-02-13T15:55:38+00:00"
}
],
"aliases": [],
+9 -1
View File
@@ -5,7 +5,7 @@ Plugin Name: Laps
Plugin URI: https://github.com/Rarst/laps
Description: Light WordPress profiler.
Author: Andrey “Rarst” Savchenko
Version: 3.0
Version: 3.3.1
Author URI: https://www.rarst.net/
Text Domain: laps
Domain Path: /lang
@@ -16,6 +16,14 @@ if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php';
}
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();
+4 -24
View File
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
totallyTyped="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
@@ -16,28 +16,8 @@
<issueHandlers>
<LessSpecificReturnType errorLevel="info"/>
<UndefinedFunction errorLevel="suppress"/>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="WP_Admin_Bar"/>
<referencedClass name="WP_Error"/>
<referencedClass name="WP_Hook"/>
</errorLevel>
</UndefinedClass>
<MixedArgument>
<errorLevel type="suppress">
<file name="src/Provider/Record_Provider.php" />
<file name="src/Record/Collector/Hook_Collector.php" />
</errorLevel>
</MixedArgument>
<MissingClosureParamType>
<errorLevel type="suppress">
<file name="src/Record/Collector/Hook_Collector.php" />
</errorLevel>
</MissingClosureParamType>
<MissingClosureReturnType>
<errorLevel type="suppress">
<file name="src/Record/Collector/Hook_Collector.php" />
</errorLevel>
</MissingClosureReturnType>
<UndefinedClass errorLevel="suppress"/>
<UndefinedDocblockClass errorLevel="suppress"/>
<UndefinedConstant errorLevel="suppress"/>
</issueHandlers>
</psalm>
+1 -1
View File
@@ -9,7 +9,7 @@ namespace Rarst\Laps\Event;
class Core_Events implements Hook_Event_Config_Interface {
/**
* @return array
* @inheritDoc
*/
public function get_events(): array {
+52
View File
@@ -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 {
/**
* @inheritDoc
*/
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 );
}
}
+3 -1
View File
@@ -7,11 +7,13 @@ 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 {
/**
* @return array
* @inheritDoc
*/
public function get_events(): array {
+3 -1
View File
@@ -7,11 +7,13 @@ 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 {
/**
* @return array
* @inheritDoc
*/
public function get_events(): array {
+3 -1
View File
@@ -7,11 +7,13 @@ 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 {
/**
* @return array
* @inheritDoc
*/
public function get_events(): array {
+27
View File
@@ -0,0 +1,27 @@
<?php
declare( strict_types=1 );
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 {
/**
* @inheritDoc
*/
public function get_events(): array {
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' ],
] : [];
}
}
+3 -1
View File
@@ -5,11 +5,13 @@ 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 {
/**
* @return array
* @inheritDoc
*/
public function get_events(): array {
+2 -3
View File
@@ -76,13 +76,12 @@ class Backtrace_Formatter {
}
/**
*
* @psalm-suppress PossiblyFalseOperand
*
* @param string $item Backtrace item.
*
* @return string
*
* @psalm-suppress PossiblyFalseOperand
* @psalm-suppress MixedInferredReturnType
*/
protected function shorten_include( string $item ): string {
+23 -9
View File
@@ -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 ),
@@ -24,7 +25,14 @@ class Hook_Formatter {
}
/**
* @psalm-type Callback = string|object|array
* @psalm-type AcceptedArgs = int
* @psalm-type Hook = array{function: Callback, accepted_args: AcceptedArgs}
* @psalm-type Priority = array-key
* @psalm-type Hooks = array<Priority, array<Hook>>
*
* @param \WP_Hook|array $hook Hook instance.
* @psalm-param \WP_Hook|Hooks $hook
*
* @return array
*/
@@ -33,8 +41,14 @@ class Hook_Formatter {
$callbacks = [];
if ( $hook instanceof \WP_Hook ) {
/** @psalm-var Hooks $hook->callbacks */
$hook = $hook->callbacks;
}
if ( empty( $hook ) ) {
return $callbacks;
}
ksort( $hook );
$functions = array_merge( ...$hook );
@@ -55,27 +69,27 @@ class Hook_Formatter {
/**
* @param string|object|array $callback Hook callback.
* @param int $args Number of accepted arguments.
*
* @return string
*/
protected function get_callback_name( $callback, int $args ): string {
switch ( gettype( $callback ) ) {
case 'object':
$callback = $this->get_class_name( $callback );
$name = $this->get_class_name( $callback );
break;
case 'array':
$class = is_string( $callback[0] )
/** @psalm-var array{0: object|string, 1: string} $callback */
$class = is_string( $callback[0] )
? $callback[0] . '::'
: $this->get_class_name( $callback[0] ) . '->';
$callback = $class . $callback[1];
$name = $class . $callback[1];
break;
default:
$name = $callback;
}
$callback .= ( 1 === $args ) ? '' : "({$args})";
return $callback;
return $name . ( ( 1 === $args ) ? '' : "({$args})" );
}
/**
@@ -85,7 +99,7 @@ class Hook_Formatter {
*/
protected function get_class_name( $object ): string {
if ( is_a( $object, 'CLosure' ) ) {
if ( $object instanceof \Closure ) {
$class = new \ReflectionFunction( $object );
return 'closure from ' . $this->shorten_path( $class->getFileName() ) . ':' . $class->getStartLine();
-2
View File
@@ -21,8 +21,6 @@ class Load_Order_Manager {
* Reorder active plugins so Laps is first and starts timing load early.
*
* @param array $plugins Filtered array of active plugins’ basenames.
*
* @return array
*/
public function pre_update_option_active_plugins( array $plugins ): array {
+6 -2
View File
@@ -57,14 +57,18 @@ class Server_Timing_Manager {
foreach ( $this->collector->get_records() as $record ) {
$duration = $record->get_duration() * 1000;
if ( $duration < 1 ) {
if ( $duration < 1 ) { // Filter out less than 1ms events as too noisy.
continue;
}
$header .= sprintf( '%s;dur=%.2f;desc="%s", ', $record->get_category(), $duration, $record->get_name() );
if ( strlen( $header ) > 4000 ) { // 8+KB headers break proxies, so we cut off at 1/2 that limit.
break;
}
}
header( 'Server-Timing: ' . $header );
header( 'Server-Timing: ' . preg_replace( '/\R/', '', $header ) );
return $input;
}
-2
View File
@@ -36,8 +36,6 @@ class Toolbar_Manager {
* Render interface and add to the toolbar.
*
* @param \WP_Admin_Bar $wp_admin_bar WordPress core toolbar object.
*
* @psalm-suppress MixedArgument
*/
public function admin_bar_menu( \WP_Admin_Bar $wp_admin_bar ): void {
+2 -2
View File
@@ -11,12 +11,12 @@ class Mustache_Cache_FrozenCache extends \Mustache_Cache_FilesystemCache {
/**
* Cache and load a compiled Mustache_Template class.
*
* @psalm-suppress InvalidScalarArgument
*
* @param string $key Key.
* @param string $value Value.
*
* @return void
*
* @psalm-suppress InvalidScalarArgument
*/
public function cache( $key, $value ): void {
+1 -5
View File
@@ -20,9 +20,7 @@ class Plugin extends Container {
/**
* @param array $values Configuration values to apply.
*
* @psalm-suppress MixedArgument
* @psalm-suppress MixedAssignment
* @psalm-param array<string, mixed> $values
*/
public function __construct( array $values = [] ) {
@@ -63,8 +61,6 @@ class Plugin extends Container {
/**
* Start Stopwatch and timing plugin load immediately, then set up core events and needed hooks.
*
* @psalm-suppress MixedAssignment
*/
public function run(): void {
+2 -1
View File
@@ -3,12 +3,13 @@ declare( strict_types=1 );
namespace Rarst\Laps\Provider;
use Pimple\ServiceProviderInterface;
use Rarst\Laps\Plugin;
/**
* Interface for providers that need to boot up once plugin is ready to start.
*/
interface Bootable_Provider_Interface {
interface Bootable_Provider_Interface extends ServiceProviderInterface {
/**
* @param Plugin $laps Container instance.
+11 -5
View File
@@ -6,9 +6,11 @@ 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;
use Rarst\Laps\Event\WooCommerce_Events;
use Rarst\Laps\Event\Yoast_Events;
/**
@@ -18,16 +20,20 @@ class Hook_Event_Provider implements ServiceProviderInterface {
/**
* @param Container $pimple Container instance.
*
* @psalm-suppress DeprecatedClass
*/
public function register( Container $pimple ): void {
$pimple['hook.events'] = function (): array {
return [
'core' => new Core_Events(),
'genesis' => new Genesis_Events(),
'hybrid' => new Hybrid_Events(),
'tha' => new THA_Events(),
'yoast' => new Yoast_Events(),
'core' => new Core_Events(),
'extension' => new Extension_Events(),
'genesis' => new Genesis_Events(),
'hybrid' => new Hybrid_Events(),
'tha' => new THA_Events(),
'woocommerce' => new WooCommerce_Events(),
'yoast' => new Yoast_Events(),
];
};
}
+6 -4
View File
@@ -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;
@@ -29,10 +30,11 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int
$pimple['collectors'] = function ( Plugin $laps ): array {
return [
'core' => new Core_Load_Collector(),
'hook' => new Hook_Collector( $laps['stopwatch'], $laps['hook.events'] ),
'http' => new Http_Collector( $laps['stopwatch'] ),
'sql' => new Sql_Collector(),
'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(),
];
};
+17 -5
View File
@@ -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->timeload = microtime( true );
$this->network_activated = ! did_action( 'muplugins_loaded' );
}
/**
@@ -30,14 +34,22 @@ class Core_Load_Collector implements Record_Collector_Interface {
$request_time = filter_var( $_SERVER['REQUEST_TIME_FLOAT'], FILTER_VALIDATE_FLOAT );
$php = 'PHP Load – ' . PHP_VERSION;
if ( function_exists( 'opcache_get_status' ) ) {
$zend_status = opcache_get_status();
$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 Load', $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( $php, $request_time, $timestart - $request_time, '', 'php' ),
new Record( $load, $timestart, $this->timeload - $timestart, '', 'core' ),
];
}
}
+59 -4
View File
@@ -20,12 +20,21 @@ class Hook_Collector extends Stopwatch_Collector {
/** @var array $events */
protected $events = [];
/** @var array */
/**
* @var array $callbacks
* @psalm-var array<string, \WP_Hook> $callbacks
*/
protected $callbacks = [];
/** @var Hook_Formatter */
protected $formatter;
/**
* @var array $calls Tracks number of calls for recurrent events.
* @psalm-var array<string, int> $calls
*/
private $calls = [];
/**
* @param Stopwatch $stopwatch Stopwatch instance.
* @param Hook_Event_Config_Interface[] $event_configs Starts and stops configuration.
@@ -34,7 +43,12 @@ class Hook_Collector extends Stopwatch_Collector {
parent::__construct( $stopwatch );
$this->start( 'Plugins Load', 'plugin' );
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 +58,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(): void {
$this->stop( 'Network & MU Plugins Load' );
$this->start( 'Plugins Load', 'plugin' );
}
/**
* Hook events by name and priority from array.
*
@@ -56,11 +78,11 @@ class Hook_Collector extends Stopwatch_Collector {
/**
* @var int|string $key
* @var array $data
* @psalm-var array{0:string} $data
*/
foreach ( $stops as $key => $data ) {
if ( is_int( $key ) ) {
/** @var array{0:string} $data */
$this->add_event( ...$data );
continue;
}
@@ -81,6 +103,9 @@ class Hook_Collector extends Stopwatch_Collector {
* @param string|null $stop Stop hook name (defaults to start name). Pass empty string to ignore.
* @param int $start_priority Start hook priority (defaults to -1).
* @param int $stop_priority Stop hook priority (defaults to max int).
*
* @psalm-suppress MissingClosureReturnType
* @psalm-suppress MissingClosureParamType
*/
private function add_event(
string $event,
@@ -96,13 +121,17 @@ class Hook_Collector extends Stopwatch_Collector {
if ( '' !== $start ) {
add_action( $start, function ( $input = null ) use ( $event, $category, $start, $stop ) {
global $wp_filter;
$event .= $this->get_count_suffix( $event, true );
if ( 'Sidebar' === $event ) {
/** @var string $input */
$event = $input;
}
if ( $start === $stop ) {
global $wp_filter;
/** @psalm-var array<string, \WP_Hook> $wp_filter */
$this->callbacks[ $event ] = $wp_filter[ $start ];
}
@@ -115,7 +144,10 @@ 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 ) {
/** @var string $input */
$event = $input;
}
@@ -126,6 +158,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.
*/
+23 -12
View File
@@ -16,7 +16,10 @@ class Http_Collector extends Stopwatch_Collector {
/** @var Backtrace_Formatter */
private $formatter;
/** @var array */
/**
* @var array $callers
* @psalm-var array<string, string> $callers
*/
private $callers = [];
/**
@@ -35,16 +38,21 @@ class Http_Collector extends Stopwatch_Collector {
/**
* Capture start time of HTTP request
*
* @param boolean $false Whether to preempt an HTTP request's return value. Default false.
* @param array $args HTTP request arguments.
* @param string $url The request URL.
* @param false|array|\WP_Error $false Whether to preempt an HTTP request's return value. Default false.
* @param array $args HTTP request arguments.
* @param string $url The request URL.
*
* @return boolean
* @return false|array|\WP_Error
*
* @psalm-suppress RedundantConditionGivenDocblockType
* @noinspection PhpUnusedParameterInspection
*/
public function pre_http_request( bool $false, array $args, string $url ): bool {
public function pre_http_request( $false, $args, $url ) {
$this->start( $url, 'http' );
$this->callers[ $url ] = wp_debug_backtrace_summary( __CLASS__, 5, true );
if ( $url && is_string( $url ) ) {
$this->start( $url, 'http' );
$this->callers[ $url ] = wp_debug_backtrace_summary( __CLASS__, 5 );
}
return $false;
}
@@ -58,13 +66,16 @@ class Http_Collector extends Stopwatch_Collector {
* @param array $args HTTP request arguments.
* @param string $url The request URL.
*
* @return mixed
* @return array|\WP_Error
*
* @noinspection MoreThanThreeArgumentsInspection
* @psalm-suppress RedundantConditionGivenDocblockType
* @noinspection PhpUnusedParameterInspection
*/
public function http_api_debug( $response, string $type, $class, array $args, string $url ) {
public function http_api_debug( $response, $type, $class, $args, $url ) {
$this->stop( $url );
if ( $url && is_string( $url ) ) {
$this->stop( $url );
}
return $response;
}
@@ -0,0 +1,76 @@
<?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.
*
* @psalm-suppress DocblockTypeContradiction
*/
public function plugin_loaded( $plugin ): void {
$time = microtime( true );
if ( ! is_string( $plugin ) ) { // Broken hook input from global.
$this->last = $time;
return;
}
$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.
*/
private function create_record( array $entry ): Record {
return new Record(
plugin_basename( $entry['name'] ),
$entry['origin'],
$entry['duration'],
'',
'plugin'
);
}
}
+13 -11
View File
@@ -8,6 +8,8 @@ use Rarst\Laps\Record\Record;
/**
* Processes SQL events from data logged by wpdb.
*
* @template QueryData as array{0: string, 1: float, 2: string, 3: float}
*/
class Sql_Collector implements Record_Collector_Interface {
@@ -25,7 +27,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.
}
}
@@ -35,8 +37,6 @@ class Sql_Collector implements Record_Collector_Interface {
* @param string $query SQL query.
*
* @return string
*
* @psalm-suppress MixedPropertyFetch
*/
public function query( $query ): string {
@@ -64,7 +64,10 @@ class Sql_Collector implements Record_Collector_Interface {
}
/** @var array $wpdb->queries */
return array_map( [ $this, 'transform' ], array_keys( $wpdb->queries ), $wpdb->queries );
/** @psalm-var array<int, QueryData> $wpdb->queries */
$records = array_filter( array_map( [ $this, 'transform' ], array_keys( $wpdb->queries ), $wpdb->queries ) );
return $records;
}
/**
@@ -80,25 +83,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 );
@@ -51,6 +51,7 @@ class Stopwatch_Collector implements Record_Collector_Interface {
*/
public function get_records(): array {
/** @psalm-var array<string, StopwatchEvent> $events */
$events = $this->stopwatch->getSectionEvents( '__root__' );
/** @var string $name */
+1 -1
View File
@@ -43,7 +43,7 @@ class Stopwatch_Record implements Record_Interface {
public function get_description(): string {
$duration = round( $this->stopwatch_event->getDuration() );
$memory = $this->stopwatch_event->getMemory() / 1024 / 1024;
$memory = round( $this->stopwatch_event->getMemory() / 1024 / 1024, 2 );
$description = '' !== $this->description ? "<hr />{$this->description}" : '';
return "{$this->name} – {$duration} ms – {$memory} MB{$description}";
+19 -5
View File
@@ -7,6 +7,7 @@ use Rarst\Laps\Event\Core_Events;
use Rarst\Laps\Event\Genesis_Events;
use Rarst\Laps\Event\Hybrid_Events;
use Rarst\Laps\Event\THA_Events;
use Rarst\Laps\Event\WooCommerce_Events;
use Rarst\Laps\Event\Yoast_Events;
use Rarst\Laps\Tests\LapsTestCase;
@@ -16,7 +17,7 @@ class EventTest extends LapsTestCase {
$events = ( new Core_Events() )->get_events();
$this->assertInternalType( 'array', $events );
$this->assertIsArray( $events );
$this->assertNotEmpty( $events );
}
@@ -28,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 );
}
@@ -45,7 +46,7 @@ class EventTest extends LapsTestCase {
$events = $hybrid->get_events();
$this->assertInternalType( 'array', $events );
$this->assertIsArray( $events );
$this->assertNotEmpty( $events );
}
@@ -58,7 +59,20 @@ class EventTest extends LapsTestCase {
$events = $tha->get_events();
$this->assertInternalType( 'array', $events );
$this->assertIsArray( $events );
$this->assertNotEmpty( $events );
}
public function testWooCommerce() {
$woocommerce = new WooCommerce_Events();
$this->assertEmpty( $woocommerce->get_events() );
$this->getMockBuilder( 'WooCommerce' )->allowMockingUnknownTypes()->getMock();
$events = $woocommerce->get_events();
$this->assertIsArray( $events );
$this->assertNotEmpty( $events );
}
@@ -71,7 +85,7 @@ class EventTest extends LapsTestCase {
$events = $yoast->get_events();
$this->assertInternalType( 'array', $events );
$this->assertIsArray( $events );
$this->assertNotEmpty( $events );
}
}
+4 -2
View File
@@ -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] );
}
}
+5 -2
View File
@@ -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( [] ) );
}
}
+2 -2
View File
@@ -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();
}
+1 -1
View File
@@ -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] );
}
+1 -2
View File
@@ -3,7 +3,6 @@
namespace Rarst\Laps\Tests;
use Brain\Monkey\Functions;
use Pimple\ServiceProviderInterface;
use Rarst\Laps\Provider\Bootable_Provider_Interface;
class PluginTest extends LapsTestCase {
@@ -12,7 +11,7 @@ class PluginTest extends LapsTestCase {
$container = new \Rarst\Laps\Plugin();
$service = $this->getMockBuilder( [ ServiceProviderInterface::class, Bootable_Provider_Interface::class ] )
$service = $this->getMockBuilder( Bootable_Provider_Interface::class )
->getMock();
$service->expects( $this->once() )
+1 -1
View File
@@ -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] );
}
-1
View File
@@ -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)' ) );
+2 -2
View File
@@ -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() );
+2 -2
View File
@@ -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 );
+3 -3
View File
@@ -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() );
}
+2 -2
View File
@@ -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() );
}
}