PHPackages                             petrknap/shorts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. petrknap/shorts

ActiveLibrary[Testing &amp; Quality](/categories/testing)

petrknap/shorts
===============

Set of short PHP helpers

v3.3.1(4d ago)0114.2k↓48.4%18LGPL-3.0-or-laterPHPPHP &gt;=8.1

Since Nov 4Pushed 4d ago1 watchersCompare

[ Source](https://github.com/petrknap/php-shorts)[ Packagist](https://packagist.org/packages/petrknap/shorts)[ Docs](https://github.com/petrknap/php-shorts)[ Fund](https://petrknap.github.io/donate.html)[ RSS](/packages/petrknap-shorts/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (10)Versions (18)Used By (18)

Set of short PHP helpers
========================

[](#set-of-short-php-helpers)

- [Exceptions](#exceptions)
    - [`CouldNotProcessData` template](#couldnotprocessdata-template)
    - [`NotImplemented`](#notimplemented)
- [`HasRequirements` trait](#hasrequirements-trait)
- [Testing](#testing)
    - [`IlluminateDatabase` helper](#illuminatedatabase-helper)
    - [`MarkdownFileTest` interface + trait](#markdownfiletest-interface--trait)

Exceptions
----------

[](#exceptions)

### [`CouldNotProcessData` template](./src/Exception/CouldNotProcessData.php)

[](#couldnotprocessdata-template)

Template for an exception that indicates that the data could not be processed.

```
interface ImageResizerException extends Throwable {}

final class ImageResizerCouldNotResizeImage extends PetrKnap\Shorts\Exception\CouldNotProcessData implements ImageResizerException {}

final class ImageResizer {
    public function resize(string $image) {
        throw new ImageResizerCouldNotResizeImage(__METHOD__, $image);
    }
}
```

### [`NotImplemented`](./src/Exception/NotImplemented.php)

[](#notimplemented)

Simple exception for prototyping purposes.

```
final class StringablePrototype implements Stringable {
    public function __toString(): string {
        PetrKnap\Shorts\Exception\NotImplemented::throw(__METHOD__);
    }
}
```

[`HasRequirements` trait](./src/HasRequirements.php)
----------------------------------------------------

[](#hasrequirements-trait)

Simple trait to check if requirements of your code are fulfilled.

```
final class ServiceWithRequirements {
    use PetrKnap\Shorts\HasRequirements;

    public function __construct() {
        self::checkRequirements(functions: ['required_function']);
    }

    public function do(): void {
        required_function();
    }
}
```

It should not replace [Composers](https://getcomposer.org/) [`require`s](https://getcomposer.org/doc/04-schema.md#require), but it could improve them and check [`suggest`s](https://getcomposer.org/doc/04-schema.md#suggest).

Testing
-------

[](#testing)

### [`IlluminateDatabase` helper](./src/Testing/IlluminateDatabase.php)

[](#illuminatedatabase-helper)

Simple helper which provides logic to test `Illuminate\Database` without `Laravel` mess.

```
$pdo = new PDO('sqlite::memory:');
$pdo->exec('CREATE TABLE tigers (id INTEGER PRIMARY KEY, name VARCHAR)');
$pdo->prepare('INSERT INTO tigers (name) VALUES (?), (?), (?)')
    ->execute(['Roque', 'Jasper', 'Gopal']);

PetrKnap\Shorts\Testing\IlluminateDatabase::createCapsuleManager($pdo)
    ->bootEloquent();

class Tiger extends Illuminate\Database\Eloquent\Model {}

assert(Tiger::count() === 3);
```

### [`MarkdownFileTest` interface](./src/PhpUnit/MarkdownFileTestInterface.php) + [trait](./src/PhpUnit/MarkdownFileTestTrait.php)

[](#markdownfiletest-interface--trait)

The interface and trait let you automatically test code examples in a Markdown file like `README.md`.

```
final class ReadmeTest extends PHPUnit\Framework\TestCase implements PetrKnap\Shorts\PhpUnit\MarkdownFileTestInterface {
    use PetrKnap\Shorts\PhpUnit\MarkdownFileTestTrait;

    public static function getPathToMarkdownFile(): string {
        return __DIR__ . '/../README.md';
    }

    public static function getExpectedOutputsOfPhpExamples(): array {
        return [
            'some example' => 'has this output',
        ];
    }
}
```

By specifying the file path and expected outputs, the trait runs each code block and checks that its output matches, keeping documentation examples correct and up‑to‑date.

---

Run `composer require petrknap/shorts` to install it. You can [support this project via donation](https://petrknap.github.io/donate.html). The project is licensed under [the terms of the `LGPL-3.0-or-later`](./COPYING.LESSER).

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance99

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Recently: every ~110 days

Total

17

Last Release

4d ago

Major Versions

v1.6.0 → v2.0.02024-04-17

v2.1.1 → v3.0.02024-11-02

PHP version history (2 changes)v1.0.0PHP &gt;=8.0

v3.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/c0e19f2ea17567eb9f536d1e00595b83630dfb8b2df6e7e422e06a9a48e85585?d=identicon)[petrknap](/maintainers/petrknap)

---

Top Contributors

[![petrknap](https://avatars.githubusercontent.com/u/8299754?v=4)](https://github.com/petrknap "petrknap (53 commits)")

---

Tags

arrayhelpermarkdownphpphp-libraryphpunitphpunithelperarraymarkdown

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/petrknap-shorts/health.svg)

```
[![Health](https://phpackages.com/badges/petrknap-shorts/health.svg)](https://phpackages.com/packages/petrknap-shorts)
```

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k955.1M155.1k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k136.1M986](/packages/brianium-paratest)[johnkary/phpunit-speedtrap

Find and report on slow tests in your PHPUnit test suite

78338.9M134](/packages/johnkary-phpunit-speedtrap)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69619.8M639](/packages/spatie-phpunit-snapshot-assertions)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

57129.2M612](/packages/dg-bypass-finals)[phpspec/prophecy-phpunit

Integrating the Prophecy mocking library in PHPUnit test cases

19459.2M1.8k](/packages/phpspec-prophecy-phpunit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
